ludic/examples/library/managers.ludic
Orkuncakilkaya 19fcf60599 wip(0.S3): packages and examples migrated again from their pre-0.S sources in one run
ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic
  1804 vars into 126 states, 64 into lets; 23498 edits in 460 files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 15:31:34 +03:00

44 lines
2.4 KiB
Text

# managers.ludic — the engine managers: the Map cell API, Sprite facing / run strip /
# flash / blink, IVec2 geometry, List.sample, Input.move_i, Fx, the audio bank,
# Camera.shake_for, timed Assets. Deterministic; prints:
# 35046 46 251 53 900 -1 20 324 0 10 102
program Managers {
import "ludic.core/components.ludic"
import "ludic.shooter/shooter.ludic"
property Tag { n: int = 0 }
model Thing { Position, Body, Sprite, Tag, TopDown }
model WorldRules { Solids }
state ManagersState {
frames: int = 0
}
handler Tick(managers_st: mut ManagersState) phase Update {
managers_st.frames += 1
if managers_st.frames == 1 {
Map.size(10, 8)
Map.fill(glyph: '.')
Map.border(glyph: '#')
Map.rect(x: 4, y: 3, width: 2, height: 2, glyph: '#')
spawn WorldRules { Solids { tile: 16, wall: '#' } }
print(Map.get(x: 0, y: 0) * 1000 + Map.get(x: 5, y: 5)) # 35046: '#', '.'
let cell = Map.random_cell(glyph: '.')
print(Map.get(x: cell.x, y: cell.y)) # 46
let a = IVec2.make(0, 0); let b = IVec2.make(3, 4)
print(IVec2.distance2(a, b) * 10 + IVec2.within(a, b, 5)) # 251
print(IVec2.heading(a, b)) # 53
let p = IVec2.along(a, 0, 10); print(p.x * 100 + p.y) # 900 (the sine table rounds down)
print(IVec2.step(180).x) # -1
print(Angle.diff_degrees(a: 350, b: 10)) # 20
let pool = new []int; push(pool, 7); push(pool, 8); push(pool, 9)
let picks = List.sample(pool, 3); print(len(picks) * 100 + picks[0] + picks[1] + picks[2]) # 324
let m = Input.move_i(); print(m.x + m.y) # 0
Audio.define(name: "hit", path: "nope.wav")
Audio.play(name: "hit")
Camera.shake_for(amount: 3, frames: 2)
Fx.sparks(x: 10, y: 10, color: 0xffffff, count: 4)
Fx.number(x: 20, y: 20, value: 42, color: 0xffff00)
spawn Thing { Position { x: 20, y: 20 }, Sprite { id: 5, move_id: 9, face: 1, flash: 3, blink: 6 }, TopDown { want_x: -1 } }
}
if managers_st.frames == 3 { print(Map.is_solid(x: 0, y: 0) * 10 + Map.is_solid_at(x: 40, y: 40)) } # 10
if managers_st.frames == 5 { for (s, t) in query [Sprite, Tag] { print(s.flip * 100 + s.flash * 10 + s.blink) }; quit() } # 102
}
}