ludic/examples/library/tiled_p5.ludic
Orkuncakilkaya bf36bc8a8f refactor(runtime,packages,examples): named constants, package enums, idiom sweep
- runtime: HEADLESS_FRAME_PATH, STICK_DEADZONE / STICK_LEFT_X/Y, key and
  byte codes as char literals throughout (`k == 'w'`, `fill(rt_map, ' ', …)`)
- ludic.gameplay/stats: drop the duplicate `stat_field` (it answered "atk"
  for every build stat); Stats.base uses stats_field_name
- ludic.shooter: compare aim modes and fire patterns with AimMode.* and
  WeaponPattern.* instead of raw ints; STICK_RIGHT_X/Y
- ludic.npcai: DecisionMade / brain_set_state use AiState.*
- examples/games/menu.ludic uses Font.load / Ui.* with FONT_PATH and
  BACKDROP named; strings.ludic header says what it prints
- whole tree: `x = x + 1` → `x += 1` (single-term right-hand sides only),
  `0 - x` → `-x`, ASCII codes → char literals; every .ludic and every
  ```ludic fence reformatted with the fixed formatter (whitespace only)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-05 01:12:26 +03:00

58 lines
2.5 KiB
Text

# tiled_p5.ludic — Tiled P5 breadth (issue #73): image & group layers, the
# isometric / staggered / hexagonal orientation coordinate transforms, and Wang
# GID resolution (exported Wang GIDs are ordinary GIDs — the resolver handles
# them; the terrain-corner authoring concept is editor-side and ignored).
#
# A full run prints: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
program TiledP5 {
property Tag { v: int = 0 }
model Marker { Tag }
handler Boot phase Start {
# --- isometric coordinate transform (tilewidth 64, tileheight 32) ---
let iso = Tiled.load("assets/tiled-fixtures/isometric_grass_and_water.tmx")
if Value.as_str(Value.get(Tiled.tree(iso), "orientation")) == "isometric" { print(1) }
if Tiled.cell_x(iso, 1, 0) == 32 { print(2) } # (1-0)*64/2
if Tiled.cell_x(iso, 0, 1) == -32 { print(3) } # (0-1)*64/2
if Tiled.cell_y(iso, 1, 1) == 32 { print(4) } # (1+1)*32/2
if Tiled.cell_y(iso, 2, 0) == 32 { print(5) } # (2+0)*32/2
# --- Wang GIDs resolve to the right tiles ---
# scan the first tile layer for a non-zero GID and resolve it
var g = 0
var cy = 0
while cy < Tiled.height(iso) and g == 0 {
var cx = 0
while cx < Tiled.width(iso) and g == 0 { g = Tiled.gid(iso, 0, cx, cy); cx += 1 }
cy += 1
}
let r = Tiled.resolve(iso, g)
if r.tileset == 0 and r.local >= 0 { print(6) }
# --- hexagonal transform (tw 14, th 12, hexside 6, staggeraxis y, index odd) ---
let hex = Tiled.load("assets/tiled-fixtures/hexagonal-mini.tmx")
if Value.as_str(Value.get(Tiled.tree(hex), "orientation")) == "hexagonal" { print(7) }
if Tiled.cell_y(hex, 0, 2) == 18 { print(8) } # 2 * (12+6)/2
if Tiled.cell_x(hex, 0, 1) == 7 { print(9) } # odd row shifted by 14/2
if Tiled.cell_x(hex, 1, 0) == 14 { print(10) } # even row, no shift
# --- image & group layers ---
let m = Tiled.load("assets/tiled-fixtures/img_group.tmx")
if Tiled.layer_kind(m, 0) == 2 { print(11) } # imagelayer
if Tiled.layer_kind(m, 1) == 3 { print(12) } # group
if Tiled.layer_offsetx(m, 1) == 16 and Tiled.layer_tint(m, 1) == "#ff0000" { print(13) }
# render: the image layer paints the atlas across the view -> pixels drawn
rt_clear(0)
Tiled.draw(m, 0, 0)
var painted = 0
var yy = 0
while yy < 32 and painted == 0 {
var xx = 0
while xx < 32 and painted == 0 { if rt_get_px(xx, yy) != 0 { painted = 1 }; xx += 1 }
yy += 1
}
if painted == 1 { print(14) }
}
handler Run phase Update { quit() }
}