Game Development Reference
In-Depth Information
to indicate that a collision has been detected, the type of collision that has occurred
(good or bad), and that the scoreboard has been updated, since after all, this program-
ming logic is contained in the scoringEngine() method and thus should pertain to the
act or scoring in some way or another.
After we test this conditional if() programming logic and make sure that everything
works as anticipated, we can take a look at how to add optimization into this .scorin-
gEngine() method, and then we will be ready to add some more Actor types, such as
the Treasure.java class, which we will be adding next. After that, we can add some en-
emies (adversaries) to the InvinciBagel game, as we continue to add features that make
our game play more fun and exciting during the course of this chapter.
Test the game, using the Run
Project work process. As you can see in Figure
17-11 , the scoreboard works!
Figure 17-11 . Use Run
Project to test the game, and collide with the objects on the screen, updating your score-
board
Optimizing the scoringEngine() Method: Using Logic-
al If Else If
Although the previous series of if() statements will do the job that we are trying to do
here, we really need to emulate the break; statement that we would have at our dis-
posal if we were using the Java switch-case statement type. To optimize this method,
we want to break out of this evaluation series once the object type that is involved in
the collision has been determined. We can do this by attaching all of these conditional
if() statements together, using the Java else-if capability. If a condition in this structure
is satisfied, the rest of the if-else-if structure is not evaluated, which is the equivalent of
 
 
Search WWH ::




Custom Search