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 final class LevelData
- Object
- LevelData
A platformer level as data, read from JSON and turned into a PlatformWorld.
The format is meant to be written by hand, by the level editor and by a
language model alike. Positions and sizes are in tiles, speeds in pixels per
tick, and every number may be a decimal (read exactly, see LevelJson):
{
"name": "First steps",
"tileSize": 16,
"tiles": [
"#..............#",
"#.........====.#",
"#.....H........#",
"#.....H..../####",
"################"
],
"spawn": [1, 3],
"goal": [14, 2, 1, 1],
"platforms": [{"path": [[3, 2], [8, 2]], "w": 2, "speed": 0.75, "pause": 30}],
"abilities": ["move", "ladder", "walljump", "jump", "crouch", "dash"],
"tuning": {"maxJumps": 2, "jumpSpeed": 4.6}
}tiles uses the actors listed on Tile. abilities lists the hero’s
abilities in processing order (names on Abilities); omitted, the hero gets
move, ladder, walljump, jump, crouch and dash. tuning keys are listed on
applyTuning. health gives the hero hit points (otherwise one hit kills) and
lives limits retries (otherwise unlimited). players (default 1) makes that
many heroes, hero, hero2, …, side by side at the spawn, for a
shared-screen game.
entities places everything else, each with "type" and "at": [col, row]:
coin, gem, heart, life, key and powerup (name: the key or the
ability), spring (power), checkpoint, door (key, h), gate
(channel, w, h, inverted), lever and plate (channel), crumble
(w, delay, respawn), crate (a PushBlock) and enemy (kind, brain, hp, damage,
speed, range, stompable, and opens: a channel its defeat turns on).
Other types go to an EntityFactory.
Methods
public static LevelData parse(String text) | Reads a level. |
public String getName() | The level’s name. |
public int getTileSize() | The tile size in pixels. |
public Map<String, Object> getJson() | The parsed JSON, for game-specific fields (enemies, pickups, art). |
public String[] getTiles() | The tile rows. |
public PlatformWorld createWorld(long seed) | Builds a fresh world with the hero at the spawn point. |
public PlatformWorld createWorld(long seed, EntityFactory factory) | Builds a fresh world, creating unknown entity types through a factory. |
public static void applyTuning(Actor c, Map<String, Object> t) | Applies tuning to an actor’s abilities. |
Inherited methods
Method details
parse
public static LevelData parse(String text)Parameters
textString- the level JSON
Returns
Throws
IllegalArgumentException- when the JSON or the level is malformed
getName
public String getName()Returns
getTileSize
public int getTileSize()Returns
getJson
public Map<String, Object> getJson()Returns
getTiles
public String[] getTiles()Returns
createWorld
public PlatformWorld createWorld(long seed)Parameters
seedlong- the random seed
Returns
createWorld
public PlatformWorld createWorld(long seed, EntityFactory factory)Parameters
seedlong- the random seed
factoryEntityFactory- the game’s own entity types, may be null
Returns
applyTuning
public static void applyTuning(Actor c, Map<String, Object> t)gravity, maxFall, walkSpeed, runSpeed, jumpSpeed,
maxJumps, coyoteTicks, bufferTicks, climbSpeed, dashSpeed,
dashTicks, wallSlide, automaticFire, shotGravity, fireCooldown.
Unknown keys are ignored so a game can keep its own
keys in the same object.Parameters
cActor- the actor
tMap<String, Object>- the tuning object, may be null