Class GameRules
A game's own rules over a PlatformWorld: when it is won, when it is lost,
what happens when an actor dies and what is checked every tick. The engine
knows how things move and collide; a game built on it says what they mean.
With no rules set, a world plays a classic platformer: the first actor is the player, reaching the goal rectangle completes the level, and a death costs a life and respawns at the last checkpoint. Override only what your game changes:
- a race won by whoever reaches the exit first: override
onStep, callPlatformWorld.completewith the winner; - an endless runner lost on the first hit: return true from
onDeathafterPlatformWorld.endGame; - a puzzle won when every block is on a target: count in
onStepand keep the count in a game counter (PlatformWorld.setCounter) so the HUD and the replay hash both see it.
Rules run inside the simulation, so they must be as deterministic as the
rest of it: fixed point only, no clock, randomness only from
PlatformWorld.getRng.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanonDeath(PlatformWorld world, Actor actor) Called when an actor runs out of health or falls out of the level.voidonStart(PlatformWorld world) Called once, before the first tick.voidonStep(PlatformWorld world) Called at the end of every tick, after everything moved and touched.booleanreachesGoal(PlatformWorld world, Actor actor) Whether reaching the goal rectangle completes the level for this actor.
-
Constructor Details
-
GameRules
public GameRules()
-
-
Method Details
-
onStart
Called once, before the first tick.
Parameters
world: the world
-
onStep
Called at the end of every tick, after everything moved and touched.
Parameters
world: the world
-
reachesGoal
Whether reaching the goal rectangle completes the level for this actor. The default lets only the first actor (the player) finish.
Parameters
world: the worldactor: the actor overlapping the goal
Returns
true to complete the level
-
onDeath
Called when an actor runs out of health or falls out of the level.
Parameters
world: the worldactor: the actor
Returns
true if the rules handled it; false for the default (a life lost and a respawn for the player, death for anyone else)
-