Java Reference
In-Depth Information
onMouseExited make the button Node change color as the mouse passes over it, which tells the user that
the Node is interactive in some way.
The Node startScreen now has two buttons wired up to actions. When the user clicks on the Node
aboutScreen.startButton , a new game is started by calling the function startGame . When the user clicks
on startScreen.aboutButton , the startScreen Node is replaced with the Node aboutScreen using a
WipeReplace . Conversely, when the user clicks on the Node aboutScreen.backButton , a WipeReplace
replaces the Node aboutScreen with the Node startScreen . This allows the user to navigate from the start
screen to the about screen and back. When the user clicks on the Node startScreen.startButton , the
Node startScreen is replaced with the Node gameModel.screen . This starts the game proper.
Round Life Cycle
Once the user is ready to actually play the game, the class GameModel initializes and starts accepting user
input. Playing the game constitutes firing a clown five times at the bucket of water. Let's call that a
round. Each time a clown is fired the application will go from waiting for the user, to animating the
scene, to back to waiting for the user. We will start by looking at how GameModel initializes and then how
the state of the game is managed. Let's take a look at the class GameModel and get into the meat of the
game.
Listing 11-3. GameModel.fx (partial)
public class GameModel {
//local variables omitted for brevity, please see the source code.
init{
initScreen();
}
function initScreen():Void{
Main.simplifyGradients(screen);
Main.removeFromParent(screen.aboutPanel);
Main.removeFromParent(screen.aboutButton);
Main.removeFromParent(screen.startButton);
Main.removeFromParent(screen.title);
screen.powerLevel.visible = true;
screen.backFromPlayButton.visible = false;
screen.playAgainButton.visible = false;
screen.gameOverText.visible = false;
Main.makeButton(screen.backFromPlayButton, goBack);
Main.makeButton(screen.playAgainButton, playAgain);
screen.onMouseWheelMoved = mouseWheelMoved;
screen.onMouseClicked = mouseButtonClicked;
clownNode = Main.offsetFromZero(screen.flyingClown);
cannonNode = Main.offsetFromZero(screen.cannon);
bucketNode = Main.offsetFromZero(screen.waterBucket);
balloonNode = Main.offsetFromZero(screen.bonusBalloon);
net = Main.offsetFromZero(screen.net);
Search WWH ::




Custom Search