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 10 ■ Directing the Cast of Actors: Creating a Casting Director Engine and Creating the Bagel Actor Class<br />

Figure 10-16. Override public boolean .collide() method body, for our use later on during a collision detection chapter<br />

We have made a lot of good progress in this chapter, creating a Casting Director and the Star for your game!<br />

Summary<br />

In this tenth chapter, we added two key classes to the game: the CastingDirector.java class and the Bagel.java class.<br />

The first performs a cast management and collision management functionality, and the second adds the primary<br />

actor for the game, so that we can start to work on how the InvinciBagel moves around the screen. We looked at a<br />

diagram of our current package and class structure and how the new classes are going to fit into an overall game<br />

engine design strategy that we are implementing during this book.<br />

We learned what a <strong>Java</strong> interface is, and how <strong>Java</strong> interfaces will allow us to control what’s implemented by other<br />

developers regarding our classes. We also learned about the <strong>Java</strong> Collection Framework, which provides things such<br />

as Arrays, Lists and Sets to use to provide data store functionality for our <strong>Java</strong> 8 and <strong>Java</strong>FX applications (games).<br />

We learned about the java.util package and its List interface, as well as the ArrayList class, and how the<br />

ArrayList class implements this List interface. We learned about Elements, Keys, Values, and<br />

Types. We learned that the List and ArrayList objects have a structure and an order, whereas the Set and HashSet<br />

objects do not have a specific order, and cannot have duplicate elements.<br />

Next we created your CastingDirector.java class, to manage the Actor objects that will need to be added to the<br />

game and removed from the game. This class will also maintain the List structure that will be used for the<br />

collision detection logic that we will be adding later on during the book in Chapter 16.<br />

Finally, we created our first Actor related class, the Bagel class, which extends the Hero superclass and will allow<br />

us to put the primary InvinciBagel Actor object character into our game Scene and onto the Stage. We created the<br />

Bagel() constructor method and used the @Override keyword to override the .update() and .collide() methods, so<br />

that we have someplace to construct our programming logic relating to this character during the rest of the book.<br />

In the next chapter, we’re going to take a look at how to move the game sprite around the screen using this<br />

KeyEvent event handling structure that we have created during this chapter, as well as how to ascertain the boundary<br />

(edges) of the screen, character direction, movement velocity, and related animation and movement considerations.<br />

www.it-ebooks.info<br />

227

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

Saved successfully!

Ooh no, something went wrong!