我得到了一个物体(称为 tempEnemy),它飞来飞去并射击。问题是我不能保持值 tempEnemy.rotateTo 为正值,即它应该在 0 到 359 度之间。目前 rotateTo 的范围为:rotateTo < 0 (bug) && rotateTo > 0 && rotateTo > 359 (bug)。
tempEnemy.dX = tempEnemy.destX - tempEnemy.x;
tempEnemy.dY = tempEnemy.destY - tempEnemy.y;
//I added 180 because my tempEnemy object was looking and shooting to the wrong direction
tempEnemy.rotateTo = (toDegrees(getRadians(tempEnemy.dX, tempEnemy.dY))) + 180;
if (tempEnemy.rotateTo > tempEnemy.frame + 180) tempEnemy.rotateTo -= 360;
if (tempEnemy.rotateTo < tempEnemy.frame - 180) tempEnemy.rotateTo += 360;
tempEnemy.incFrame = int((tempEnemy.rotateTo - tempEnemy.frame) / tempEnemy.rotateSpeed);