私は弾丸クラスを作ろうとしています。呼び出されると、方向と初期位置が取得されます。問題は、方向が機能していないことです。方向として設定したものに関係なく、上昇するだけです。
助けてください。
前もって感謝します
public class Bullet extends JComponent implements ActionListener{
private int bx,by;
private double theta;
private double BvelX, BvelY;
private Timer timer = new Timer(8,this);
public Bullet(int bx, int by, double theta)
{
this.bx = bx;
this.by = by;
this.theta = theta;
BvelX = 0;
BvelY = -1;
timer.start();
revalidate();
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D graphicsS = (Graphics2D) g;
graphicsS.rotate(theta, bx, by);
graphicsS.setColor(Color.RED);
graphicsS.fillOval(bx, by, 8, 8);
}
public void actionPerformed(ActionEvent e)
{
bx += BvelX;
by += BvelY;
/*by += 5*(Math.sin(theta));
bx += 5*(Math.cos(theta));*/
revalidate();
repaint();
}
}