ludic/examples/chronorift/rules.ludic
Orkuncakilkaya a3a1e4d160 Language: named colors, namespaced Screen/Input/Random/Map API, named args
An opinionated, game-facing surface for the language:
- Color.<Name>: 221 named colors resolved to 0xRRGGBB at compile time
  (selfhost/emit_color.ludic).
- Namespaced builtins Screen.* / Input.key / Random.* / Map.*, so calls read as
  subject.action; present() -> Screen.show(), clear -> Screen.clear,
  fill_rect -> Screen.fill_rectangle, etc.
- Named arguments, e.g. Screen.fill_rectangle(x:, y:, width:, height:, color:),
  reordered to the callee's parameters at emit time.
- machine/become can run over a named program-scope var, not just a register.
- Migrate examples off numeric registers to named vars; snake/menu/chronorift
  render byte-identical to the goldens and the bootstrap fixpoint is preserved.
- Regenerate the checked-in seed (selfhost/ludicc.seed.ll).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-29 16:05:55 +03:00

86 lines
3.2 KiB
Text

# rules.ludic — pure game rules & map data (functions only, no systems).
fn tile_sprite(c: int) -> int {
match c {
'T', '#' => return SPR_TREE
'H' => return SPR_HOUSE
'D' => return SPR_DOOR
'r', 'h' => return SPR_PATH
',', 'S', 'B' => return SPR_FLOOR
'=' => return SPR_WALL
}
return SPR_GRASS
}
fn walkable(x: int, y: int) -> bool {
let c = Map.tile(x, y)
return c == '.' or c == 'D' or c == 'r' or c == ',' or c == 'S' or c == 'B' or c == 'h'
}
fn is_confirm(k: int) -> bool { return k == 32 or k == 10 or k == 13 }
fn enemy_name(et: int) -> str {
if et == 0 { return "SLIME" }
if et == 1 { return "SKELETON" }
return "RIFT WARDEN"
}
fn build_field(x: int) -> int {
Map.size(40, 18)
Map.row(0, "########################################")
Map.row(1, "#......................................#")
Map.row(2, "#...TT.........................TT.....D#")
Map.row(3, "#..TT.......................TT.........#")
Map.row(4, "#..T.........................T.........#")
Map.row(5, "#....................................T.#")
Map.row(6, "#.....TT....................TT.......T.#")
Map.row(7, "#....TT.....................T..........#")
Map.row(8, "#...........rrrrrrrr........HH.........#")
Map.row(9, "#..........r........r.......HH.........#")
Map.row(10, "#......TT...r........rrrrrrrrhr......T.#")
Map.row(11, "#.....TT...r.................r.......T.#")
Map.row(12, "#..........r.......TT.......r..........#")
Map.row(13, "#..........rrrrrrrrrrrrrrrrr.........T.#")
Map.row(14, "#.........TT.........................T.#")
Map.row(15, "#........TT..........................T.#")
Map.row(16, "#....................................T.#")
Map.row(17, "########################################")
return 0
}
fn build_dungeon(x: int) -> int {
Map.size(40, 18)
Map.row(0, "========================================")
Map.row(1, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(2, "=,S,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(3, "=,,,,,====,,,,,,,,,,,,,,,====,,,,,,,,,,=")
Map.row(4, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(5, "=,,,,,,,,,,,,,====,,,,,,,,,,,,,,,,,,,,,=")
Map.row(6, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,====,,,,,=")
Map.row(7, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(8, "=,,,====,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(9, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(10, "=,,,,,,,,,,,,,,,,,,====,,,,,,,,,,,,,,,,=")
Map.row(11, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(12, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,====,,,,,,,=")
Map.row(13, "=,,,,,,,,,====,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(14, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(15, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,B,,=")
Map.row(16, "=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=")
Map.row(17, "========================================")
return 0
}
fn grant_xp(amount: int) -> int {
for (t) in query [Stats, {Party}] {
if t.hp > 0 {
t.xp = t.xp + amount
while t.xp >= t.lvl * 20 {
t.xp = t.xp - t.lvl * 20
t.lvl = t.lvl + 1
t.maxhp = t.maxhp + 8
t.hp = t.maxhp
t.maxmp = t.maxmp + 2
t.atk = t.atk + 2
t.def = t.def + 1
}
}
}
return 0
}