public abstract class GameLevel
extends java.lang.Object
For our purposes, a level is loosely defined by having a background, some number of sprites that stick around for a while, and some kind of goal to get to the end of the level. To make things simple, we treat an opening screen as its own level as well (with the goal being to choose what game to play!)
When a level is complete, it can ask the game manager to start up another level with the
GameObjectManager.setLevel(GameLevel)
call. That new level can be a different
subclass of GameLevel, or the same subclass but with a different (presumably more
difficult) configuration.
Modifier and Type | Field and Description |
---|---|
protected GameObjectManager |
mManager
Reference to the game object manager currently in charge.
|
Constructor and Description |
---|
GameLevel()
This constructor does nothing.
|
Modifier and Type | Method and Description |
---|---|
void |
finish()
Called by the game object manager when this level is about to be destroyed before starting
a new level.
|
boolean |
onAnyFling(float x,
float y,
float dx,
float dy)
Override this routine if you want your central game logic to handle ALL screen fling actions.
|
boolean |
onAnyTouch(float x,
float y)
Override this routine if you want your central game logic to handle ALL screen touches.
|
void |
onUnclaimedFling(float x,
float y,
float dx,
float dy)
Override this routine if you want your central game logic to handle screen fling actions that
don't start on a game object.
|
void |
onUnclaimedScroll(float x,
float y,
float dx,
float dy,
boolean finished)
Override this routine if you want to detect "scroll" events on the screen.
|
void |
onUnclaimedTouch(float x,
float y)
Override this routine if you want your central game logic to handle screen touches that
don't hit any game objects.
|
void |
setObjectManager(GameObjectManager manager)
Called by the object manager to configure this level.
|
void |
setup()
Your setup method is where all your work for setting up a new level should go.
|
void |
update(int millis)
You can choose how much of your game logic is done by individual sprites and how much
is done centrally here in your override of the update method.
|
protected GameObjectManager mManager
This is used by the game level to configure the world size, set a scene, and add sprites or other game objects to be managed. (updated and drawn on the screen).
public GameLevel()
public void setObjectManager(GameObjectManager manager)
manager
- public void setup()
public void update(int millis)
millis
- number of milliseconds since the previous game engine update.public boolean onAnyTouch(float x, float y)
Any time the screen is touched, this method will be called first to give your central game logic a shot at doing something about the touch. If you want to accept this event and keep it from being passed to any game objects, return true. If you return false, every game object will be compared for overlap.
x
- horizontal coordinate of the point tapped, in world unitsy
- vertical coordinate of the point tapped, in world unitstrue
to swallow the event, false
to pass it on to game objectspublic void onUnclaimedTouch(float x, float y)
After all the game objects have been checked for overlap with a touch, if none of them was a 'hit', then this routine will be called. This might be useful, for example, to play a sound indicating they didn't tap the right place, or to pop up instructions on how to use the controls for the game.
x
- horizontal coordinate of the point tapped, in world unitsy
- vertical coordinate of the point tapped, in world unitspublic boolean onAnyFling(float x, float y, float dx, float dy)
Any time the user flings, this method will be called first to give your central game logic a shot at doing something about the fling. If you want to accept this event and keep it from being passed to any game objects, return true. If you return false, every game object will be compared for overlap.
x
- horizontal coordinate of the point the fling started, in world unitsy
- vertical coordinate of the point the fling started, in world unitstrue
to swallow the event, false
to pass it on to game objectspublic void onUnclaimedFling(float x, float y, float dx, float dy)
After all the game objects have been checked for overlap with a fling, if none of them was a 'hit', then this routine will be called. This might be useful, for example, if your game simply uses flings at the side of the screen to contol your character, so you don't care where the fling action happened but simply about the direction.
x
- horizontal coordinate of the point the fling started, in world unitsy
- vertical coordinate of the point the fling started, in world unitsdx
- horizontal velocity of the flingdy
- vertical velocity of the flingpublic void onUnclaimedScroll(float x, float y, float dx, float dy, boolean finished)
Note that a 'scroll' is a slow, deliberate movement of the finger across the screen with a defined starting and stopping point. This is the kind of movement you might need for stretching the slingshot in a game like angry birds.
Also important is the fact that you will get many of these callbacks with finished == false as the finger is moved around, and then one last callback with finished == true. That way you can make sound effets or change the slingshot image on screen while the user decides just how far to pull it.
x
- horizontal coordinate of the point the scroll started, in world unitsy
- vertical coordinate of the point the scroll started, in world unitsdx
- horizontal distance the user's finger has draggeddy
- vertical distance the user's finger has draggedfinished
- true
if this is the final event (user just lifted their finger)public void finish()
If you have any important cleanup code to do (for example, stopping the background music for one level before beginning another, once we support that) then override this method and put that code there.