Graphics Programs Reference
In-Depth Information
are incremented because the interpolated positions of Enemy objects
do not represent the actual centers of the corresponding Enemy ob-
jects (w.r.t. the global center), which is why they have to be adjus-
ted.
Now, obviously, when this difference is zero it would imply that the centers overlap.
For such a difference, targeting (
Figure 6-11
)
has to be very accurate. We can
avoid the need for such precise accuracy. As shown in
Listing 6-23
-
if(Matrix.length(difference[0], difference[1], 0) < 3)
- using the
Matrix.length(float vec[0], float vec[1], float
vec[2])
method, we can obtain the length of vector
vec
. Here, instead of testing
for a condition where length is equal to zero, we test if the length is less than three.
This makes it easier to target the Enemy objects.
Finally, if this condition holds true, set the
renderEnemy
flag to
false
. And then,
remove the current missile and the current Enemy object from their corresponding
ArrayList
. This will annihilate the missile and Enemy objects, as shown in
Fig-
ure 6-12
.
The game is still not complete. Now, it's your job to integrate menus with this game
refer back to the
GAME MENU
application (
Chapter2/gamemenu.zip
) to re-
fresh your memory about the code requirements for creating simple game menus.
Summary
At the start of this chapter you learned about a simple way for Android ES 2.0 applic-
ations to reduce their power consumption. Then we continued developing the
Tank
Fence
game; you learned about adding the Missile and Enemy game objects.
You can extend the
Tank Fence
game to incorporate advanced techniques of object-
oriented programming.
Beginning Android Games, Second Edition
by Mario Zech-
ner and Robert Green (Apress, 2012) provides a complete description of how to build
an Android game framework.