Game Development Reference
In-Depth Information
1.
Rotate or move the ship on screen depending on the value of the class
variables: left, right, up, or down. These variables are updated depending on
the key pressed by the user. The actual movement or rotation is performed by
updating the delta values of the ship's X and Y coordinates and its angle of
rotation.
2.
Update other sprites, like the thrusters (which are independent sprites), as the
ship moves around.
3.
Perform other physics checks:
Do not let the ship exceed a speed limit.
If the ship has exploded, update the ship counter, and create a new ship or
end the game depending on the number of ships left.
Listing 4-8. Updating the Game Physics
protected void updatePhysics() {
// Update Sprites
updateShip();
updatePhotons();
updateUfo();
updateMissile();
updateAsteroids();
updateExplosions();
// Check the score and advance high score,
if (score > highScore)
highScore = score;
// add a new ship if score reaches Constants.NEW_SHIP_POINTS
if (score > newShipScore) {
newShipScore += Constants.NEW_SHIP_POINTS;
shipsLeft++;
}
// start the flying saucer as necessary.
if (playing && score > newUfoScore && ! ufo.active) {
newUfoScore += Constants.NEW_UFO_POINTS;
ufoPassesLeft = Constants.UFO_PASSES;
initUfo();
}
// If all asteroids have been destroyed create a new batch.
if (asteroidsLeft <= 0)
if (--asteroidsCounter <= 0)
initAsteroids();
}
// Update Ship
Search WWH ::




Custom Search