Class 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.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplyTuning(Actor c, Map<String, Object> t) Applies tuning to an actor's abilities.createWorld(long seed) Builds a fresh world with the hero at the spawn point.createWorld(long seed, EntityFactory factory) Builds a fresh world, creating unknown entity types through a factory.getJson()The parsed JSON, for game-specific fields (enemies, pickups, art).getName()The level's name.String[]getTiles()The tile rows.intThe tile size in pixels.static LevelDataReads a level.
-
Method Details
-
parse
-
getName
The level's name.
Returns
the name
-
getTileSize
public int getTileSize()The tile size in pixels.
Returns
the tile size
-
getJson
-
getTiles
The tile rows.
Returns
a copy of the rows, top first
-
createWorld
Builds a fresh world with the hero at the spawn point.
Parameters
seed: the random seed
Returns
a world ready to step
-
createWorld
Builds a fresh world, creating unknown entity types through a factory.
Parameters
seed: the random seedfactory: the game's own entity types, may be null
Returns
a world ready to step
-
applyTuning
Applies tuning to an actor's abilities. Keys, all optional, in pixels and ticks:
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
c: the actort: the tuning object, may be null
-