28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 11<br />

Moving Your Action Figure in 2D:<br />

Controlling the X and Y Display<br />

Screen Coordinates<br />

Now that we have created the public CastingDirector class, which I call the “casting engine,” in Chapter 10, we need to<br />

get back into our InvinciBagel.java primary application class coding here in Chapter 11, and create our iBagel primary<br />

game play Actor (character) in the .createGameActors() method. We will also create the castDirector object using<br />

the CastingDirector.java class and its CastingDirector() constructor method, which we created in Chapter 10, as well as<br />

creating the .createCastingDirection() method, which will manage our casting direction class-related features.<br />

After we finish adding the code into our InvinciBagel.java class that will create the iBagel Bagel object, and create<br />

a castDirector CastingDirector object, we will reorganize our code into logical method structures for the major task<br />

areas that need to be addressed in the InvinciBagel class. After we do this, we’ll have eight logical method areas. These<br />

methods will then serve as “guides” to the functional areas that we will need to keep updated (add statements to) as<br />

we develop our game over the rest of the book. For instance, if we add an Actor to the game, we will do this by adding<br />

(instantiating) an Actor object inside of a .createGameActors() method, and then add the Actor object to a cast object<br />

created using our new CastingDirector() constructor method inside of a new .createCastingDirection() method.<br />

In addition to the .createGameActors() and .createCastingDirector() methods, our new methods will include the<br />

.loadImageAssets() method, the .createSceneEventHandling() method, the .createStartGameLoop() method,<br />

and the .addGameActorNodes() method. So, we will be creating half a dozen new methods for your InvinciBagel.<br />

java class during this chapter, to significantly “beef up” the top-level organizational structure for our game’s core<br />

class as well as its “top-level” .start() method. There’s only one method that will survive this process without any<br />

modifications; that will be the .addNodesToStackPane() method, that you created in Chapter 6 (see Figure 6-8 to<br />

refresh your memory).<br />

After we have reorganized our InvinciBagel.java code infrastructure, we can move on and start to create the<br />

program logic that will be used to create, and later control, the primary hero for our game, the InvinciBagel himself.<br />

This will involve using the Bagel() and CastingDirector() constructor methods, and then adding the iBagel Bagel<br />

object to the Scene Graph (StackPane root object) and CastingDirector castDirector object, using the .add() method<br />

call and the .addCurrentCast() method call respectively.<br />

After we have the iBagel Actor created, we will wire up its .update() method to the GamePlayLoop .handle()<br />

method, at which point we can start to build the programming logic that will move this InvinciBagel around on your<br />

Stage. At this point, things get more interesting, as we can start to define the movement boundaries for the Stage, the<br />

sprite image states (the nine different character positions), and how these relate to X (left-right) and Y (up-down) key<br />

usage. For instance, no movement will be standing, left and right will use running, up will use jump, down will land, or<br />

later on in the game design, certain key combinations can cause an InvinciBagel to fly and so on as we refine the code.<br />

229

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!