Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public class PlatformWorld
- Object
- PlatformWorld
The whole platformer simulation: a TileGrid, its MovingPlatforms, the
Actors and LevelEntitys in it, advanced one fixed tick (1/60 s) at a time.
The world is deterministic. Given the same level and the same Input bits per
tick it reaches the same hash() on every device and on the server, which is
what Replay relies on to verify a run. Rendering never feeds back into it: a
view reads positions after each step, interpolates between them, and plays
the tick’s getEvents().
It also keeps the level’s bookkeeping, the part of Corgi Engine’s level and game managers that affects play: score, coins, secrets, keys, lives, the respawn point and the switch channels.
Fields
public static final int TICKS_PER_SECOND = 60 | The rate the world is designed for. |
public static final int COUNTERS = 16 | How many game counters a world keeps. |
Constructors
public PlatformWorld(TileGrid grid, long seed) | Creates a world over a grid. |
Methods
Inherited methods
Field details
TICKS_PER_SECOND
public static final int TICKS_PER_SECOND = 60COUNTERS
public static final int COUNTERS = 16Constructor details
PlatformWorld
public PlatformWorld(TileGrid grid, long seed)Parameters
gridTileGrid- the level’s collision map
seedlong- the random seed
Method details
addPlatform
public void addPlatform(MovingPlatform p)Parameters
pMovingPlatform- the platform
addActor
public void addActor(Actor c)step drives
with its first input; actors with a brain ignore their input slot.
Unlike an entity, an actor added during a step (from the rules, a touch
or a brain) joins at once and is stepped, touched and hit in that same
tick; it is deterministic either way, so replays agree.Parameters
cActor- the actor
addEntity
public void addEntity(LevelEntity e)Parameters
eLevelEntity- the entity
setRules
public void setRules(GameRules rules)Parameters
rulesGameRules- the rules, or null for a classic platformer
getRules
public GameRules getRules()Returns
setPlayerCount
public void setPlayerCount(int count)Parameters
countint- one or more
getPlayerCount
public int getPlayerCount()Returns
isPlayer
public boolean isPlayer(Actor c)Parameters
cActor- the actor
Returns
getPlayerCount() actorsnearestPlayer
public Actor nearestPlayer(Actor from)Parameters
fromActor- the actor looking
Returns
complete
public void complete(Actor by)Parameters
byActor- the winner, may be null
endGame
public void endGame()getWinner
public Actor getWinner()Returns
getCounter
public int getCounter(int index)hash(), so a replay checks them too.Parameters
indexint- 0 to
COUNTERS - 1
Returns
setCounter
public void setCounter(int index, int value)Parameters
indexint- 0 to
COUNTERS - 1 valueint- the value
addCounter
public void addCounter(int index, int delta)Parameters
indexint- 0 to
COUNTERS - 1 deltaint- the amount
setSpawn
public void setSpawn(int x, int y)Parameters
xint- left, fixed point
yint- top, fixed point
setGoal
public void setGoal(int x, int y, int w, int h)Parameters
xint- left, fixed point
yint- top, fixed point
wint- width, fixed point
hint- height, fixed point
step
public void step(int[] inputs)Parameters
inputsint[]Inputbits per actor
step
public void step(int input)Parameters
inputint- the player’s
Inputbits
damage
public boolean damage(Actor c, int amount, int fromX)fromX, and kills it at zero. An actor without HitPoints dies
at once.Parameters
cActor- the actor
amountint- hit points
fromXint- where the hit came from, fixed point x
Returns
onDeath
protected void onDeath(Actor c)Parameters
cActor- the actor
emit
public void emit(int type, int x, int y, String subject, String detail)Parameters
typeint- a
WorldEventconstant xint- where, fixed point
yint- where, fixed point
subjectString- the id involved, may be null
detailString- extra detail, may be null
getEvents
public List<WorldEvent> getEvents()Returns
enableAbility
public void enableAbility(Actor c, String name)Parameters
cActor- the actor
nameString- a stock ability name (see
Abilities)
isChannelOn
public boolean isChannelOn(int channel)Parameters
channelint- 0 to 31
Returns
setChannel
public void setChannel(int channel, boolean on)Parameters
channelint- 0 to 31
onboolean- the new state
addScore
public void addScore(int points)Parameters
pointsint- the points
addCoins
public void addCoins(int n)Parameters
nint- the coins
addSecret
public void addSecret()addLife
public void addLife()addKey
public void addKey(String name)Parameters
nameString- the key name
useKey
public boolean useKey(String name)Parameters
nameString- the key name
Returns
getKeys
public List<String> getKeys()Returns
getLives
public int getLives()Returns
setLives
public void setLives(int lives)Parameters
livesint- the lives
setStompBounce
public void setStompBounce(int speed)Parameters
speedint- fixed point per tick
getScore
public int getScore()Returns
getCoins
public int getCoins()Returns
getSecrets
public int getSecrets()Returns
getGrid
public TileGrid getGrid()Returns
getPlatforms
public List<MovingPlatform> getPlatforms()Returns
getActors
public List<Actor> getActors()Returns
getEntities
public List<LevelEntity> getEntities()Returns
getPlayer
public Actor getPlayer()Returns
getRng
public Rng getRng()Returns
getTick
public int getTick()Returns
isComplete
public boolean isComplete()Returns
isGameOver
public boolean isGameOver()Returns
getDeaths
public int getDeaths()Returns
getSpawnX
public int getSpawnX()Returns
getSpawnY
public int getSpawnY()Returns
getGoal
public int[] getGoal(){x, y, w, h}, fixed point.Returns
hash
public long hash()