Bringing the spaceship to life
First, we need to add a bit more functionality to our GameObject
class. We do so in GameObject
because bullets and asteroids share a surprising amount of similarities with a spaceship.
We need a bunch of getters and setters to get and set the rotation rate, traveling angle, and facing angle. Add the following methods to the GameObject
class:
public void setRotationRate(float rotationRate) { this.rotationRate = rotationRate; } public float getTravellingAngle() { return travellingAngle; } public void setTravellingAngle(float travellingAngle) { this.travellingAngle = travellingAngle; } public float getFacingAngle() { return facingAngle; } public void setFacingAngle(float facingAngle) { this.facingAngle = facingAngle; }
Now, we add a move
method, which adjusts the x and y coordinates as well as the facingAngle
of the object based on the current frames per second. Add the move
method:
void move(float fps){ if(xVelocity != 0) { worldLocation.x...