Game Development Reference
In-Depth Information
we do is update the state time based on the delta time so that we can decide which of the two
animation frames we need to use for rendering that squirrel later on.
The Platform Class
The Platform class is shown in Listing 9-13.
Listing 9-13. Platform.java, the Platform Class
package com.badlogic.androidgames.jumper;
import com.badlogic.androidgames.framework.DynamicGameObject;
public class Platform extends DynamicGameObject {
public static final float PLATFORM _ WIDTH = 2;
public static final float PLATFORM _ HEIGHT = 0.5f;
public static final int PLATFORM _ TYPE _ STATIC = 0;
public static final int PLATFORM _ TYPE _ MOVING = 1;
public static final int PLATFORM _ STATE _ NORMAL = 0;
public static final int PLATFORM _ STATE _ PULVERIZING = 1;
public static final float PLATFORM _ PULVERIZE _ TIME = 0.2f * 4;
public static final float PLATFORM _ VELOCITY = 2;
Platforms are a little bit more complex, of course. Let's go over the constants defined in the
class. The first two constants define the width and height of a platform, as discussed earlier.
A platform has a type; it can be either a static platform or a moving platform. We denote this via
the constants PLATFORM_TYPE_STATIC and PLATFORM_TYPE_MOVING . A platform can also be in one
of two states: it can be in a normal state—that is, either sitting there statically or moving—or
it can be pulverized. The state is encoded via one of the constants PLATFORM_STATE_NORMAL or
PLATFORM_STATE_PULVERIZING . Pulverization is, of course, a process limited in time. We therefore
define the time it takes for a platform to be completely pulverized, which is 0.8 seconds. This
value is simply derived from the number of frames in the Animation of the platform and the
duration of each frame—one of the little quirks we have to accept while trying to follow the MVC
pattern. Finally, we define the speed of moving platforms to be 2 m/s, as discussed earlier. A
moving platform will behave exactly like a squirrel in that it just travels in one direction until it hits
the world's horizontal boundaries, in which case it just inverts its direction.
int type;
int state;
float stateTime;
public Platform( int type, float x, float y) {
super (x, y, PLATFORM_WIDTH, PLATFORM_HEIGHT);
this .type = type;
this .state = PLATFORM _ STATE _ NORMAL ;
this .stateTime = 0;
if (type == PLATFORM _ TYPE _ MOVING ) {
velocity.x = PLATFORM _ VELOCITY ;
}
}
 
Search WWH ::




Custom Search