Graphics Programs Reference
In-Depth Information
Listing 6-20. TANK FENCE GAME 5/src/com/apress/android/tankfencegame5/
Enemy.java
public void interpolateXY() {
if(_sourcePositionX >= 0) {
_destinationPositionX = _destinationPositionX - _dx;
_destinationPositionY = _destinationPositionY - _dy;
}
if(_sourcePositionX < 0) {
_destinationPositionX = _destinationPositionX + _dx;
_destinationPositionY = _destinationPositionY + _dy;
}
}
Listing 6-21. TANK FENCE GAME 5/src/com/apress/android/tankfencegame5/
Enemy.java
public Enemy(float positionX, float positionY, float
positionZ, float slopeZ) {
_sourcePositionX = positionX;
_sourcePositionY = positionY;
_sourcePositionZ = positionZ;
_destinationPositionX = positionX;
_destinationPositionY = positionY;
_destinationPositionZ = positionZ;
_slopeZ = slopeZ;
_dy
= _dx * _slopeZ;
}
Now, you need to make a couple of changes to the Renderer class to use the _en-
emies ArrayList . The new argument in the Enemy() constructor (see Listings
6-16 and 6-21 ) is added so that you can directly specify the slope. As we are spawn-
ing the Enemy objects in a symmetrical manner, we can easily pass the slopes:
// 10.0005, 10.0, 0.1005
GLES20Renderer._enemies.add(new Enemy(2 * 10.0005f, 2
* 10.0f, 0, 1.00005f));
 
 
Search WWH ::




Custom Search