- Image layers: <imagelayer> renders with parallax + optional repeatx/repeaty tiling across the view; the image loads relative to the map file. Group layers flatten at build (children render in file order); layer offset/opacity/tint are queryable (Tiled.layer_kind / layer_offsetx / layer_offsety / layer_opacity / layer_tint), a group's tint applying recursively. - Orientation transforms: Tiled.cell_x / Tiled.cell_y compute a tile cell's screen position for orthogonal, isometric ((x-y)*tw/2, (x+y)*th/2), staggered, and hexagonal (rows step by (tileh+hexsidelength)/2, alternate rows shoved per staggerindex) — the tile draw now places cells through them. - Wang: exported Wang-set GIDs are ordinary GIDs and resolve through the standard GID resolver; the terrain-corner authoring concept is editor-side (design cut). Proven by library/tiled_p5.ludic (14 assertions) over the real isometric_grass_and_water.tmx (iso + Wang) and hexagonal-mini.tmx, plus a hand-authored image+group fixture. x test: 96 passed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
58 lines
2.6 KiB
Text
58 lines
2.6 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) == 0 - 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 = cx + 1 }
|
|
cy = 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 = xx + 1 }
|
|
yy = yy + 1
|
|
}
|
|
if painted == 1 { print(14) }
|
|
}
|
|
|
|
handler Run phase Update { quit() }
|
|
}
|