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 8 ■ Creating Your Actor Engine: Design the Characters for Your Game and Define Their Capabilities<br />

The .handle() method in a GamePlayLoop object will call these .update() methods, so there is a connection<br />

there as well. There are connections between the Actor and Hero classes with the InvinciBagel class, as all your<br />

game sprite objects created using these abstract classes will be declared and instantiated from within a method in<br />

this class.<br />

We are making great progress on developing our game engine framework, while at the same time, seeing<br />

how some of the core features of the <strong>Java</strong> 8 programming language can be implemented to our advantage. We will<br />

be looking at the powerful new <strong>Java</strong> 8 lambda expressions feature in the next chapter on event handling as well,<br />

so more knowledge regarding leading-edge <strong>Java</strong> 8 features is right around the (game) bend. I hope you are as<br />

excited as I am!<br />

Summary<br />

In this eighth chapter, we wrote the second round of the several game engines that we will be designing and coding<br />

during this book, the Actor (fixed sprites) superclass, and its Hero (motion sprites) subclass. Once we start creating<br />

our game sprites in Chapter 10 and subsequent chapters, the Hero class will also become a superclass. Essentially,<br />

during this chapter you learned how to create public abstract classes, which will be used to define our sprite objects<br />

from here on out during the book. What this amounts to is doing all the heavy lifting (sprite design and coding work)<br />

up front for all of the actors (sprites) in our game, making the creation of powerful fixed and motion sprites for our<br />

game much easier for us to do from here on out. We are building both our knowledge base and our game engine<br />

framework first!<br />

We first took a look at how these Actor and Hero classes would be designed, as well as what types of actual sprite<br />

classes we would be creating with them. We looked at nine sprite Image assets, and how these covered a wide range of<br />

motions by using only nine assets, and looked at how to “register” the sprite “states” relative to each other.<br />

Next, we designed and created our Actor superclass, to handle fixed sprites such as props and treasure, creating<br />

the basic List, ImageView, SVGPath, iX and iY variables and a constructor method that used these to define<br />

the fixed sprite appearance, position, and collision boundaries. Then we added some additional variables that we will<br />

be needing for future game design aspects, and learned how to have NetBeans write .get() and .set() methods.<br />

Next, we designed and created our Hero subclass, which extends Actor to handle motion sprites such as the<br />

InvinciBagel himself and his enemies, as well as projectiles and moving challenges. We created the basic constructor<br />

method that sets the variables from the Actor superclass, this time to define a motion sprites imagery, initial position,<br />

and collision boundaries. Then we added some additional variables, which we will be needing for future game design<br />

aspects, and again saw how NetBeans will write our .get() and .set() methods for us, which is always fun to watch!<br />

Finally, we took a look at an updated invincibagel package, class and object structure diagram, to see just how<br />

much progress we have made so far during the first eight chapters of this book. This is getting pretty exciting!<br />

In the next chapter, we are going to take a look at how to control the game sprites that we will create using this<br />

Actor engine that we have created during this chapter. This next Chapter 9 will cover <strong>Java</strong> 8 and <strong>Java</strong>FX event handling,<br />

which will allow our game player to manipulate (control) these actor sprites using event handling.<br />

186<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!