Game Development Reference
In-Depth Information
public void hit() {
Assets. playSound (Assets. hitSound );
}
public void coin() {
Assets. playSound (Assets. coinSound );
}
};
world = new World(worldListener);
renderer = new WorldRenderer(glGraphics, batcher, world);
pauseBounds = new Rectangle(320- 64, 480- 64, 64, 64);
resumeBounds = new Rectangle(160 - 96, 240, 192, 36);
quitBounds = new Rectangle(160 - 96, 240 - 36, 192, 36);
lastScore = 0;
scoreString = "score: 0";
}
In the constructor, we initialize all the member variables. The only interesting thing here is
the WorldListener we implement as an anonymous inner class. It's registered with the World
instance, and it will play back sound effects according to the event that gets reported to it.
Updating the GameScreen
Next we have the update methods, which will make sure any user input is processed correctly
and will also update the World instance if necessary. Listing 9-21 shows the code.
Listing 9-21. Excerpt from GameScreen.java; the Update Methods
@Override
public void update( float deltaTime) {
if if(deltaTime > 0.1f)
deltaTime = 0.1f;
switch (state) {
case GAME _ READY :
updateReady();
break ;
case GAME_RUNNING:
updateRunning(deltaTime);
break ;
case GAME_PAUSED:
updatePaused();
break ;
case GAME_LEVEL_END:
updateLevelEnd();
break ;
case GAME _ OVER :
updateGameOver();
break ;
}
}
 
Search WWH ::




Custom Search