Game Development Reference
In-Depth Information
your InvinciBagel.java class during this chapter, to significantly “beef up” the top-level
organizational structure for our game's core class as well as its “top-level” .start()
method. There's only one method that will survive this process without any modifica-
tions; that will be the .addNodesToStackPane() method, that you created in Chapter 6
(see Figure 6-8 to refresh your memory).
After we have reorganized our InvinciBagel.java code infrastructure, we can move
on and start to create the program logic that will be used to create, and later control, the
primary hero for our game, the InvinciBagel himself. This will involve using the Ba-
gel() and CastingDirector() constructor methods, and then adding the iBagel Bagel ob-
ject to the Scene Graph (StackPane root object) and CastingDirector castDirector ob-
ject, using the .add() method call and the .addCurrentCast() method call respectively.
After we have the iBagel Actor created, we will wire up its .update() method to the
GamePlayLoop .handle() method, at which point we can start to build the program-
ming logic that will move this InvinciBagel around on your Stage. At this point, things
get more interesting, as we can start to define the movement boundaries for the Stage,
the sprite image states (the nine different character positions), and how these relate to
X (left-right) and Y (up-down) key usage. For instance, no movement will be standing,
left and right will use running, up will use jump, down will land, or later on in the
game design, certain key combinations can cause an InvinciBagel to fly and so on as
we refine the code.
InvinciBagel.java Redesign: Adding Lo-
gical Methods
The first thing that I want to do regarding the InvinciBagel.java code, which should
already be open in a tab in NetBeans (if it is not, use the right-click and Open work
process), is to reorganize the current code using a half-dozen new methods that logic-
ally contain, as well as show, the different areas that we will need to address in order to
add new Actors to our game. These include things such as managing event handling,
adding new Image asset references, creating the new game Actor objects, adding the
new actors to the Scene Graph, adding the new Actor objects to the CURRENT_CAST
List we created in Chapter 10 , and starting the GamePlayLoop AnimationTimer pulse
engine. The first thing that we should do is to put those Java statements that need to be
done first and that need to be in the .start() method itself at the top of the code. These
create the Scene Graph root, a Scene object, and set up the Stage object:
Search WWH ::




Custom Search