因此,我有一个bullet类,其中包含以下代码,我希望能够通过从另一个类创建bullet来实现。我该怎么做呢。目前它看起来wierd而旋转,而不是只是跳转位置错误的旋转模式,我想看看这个正确的旋转模式
public class Bullet extends GameObject{
private Handler handler;
float direction, curve, speed, acceleration;
float dirX, dirY;
public Bullet(int x, int y, ID id, Handler handler, float direction, float speed, float acceleration, float curve) {
super(x, y, id);
this.handler = handler;
this.direction = direction;
this.speed = speed;
this.acceleration = acceleration;
this.curve = curve;
}
public void tick() {
direction = direction + curve;
speed = speed + acceleration;
dirX = (float) xDir(direction);
dirY = (float) yDir(direction);
x = (int) (x + dirX*speed);
y = (int) (y + dirY*speed);
}
public static double xDir(float angle){
double rad = angle * Math.PI/180;
return Math.cos(rad);
}
public static double yDir(float angle){
double rad = angle * Math.PI/180;
return -Math.sin(rad);
}
public void render(Graphics g) {
g.setColor(Color.magenta);
g.fillOval(x, y, 8, 8);
}
public Rectangle getBounds() {
return new Rectangle(x ,y, 8, 8);
}
}
暂无答案!
目前还没有任何答案,快来回答吧!