我正在尝试做一个子弹课。当它被调用时,它将获得一个方向和一个初始位置。问题是方向不起作用,无论我设置什么方向,它只会上升。
请帮忙。
提前致谢
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();
}
}