Game Development Reference
In-Depth Information
At this point, if you use a
Run Project
work process, you should have an
iBeagle shooting a Bullet or Cream Cheese Ball. When you catch the iBeagle with the
InvinciBagel character, you should score ten points, or, if you catch a Cream Cheese
Ball, you should get five points. If you get hit by a Bullet, you should lose five points.
You will notice as you test the InvinciBagel game application that once you get hit
by a Bullet, Cream Cheese Ball, or when you catch the iBeagle, that they do not come
back! This is because the collision detection programming logic removes an object
from the game once an InvinciBagel collects it (Treasure) or collides with it (Prop or
Projectile).
So the next step in our development will be to add in the programming logic that
adds an iBullet, iCheese or iBeagle object back into the castDirector object once they
have been removed by the collision detection programming logic that you put into
place in
Chapter 16
. To do this, we'll have to code an enhancement to the
CastingDir-
ector.java
class, code the new .loadEnemy(), .loadBullet() and .loadCheese() methods
at the bottom of the Enemy.java class, and add the appropriate programming logic im-
plementing these three new methods into the .initiateAttack() method.
Adding Bullets to a Clip: Updating .ad-
dCurrentCast()
Since we are going to add single (one at a time, not unmarried) Actor objects back into
the CURRENT_CAST List, we will need to modify the .addCurrentCast() method as it
currently only takes an Actor . . . series of objects and we need it to accommodate a
single added Actor object, like the addToRemovedActors() method does currently. You
can see the .addToRemovedActors() method at the bottom of
Figure 17-47
. The .ad-
dCurrentCast() method was designed to be used
statically
in the InvinciBagel.java
class, in the start() method, to add all of the cast members at one time (remember static
versus dynamic). Now I am going to show you how to redesign it to allow “one off”
additions during gameplay, which is a dynamic use of the method, as the List<Actor>
will be modified
dynamically
in real-time during gameplay. To upgrade the .addCur-
rentCast() method, simply “wrap” the .addAll() method call inside of the method with
an if(actors.length > 1) if-else structure, with the original code inside of the if() portion
and a
CURRENT_CAST.add(actors[0]);
statement inside of the else portion to
accommodate single Actor method calls. The Java code for the new method structure
can be seen in
Figure 17-47
, and should look like the following: