ludic/examples/library/input_edge.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

27 lines
1.1 KiB
Text

# input_edge.ludic — Input.key_pressed / key_released edge detection (#87). A
# handler game reads the press and release edges of a key in its Update phase; the
# frame loop commits the device layer itself (#83), so the game does NOT call
# Input.poll by hand, and the edges fire on exactly the transition frame. (The bug:
# a manual Input.poll under the loop used to double-commit and copy in_held into
# in_prev twice, so key_pressed/key_released never fired.)
#
# Driven headless by the keys on stdin, one char per frame. With "xkkxq":
# x frame0 — nothing
# k frame1 — pressed edge (down + just went down)
# k frame2 — held (down, no edge)
# x frame3 — released edge (was k, now not)
# q frame4 — nothing, then quit
#
# Run: printf 'xkkxq' | bin/ludic examples/library/input_edge.ludic -> 0 11 1 100 0
program InputEdge {
property Tag { n: int = 0 }
model P { Tag }
handler In phase Update {
var v = 0
if Input.key_down('k') { v += 1 } # held
if Input.key_pressed('k') { v += 10 } # went down this frame
if Input.key_released('k') { v += 100 } # went up this frame
print(v)
}
}