Graphics Programs Reference
In-Depth Information
}
After obtaining a reference to the current Enemy object, its coordinates (x and y)
are interpolated by calling the interpolateXY() method. As discussed already,
while interpolating these coordinates we need to test if the corresponding Enemy ob-
ject has entered the (white) plane. If an Enemy object enters this plane, it is removed
from the ArrayList by calling the remove() method. Else, the model matrix
enemiesMMatrix is translated. First, it is translated to the spawning position, and
then it is translated using the interpolated values. For the latter, we need to obtain the
difference between the source position (i.e., the spawning position of current Enemy
object) and the current (interpolated) position. In Listing 6-22 , the local variables dx
and dy are used to store this difference, separately for the x-coordinate and the y-
coordinate. Finally, the renderEnemies() method is called to render the current
Enemy object.
Detecting
Collisions
to
Annihilate
the
Enemy
In this section I'll describe the code for annihilating the Enemy objects using missiles
( Figures 6-11 and 6-12 ) . Begin by modifying the Renderer class of the TANK
FENCE GAME 5 application. Clear the lines of code between the if block that tests
for the size of _missiles ArrayList and the call to the renderModel()
method. This should result in the following lines of code in the onDrawFrame()
method:
public void onDrawFrame(GL10 gl) {
System.gc();
long deltaTime,startTime,endTime;
startTime = SystemClock.uptimeMillis() % 1000;
gl.glClear(GLES20.GL_COLOR_BUFFER_BIT |
GLES20.GL_DEPTH_BUFFER_BIT);
if(GLES20Renderer._zAngle >= 360) {
 
Search WWH ::




Custom Search