so, i'm trying to make a ship turn, but not instantly - here is my code:
Not sure what is wrong... originally I had an if / else if, but the else if , even though it was true, never changed the angleDelta. The way I have it now, I can't tell if it does or doesn't change angleDelta, but either way nothing happens - the current angle stays the same. Help?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Ship here. * * @author Michionlion * @version 10/3/2012 */ public class Ship extends Actor { int xPos, yPos, angle; private int xDelta, yDelta, angleDelta, destX, destY, destAngle; private boolean moving, turning; private Player player; private int frame; public Ship(int xPos, int yPos) { this.xPos = xPos; this.yPos = yPos; //this.player = player; angleDelta = 0; xDelta = 0; yDelta = 0; moving = false; turning = false; setImage("regShip.png"); } public void addedToWorld() { setLocation(xPos, yPos); turnTo(204); } public void act() { checkDestinations(); setLocation(xPos + xDelta, yPos + yDelta); setRotation(angle + angleDelta); frame++; } public Player getOwner() { return player; } protected void checkDestinations() { if (xPos == destX) xDelta = 0; if (yPos == destY) yDelta = 0; if (angle == destAngle) angleDelta = 0; if (angleDelta == 0) turning = false; else turning = true; if (xDelta == 0 && yDelta == 0) moving = false; else moving = true; } public void moveTo(int x, int y) { } public void turnTo(int a) { if (a < 0 || a > 359) return; if (a == angle) return; if (destAngle < angle) angleDelta = -1; else angleDelta = 1; destAngle = a; turning = true; } }