Log inGet started
World

Pixel Ledges: 2D Platformer Kit with Sprites, Tilemaps, Wall Jumps and Dash

README.md

Level2D

A 2D platformer level painted from text: type rows of characters into text and it becomes a playable tilemap: autotiled ground with the right edge and corner tile in every cell, merged seamless collision, one-way platforms, spikes, scattered decorations, Trapline checkpoints with pixel flags, platformsKit moving platforms drawn as tile-set planks, spinning gems, a goal, the player start, a kill zone below, and a parallax background behind it.

Put it on any scene entity; the entity's position is the bottom-left corner of the grid and one character is one world unit (16 art pixels). Several Level2D entities can sit side by side in one scene. Players (twoDKit.Player2D), the camera (twoDKit.Camera2D) and the HUD find it through twoDKit.levels. Checkpoints and the kill zone need the Trapline package, moving platforms the platformsKit package; without them those pieces are skipped.

local lvl = entity.spawn("CaveLevel")
lvl.position = { 0, 0, 0 }
lvl.component.add("twoDKit.Level2D", { theme = "cave", camera = "smooth", text = [[
##############################
#............................#
#..P.......o......=====...G..#
#.........###.............####
#....C..^^###....M.....^^#####
##############....############
]] })

Legend

# ground, = one-way platform, ^ spikes (point away from the solid beside them), B back wall (drawn behind, no collision), P (or S) player start, C checkpoint, M moving platform side to side, V moving platform up and down, o gem, G goal, * forced decoration, . or space empty. Unknown characters count as empty and are warned about (see problems()). Full format: twoDKit.level.

Fields (local, not synced)

FieldDefaultWhat
text""The level, top row first. Changing it rebuilds everything.
theme"grassland"grassland, cave, castle, lab, snow or desert: tile set and background together.
tileset"auto"Tile set override (auto follows the theme).
background"auto"Background override (auto follows the theme, none = no background).
camera""Camera style this level asks Camera2D for: pixelPerfect, smooth, rooms ("" = the camera's own).
seed1Where decorations grow.
decorationstrueScatter the tile set's decorations on free floor tiles.
killDepth3Trapline kill zone this many tiles below the bottom row (0 = none).
checkpointStyle"flag"How each C looks: flag, lantern, campfire, banner (totem banner) or beacon (sci-fi), each with an idle and a reached animation (Catalog.checkpointLookList). Old Trapline look names map to the nearest one.
gemLook"crystal"How each o looks: crystal, coin, star, cherry, orb (soul flame) or battery (power cell), each animated with its own collect burst (Catalog.gemLookList).
moverLength / moverTravel / moverSpeed4 / 5 / 2Width and travel in tiles, and speed in tiles/s, of M / V platforms.
roomWidth / roomHeight20 / 12Room size in tiles for the rooms camera.
edgeWallstrueInvisible walls just past the left and right edges. false joins rooms: place two Level2Ds side by side (the second at the first's x + width) with a gap in their touching edge columns and a player walks from one into the other; stack them (the lower one's top at the upper one's bottom) with a gap in the floor and ceiling rows to fall and jump between them (use killDepth = 0 on the upper room). With it off the kill zone spans only the level's own width. Camera2D clamps to whichever level the player is in, and only that level draws its background.

Changing theme, tileset, background, decorations, seed, gemLook or checkpointStyle rebuilds only the pictures, live; collision, checkpoints and platforms stay as they are.

Methods

  • problems(): problems found the last time the text was read.
  • size(): width and height in tiles.
  • startPosition(): world position { x, y, z } (feet) of the P marker, or a point 2 tiles in from the bottom-left corner when there is none.
  • setTheme(id): set theme and put tileset and background back to auto.

How it works

Every peer builds the same level from the same text on temporary child entities, so nothing about the level crosses the network and nothing it spawns is saved. Solid cells merge into as few BoxCollider rectangles as possible (no seams to catch on), one-way runs become thin one-way colliders at the top of their cells, and tall walls close the left and right edges. Only the level the view is in draws its background. Gem pickups are per player: a gem bursts and disappears for a player once that player's Player2D has taken it. Each C is a Trapline.Checkpoint with look none: Trapline handles touching it and coming back at it and builds and animates nothing, so a checkpoint costs next to nothing per frame; the kit draws the pixel checkpoint from art/fx/checkpoints and gems from art/fx/gems (painted by twoDKit.artgen.pickups).