28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 14<br />

Setting Up the Game Environment:<br />

Creating Fixed Sprite Classes Using<br />

the Actor Superclass<br />

Now that we made a significant amount of progress creating your primary InvinciBagel character, using a number of<br />

key methods in the Bagel.java class, as well as the Actor and Hero superclasses, all of which we put into place along<br />

with the GamePlayLoop class and CastingDirector class in Chapters 7 through 13, it is time to add fixed sprite objects,<br />

which I will call “Props,” into the Scene and on the Stage (on the screen). These fixed objects are almost as important<br />

to the game as the main character himself, as they can be used to provide obstacles, barriers, protection from the<br />

enemy, and various challenges for the primary game hero character to overcome. We will also need these fixed objects<br />

in the Scene to use in our collision detection program logic, and to test our CastingDirector class (object).<br />

If you remember, back in Chapter 8, we created the Actor superclass with fixed sprites in mind and the Hero<br />

superclass with motion sprites in mind. I started out with the motion sprites, because the primary game character is a<br />

motion sprite, and even though motion sprites are more complex, by their very nature, they are also a lot more fun to<br />

play around with! Now I need to take a chapter and put the Actor superclass into action and create some Prop-related<br />

subclasses. We will use these Actor subclasses to populate our Scene (Stage) with things such as platforms, obstacles,<br />

barriers, bridges, treasure, and similar game play fixed location objects that you will want to add into the Scene (on<br />

the Stage) to create a game world and enhance the game play experience (also known as user experience).<br />

We’ll create four fixed Prop subclasses, using the Actor superclass, which will make it easy to construct fixed<br />

scenes (also called levels, when you have created more than one). The Prop.java class will use your fixed sprite Image<br />

assets “as-is,” while the PropH.java class will set the isFlipH property to true and mirror the image asset around<br />

the Y axis, using a <strong>Java</strong>FX spriteFrame.setScaleX(-1); <strong>Java</strong> statement. The PropV.java class will set the isFlipV<br />

property to true and mirror the image asset around the X axis, using a <strong>Java</strong>FX spriteFrame.setScaleY(-1); <strong>Java</strong><br />

statement. The PropB.java class (B stands for “both”) will set both the isFlipV property and isFlipH property to true,<br />

which would mirror an image asset around both the X and Y axis, using two <strong>Java</strong>FX spriteFrame.setScale(-1); <strong>Java</strong><br />

statements.<br />

Once we have created these four Prop-related Actor subclasses, we will use them to place fixed objects into the<br />

Scene to create the first level of this game. That way, when we get into the collision detection chapter, everything that<br />

would be in a real game will be in place, and we will be able to start coding the collision detection logic; and then,<br />

eventually, an auto-attack engine; and then game play logic, which dictates how the scoring engine is implemented.<br />

This chapter will be valuable in creating a more feature-filled game. A major part of any game design, in this case,<br />

it is Ira H. Harrison Rubin’s InvinciBagel character and game, is building the environment that the characters (the<br />

hero and his or her enemies, whether in a single-player or a multi-player game) engage in is critical to the success and<br />

popularity of the game, since these fixed elements are a major part of creating the game play challenge for the player.<br />

www.it-ebooks.info<br />

299

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

Saved successfully!

Ooh no, something went wrong!