Game Development Reference
In-Depth Information
stateTime = 0;
state = SHIP_ALIVE ;
}
}
stateTime += deltaTime;
}
The update() method is pretty simple. It takes the delta time and the current accelerometer
reading on the y axis of the device (remember, we are in landscape mode, so the accelerometer
y axis is our screen's x axis). If the ship is alive, we set its velocity based on the accelerometer
value (which will be in the range −10 to 10), just as we did for Bob in Super Jumper. Additionally,
we update its position based on the current velocity. Next, we check whether the ship has left
the boundaries of the playing field, using two constants that we'll define later on in our World
class. When the position is fixed, we can update the center of the bounding sphere for the ship.
If the ship is exploding, we check how long that's been the case. After 1.6 seconds in the
exploding state, the ship is finished exploding, loses one life, and goes back to the alive state.
Finally, we update the stateTime member based on the given delta time.
public void kill() {
state = SHIP_EXPLODING ;
stateTime = 0;
velocity.x = 0;
}
}
The last kill() method will be called by the World class if it determines a collision has occurred
between the ship and either a shot or an invader. It will set the state to exploding, reset the
state time, and make sure that the ship's velocity is zero on all axes (we never set the y and z
components of the velocity vector, since we only move on the x axis).
The Invader Class
Invaders are simply floating in space according to a predefined pattern. Figure 12-11 shows
this pattern.
 
Search WWH ::




Custom Search