Game Development Reference
In-Depth Information
public void addCurrentCast( Actor actor ) {
CURRENT_CAST. add ( actor );
}
Once your game design becomes more advanced and you have decorative Actor
objects on the Stage, you can implement the COLLIDE_CHECKLIST in your if()
structures that need to iterate through (only) the Actor objects in your Scene that need
to be processed for collision.
At this point in our game design, we are processing all of the Actor objects for col-
lision, thus, we don't yet need to implement the COLLIDE_CHECKLIST List<Actor>
Array. I've included it in the class design to be thorough and because I design founda-
tional classes for games by looking out into the future toward what I will need in order
for me to create an advanced (complete) game engine. That said, we may not have
enough pages in this Beginner title to get that advanced, but the functionality is there if
you needed to use it in your games, and after this chapter you will have plenty of ex-
perience using if() structures!
Now that we can add cast members on an individual basis, it is time to write the
methods that will allow us to check the CURRENT_CAST List<Actor> Array to make
sure that there are iBullet, iCheese, and iBeagle Actor objects in place for us to use for
the next iteration of the auto-attack engine. What these methods will do is to look for
these Actor objects in the CURRENT_CAST List, and if they are not present, will add
one of them to the List so that it is ready for any type of attack that our conditional if()
statements and random number generator create together!
We'll write three methods, one for deadly projectiles, called .loadBullet() ; one for
healthy projectiles, called .loadCheese() ; and one for Enemy objects, called
loadEnemy() . This will give us the ultimate flexibility, later on in our game develop-
ment, of calling each type of functional Actor object type in its own “replenishment
function.”
Each method will look through the entire CURRENT_CAST List, using a for()
loop, along with a .size() method call. In this way, the entire List is processed, from the
first element (zero), through the last element (the List's size).
If there is no Actor object of that type found in the cast, that is, if the for() loop is
completed, and no object of that type is found, after looking through the entire
CURRENT_CAST List<Actor> for a match using object.equals() , then the two state-
ments after the for loop will be executed.
The first statement will add one Actor object of that type to the CURRENT_CAST
List<Actor>, and the second statement will then add one Actor object of that type to
Search WWH ::




Custom Search