问题描述
我有一个类似于 Asteroids 游戏的项目。游戏包含一个推力方法,顾名思义就是推力飞船。该方法并没有朝着我要求的方向推进。飞船左右键旋转,空格键推力。
private static final double THRUST_VALUE = 3;
private static final int MAX_SPEED = 4;
private int lives;
private int rotationSpeed;
public void thrust() {
double[] newVeLocity = new double[2];
double[] oldVeLocity = getVeLocity();
newVeLocity[0] = oldVeLocity[0] - THRUST_VALUE * Math.sin(getRotation()*Math.PI/180);
newVeLocity[1] = oldVeLocity[1] - THRUST_VALUE * Math.cos(getRotation()*Math.PI/180);
System.out.println(newVeLocity[0]);
System.out.println(newVeLocity[1]);
if (newVeLocity[0] >= MAX_SPEED || newVeLocity[0] <= -MAX_SPEED){
newVeLocity[0] = MAX_SPEED;
}
if (newVeLocity[1] >= MAX_SPEED || newVeLocity[1] <= -MAX_SPEED){
newVeLocity[1] = MAX_SPEED;
}
setVeLocity(newVeLocity);
速度和旋转的属性继承自 polygon 类。以下是声明的属性:
private Point[] shape; // An array of points.
private Point position; // The offset mentioned above.
private double rotation; // Zero degrees is due east.
代码运行正常,但代码逻辑关闭,不听位置,但不知道是什么问题。感谢所有输入。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)