The heart of Tiled support: load a map and draw it.
- rt_tmap model (Tmap/TmLayer/TmTileset in tiled.ludic): map header + ordered
layers (dense int32 GID arrays, heap-allocated to w*h, lifting the 96x64 cap)
+ tilesets. Built from the intermediate Value tree, so the TMX and TMJ paths
both feed it.
- GID resolver (Tiled.resolve): gid -> (tileset, localId, flipH/V/D); the three
flip flags masked off before the local-id lookup, returned alongside. gid==0
is empty.
- Image-backed render (Tiled.draw): every visible tile layer in file order,
blitting each tile from its tileset image with flips applied at draw.
- Compatibility projection (Tiled.project / auto on load): a designated
collision layer projects to the legacy byte tilemap ('#' solid, '=' one-way
via the oneway property, ' ' empty) so Grid.*/Path.*/esys_move are unchanged.
- Tiled.load resolves external tilesets + images relative to the map file and
auto-projects a collision/solids/walls layer.
- The grid and physics_tiles demos now run off a loaded map (grid_maze.tmx /
physics_map.tmx) instead of hand-authored Map.row strings, byte-identically.
Two compiler fixes fell out of this (see the changeset):
- emit_index_addr set g_addr_ty before evaluating the index, so slice[obj.field]
came back mis-typed; set it last, like the raw-pointer branches.
- @strcmp was declared by both the world table and the fs prelude; centralise
it in the head prelude so a game that uses Fs/Path links.
Proven by library/tiled_p1.ludic (14 assertions: loads+renders Kenney map
identically from .tmx and .tmj, flip mirroring) + the converted grid/
physics_tiles demos. x test: 92 passed; self-host bootstrap fixpoint intact.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
84 lines
3.8 KiB
Text
84 lines
3.8 KiB
Text
# physics_tiles.ludic — the tile-grid broadphase of the #65 movement system:
|
|
# `esys_move` resolves a Body against the Map.* tilemap (the platformer /
|
|
# top-down world), configured by a single `Solids { tile, wall, oneway }` entity.
|
|
# Reuses the same deterministic swept-AABB core as entity collision; verifies a
|
|
# tile floor, a tile wall, and a one-way tile platform (land from above, rise
|
|
# through from below).
|
|
#
|
|
# Deterministic, so a full run prints: 112 1 80 1 48 1 60
|
|
program PhysicsTiles {
|
|
property Position { x: int = 0, y: int = 0 }
|
|
property Body {
|
|
vx: fixed = 0.0, vy: fixed = 0.0,
|
|
gravity: fixed = 0.0, max_fall: fixed = 0.0,
|
|
rx: fixed = 0.0, ry: fixed = 0.0,
|
|
policy: int = 0,
|
|
on_ground: int = 0, hit_wall: int = 0, hit_ceiling: int = 0
|
|
}
|
|
property Collider { w: int = 0, h: int = 0, offx: int = 0, offy: int = 0, is_trigger: int = 0, one_way: int = 0, layer: int = 0, mask: int = 0 }
|
|
property Solids { tile: int = 0, wall: int = 0, oneway: int = 0 }
|
|
|
|
function clear_prop(name: pointer) -> void {
|
|
let p = World.prop_id(name)
|
|
if p < 0 { return }
|
|
var e = World.query_next(p, 0)
|
|
while e >= 0 { despawn e; e = World.query_next(p, 0) }
|
|
}
|
|
function clear() -> void { clear_prop("Body"); clear_prop("Collider") }
|
|
|
|
entry {
|
|
let pb = World.prop_id("Body")
|
|
let pp = World.prop_id("Position")
|
|
let f_x = World.field_id(pp, "x")
|
|
let f_y = World.field_id(pp, "y")
|
|
let f_vx = World.field_id(pb, "vx")
|
|
let f_grd = World.field_id(pb, "on_ground")
|
|
let f_hw = World.field_id(pb, "hit_wall")
|
|
|
|
# 16px tiles; the map is now a loaded Tiled map (issue #69). Its `collision`
|
|
# layer projects to the same byte tilemap: a non-zero GID becomes '#' (35,
|
|
# solid), and a GID whose tile carries the bool `oneway` property becomes
|
|
# '=' (61), a one-way platform — so esys_move sees the identical grid.
|
|
# one-way platform, cols 10-12 (y 64); wall column, col 6, rows 5-7;
|
|
# solid floor, row 8 (top edge y 128).
|
|
Tiled.load("assets/tiled-fixtures/physics_map.tmx")
|
|
spawn Config { Solids { tile: 16, wall: 35, oneway: 61 } }
|
|
|
|
# ---- T1. fall and land on the tile floor -------------------------------
|
|
clear()
|
|
spawn Runner { Position { x: 32, y: 16 }, Body { gravity: fixed(1), max_fall: fixed(6) }, Collider { w: 16, h: 16 } }
|
|
var a = World.query_next(pb, 0)
|
|
var i = 0
|
|
while i < 80 { tick_fixed(); i = i + 1 }
|
|
print(World.get(a, pp, f_y)) # 112 — feet rest on the tile floor top (128)
|
|
print(World.get(a, pb, f_grd)) # 1
|
|
|
|
# ---- T2. run into a tile wall column -----------------------------------
|
|
clear()
|
|
spawn Runner { Position { x: 16, y: 112 }, Body { gravity: fixed(1), max_fall: fixed(6) }, Collider { w: 16, h: 16 } }
|
|
a = World.query_next(pb, 0)
|
|
i = 0
|
|
while i < 60 { World.set(a, pb, f_vx, fixed(4)); tick_fixed(); i = i + 1 }
|
|
print(World.get(a, pp, f_x)) # 80 — right edge stops at the wall column (96)
|
|
print(World.get(a, pb, f_hw)) # 1
|
|
|
|
# ---- T3a. land on a one-way tile platform from above -------------------
|
|
clear()
|
|
spawn Runner { Position { x: 176, y: 16 }, Body { gravity: fixed(1), max_fall: fixed(6) }, Collider { w: 16, h: 16 } }
|
|
a = World.query_next(pb, 0)
|
|
i = 0
|
|
while i < 40 { tick_fixed(); i = i + 1 }
|
|
print(World.get(a, pp, f_y)) # 48 — feet on the one-way top (64)
|
|
print(World.get(a, pb, f_grd)) # 1
|
|
|
|
# ---- T3b. rise straight up through the one-way tile --------------------
|
|
clear()
|
|
spawn Riser { Position { x: 176, y: 120 }, Body { vy: fixed(0 - 4), policy: 1 }, Collider { w: 16, h: 16 } }
|
|
a = World.query_next(pb, 0)
|
|
i = 0
|
|
while i < 15 { tick_fixed(); i = i + 1 }
|
|
print(World.get(a, pp, f_y)) # 60 — passed through (120 - 4*15), above the platform
|
|
|
|
quit()
|
|
}
|
|
}
|