Game Development Reference
In-Depth Information
listener.coin();
score += Coin. COIN_SCORE ;
}
}
if (bob.velocity.y > 0)
return ;
len = springs.size();
for ( int i = 0; i < len; i++) {
Spring spring = springs.get(i);
if (bob.position.y > spring.position.y) {
if (OverlapTester. overlapRectangles (bob.bounds, spring.bounds)) {
bob.hitSpring();
listener.highJump();
}
}
}
}
The checkItemCollisions() method checks Bob against all coins in the world and against all
springs. If Bob hits a coin, we remove the coin from our world, tell the listener that a coin was
collected, and increase the current score by COIN_SCORE . If Bob is falling downward, we also
check Bob against all springs in the world. If he hits one, we tell him about it so that he'll perform
a higher jump than usual. We also inform the listener of this event.
private void checkCastleCollisions() {
if (OverlapTester. overlapRectangles (castle.bounds, bob.bounds)) {
state = WORLD_STATE_NEXT_LEVEL;
}
}
The final method checks Bob against the castle. If Bob hits it, we set the world's state to
WORLD_STATE_NEXT_LEVEL , signaling any outside entity (such as our game screen) that we should
transition to the next level, which will again be a randomly generated instance of World .
Game Over, Buddy!
The last method in the World class, which is invoked in the last line of the World.update()
method, is shown in Listing 9-19.
Listing 9-19. The Rest of World.java; the Game Over-Checking Method
private void checkGameOver() {
if (heightSoFar - 7.5f > bob.position.y) {
state = WORLD _ STATE _ GAME _ OVER ;
}
}
}
 
Search WWH ::




Custom Search