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 />

A .resetCollideCheckList() method uses a .clear() method to clear out the COLLIDE_CHECKLIST and then uses<br />

an .addAll() method to add (insert) the contents of the CURRENT_CAST object into the COLLIDE_CHECKLIST object.<br />

public void resetCollideCheckList() {<br />

COLLIDE_CHECKLIST.clear();<br />

COLLIDE_CHECKLIST.addAll(CURRENT_CAST);<br />

}<br />

Now that we have our ArrayList objects set up to hold cast members and advanced collision list data sets,<br />

let’s create a HashSet object. This Set object will be used to collect Actors that for one reason or another need<br />

to be removed from the game play (the Scene and the Stage).<br />

Creating a HashSet Object: REMOVED_ACTORS Data Store Set<br />

Now let’s create our third Set HashSet data store object, and let’s call it REMOVED_ACTORS, since it will<br />

be used to hold a collection of Actor objects that have been removed from the current Stage. This Set object<br />

will hold all of the Actor objects that for whatever reason need to be removed from the CURRENT_CAST List. The<br />

REMOVED_ACTORS data store (data set) will have three associated methods.<br />

The .getRemovedActors() method will return the REMOVED_ACTORS object, the .addToRemovedActors() will<br />

be the “core” method that will add Actor objects to the REMOVED_ACTORS Set object as things happen<br />

during game play (finding treasure, killing enemies, etc.) that eliminate an Actor object from the Stage and Scene,<br />

and the .resetRemovedActors() that will use the .removeAll() method to remove Actors from the CURRENT_CAST<br />

ArrayList object, and then reset the REMOVED_ACTORS data set, by using the .clear() method call on the<br />

REMOVED_ACTORS HashSet object. The code, seen in Figure 10-8, needed to declare and instantiate the HashSet<br />

object using the <strong>Java</strong> new keyword, looks like this:<br />

private final Set REMOVED_ACTORS = new HashSet();<br />

Figure 10-8. Add a private final Set named REMOVED_ACTORS and use the <strong>Java</strong> new keyword to create a HashSet<br />

www.it-ebooks.info<br />

219

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

Saved successfully!

Ooh no, something went wrong!