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

Another ArrayList Object: COLLIDE_CHECKLIST Data Store List<br />

Now let’s create our second List ArrayList data store object and call it COLLIDE_CHECKLIST since it<br />

will eventually be accessed in the .collide() method; this will happen if you implement complex multiple object<br />

collision lists in later advanced stages of game development. We will not get to the advanced level that will require<br />

implementation of this during this book, but I wanted to show you how to put a complete CastingDirector class<br />

together, so that you will have it in place when you need it for your game development, as you add more advanced<br />

features into your game. This object will hold the most current copy of the CURRENT_CAST ArrayList and<br />

will have two methods. The .getCollideCheckList() method will return the COLLIDE_CHECKLIST object, and the<br />

.resetCollideCheckList() will reset the COLLIDE_CHECKLIST, by using the .clear() method call, and for now, we<br />

will use the .addAll() method to load COLLIDE_CHECKLIST ArrayList object with the current version of the<br />

CURRENT_CAST ArrayList object. Later we can use this List to hold a custom collision checklist, that groups<br />

together only objects that can collide with each other into one List. The <strong>Java</strong> code, which can be seen in Figure 10-7,<br />

needed to declare and instantiate the object, should look like the following:<br />

private final List COLLIDE_CHECKLIST = new ArrayList();<br />

Figure 10-7. Add a COLLIDE_CHECKLIST List object, .getCollideCheckList(), and resetCollideCheckList()<br />

methods<br />

A .getCollideCheckList() method uses a return keyword, to give access to the COLLIDE_CHECKLIST, like this:<br />

public List getCollideCheckList() {<br />

return COLLIDE_CHECKLIST;<br />

}<br />

218

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

Saved successfully!

Ooh no, something went wrong!