wip(0.S3): packages and examples migrated in one run - ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 15:02:45 +03:00
parent d490d4f9f1
commit 3eda72e8c2
172 changed files with 3094 additions and 2966 deletions

View file

@ -8,43 +8,43 @@
enum KnightAct { Attack, Guard, Item, Flee }
enum MageAct { Attack, Heal, Guard }
handler Battle phase Update {
if game_mode == 1 {
handler Battle(games_chronorift_st: mut GamesChronoriftState) phase Update {
if games_chronorift_st.game_mode == 1 {
let k = Input.key()
for (e) in query [Stats, {Enemy}] {
machine turn_phase {
machine games_chronorift_st.turn_phase {
state KnightMenu {
for (st, pt) in query [Stats, Party] {
if pt.slot == 0 {
if st.hp <= 0 {
become MageMenu
menu_cursor = 0
games_chronorift_st.menu_cursor = 0
} else {
if k == 'w' { menu_cursor = max(0, menu_cursor - 1) }
if k == 's' { menu_cursor = min(3, menu_cursor + 1) }
if k == 'w' { games_chronorift_st.menu_cursor = max(0, games_chronorift_st.menu_cursor - 1) }
if k == 's' { games_chronorift_st.menu_cursor = min(3, games_chronorift_st.menu_cursor + 1) }
if is_confirm(k) {
match menu_cursor {
match games_chronorift_st.menu_cursor {
KnightAct.Attack => {
let d = max(1, st.atk - e.def + Random.range(0, 4))
e.hp -= d
player_hit = d
games_chronorift_st.player_hit = d
}
KnightAct.Guard => { st.guard = 1; player_hit = 0 }
KnightAct.Guard => { st.guard = 1; games_chronorift_st.player_hit = 0 }
KnightAct.Item => {
if potions > 0 {
potions -= 1
if games_chronorift_st.potions > 0 {
games_chronorift_st.potions -= 1
st.hp = min(st.maxhp, st.hp + 24)
player_hit = 24
} else { player_hit = 0 }
games_chronorift_st.player_hit = 24
} else { games_chronorift_st.player_hit = 0 }
}
KnightAct.Flee => {
if Random.chance(50) { e.hp = 0; game_mode = 0 }
else { player_hit = 0 }
if Random.chance(50) { e.hp = 0; games_chronorift_st.game_mode = 0 }
else { games_chronorift_st.player_hit = 0 }
}
}
become KnightResolve
menu_cursor = 0
games_chronorift_st.menu_cursor = 0
}
}
}
@ -55,13 +55,13 @@ handler Battle phase Update {
if k != 0 {
if e.hp <= 0 {
grant_xp(e.xp)
gold += e.xp
if enemy_type == 2 { boss_down = 1; game_mode = 3; ack = 0 }
else { game_mode = 0 }
games_chronorift_st.gold += e.xp
if games_chronorift_st.enemy_type == 2 { games_chronorift_st.boss_down = 1; games_chronorift_st.game_mode = 3; games_chronorift_st.ack = 0 }
else { games_chronorift_st.game_mode = 0 }
become KnightMenu
} else {
become MageMenu
menu_cursor = 0
games_chronorift_st.menu_cursor = 0
}
}
}
@ -72,14 +72,14 @@ handler Battle phase Update {
if st.hp <= 0 {
become EnemyTurn
} else {
if k == 'i' { menu_cursor = max(0, menu_cursor - 1) }
if k == 'k' { menu_cursor = min(2, menu_cursor + 1) }
if k == 'i' { games_chronorift_st.menu_cursor = max(0, games_chronorift_st.menu_cursor - 1) }
if k == 'k' { games_chronorift_st.menu_cursor = min(2, games_chronorift_st.menu_cursor + 1) }
if k == 'j' {
match menu_cursor {
match games_chronorift_st.menu_cursor {
MageAct.Attack => {
let d = max(1, st.atk + 5 - e.def + Random.range(0, 5))
e.hp -= d
player_hit = d
games_chronorift_st.player_hit = d
}
MageAct.Heal => {
if st.mp >= 4 {
@ -87,13 +87,13 @@ handler Battle phase Update {
for (t2, p2) in query [Stats, Party] {
if p2.slot == 0 { t2.hp = min(t2.maxhp, t2.hp + 16) }
}
player_hit = 16
} else { player_hit = 0 }
games_chronorift_st.player_hit = 16
} else { games_chronorift_st.player_hit = 0 }
}
MageAct.Guard => { st.guard = 1; player_hit = 0 }
MageAct.Guard => { st.guard = 1; games_chronorift_st.player_hit = 0 }
}
become MageResolve
menu_cursor = 0
games_chronorift_st.menu_cursor = 0
}
}
}
@ -104,9 +104,9 @@ handler Battle phase Update {
if k != 0 {
if e.hp <= 0 {
grant_xp(e.xp)
gold += e.xp
if enemy_type == 2 { boss_down = 1; game_mode = 3; ack = 0 }
else { game_mode = 0 }
games_chronorift_st.gold += e.xp
if games_chronorift_st.enemy_type == 2 { games_chronorift_st.boss_down = 1; games_chronorift_st.game_mode = 3; games_chronorift_st.ack = 0 }
else { games_chronorift_st.game_mode = 0 }
become KnightMenu
} else {
become EnemyTurn
@ -123,7 +123,7 @@ handler Battle phase Update {
var ed = max(1, e.atk - t3.def + Random.range(0, 4))
if t3.guard == 1 { ed /= 2; t3.guard = 0 }
t3.hp -= ed
enemy_hit = ed
games_chronorift_st.enemy_hit = ed
done = 1
}
}
@ -132,10 +132,10 @@ handler Battle phase Update {
for (t4) in query [Stats, {Party}] {
if t4.hp > 0 { alive += 1 }
}
if alive == 0 { game_mode = 2; ack = 0 }
if alive == 0 { games_chronorift_st.game_mode = 2; games_chronorift_st.ack = 0 }
else {
become KnightMenu
menu_cursor = 0
games_chronorift_st.menu_cursor = 0
}
}
}
@ -144,29 +144,29 @@ handler Battle phase Update {
}
}
handler CleanBattle phase LateUpdate {
if game_mode != 1 {
handler CleanBattle(games_chronorift_st: GamesChronoriftState) phase LateUpdate {
if games_chronorift_st.game_mode != 1 {
for (e) in query [Stats, {Enemy}] {
despawn self()
}
}
}
handler Meta phase Update {
handler Meta(games_chronorift_st: mut GamesChronoriftState) phase Update {
let k = Input.key()
if game_mode == 2 {
if k == 0 { ack = 1 }
if games_chronorift_st.game_mode == 2 {
if k == 0 { games_chronorift_st.ack = 1 }
if k != 0 {
if ack == 1 {
if games_chronorift_st.ack == 1 {
for (h) in query [Stats, {Party}] { h.hp = h.maxhp }
game_mode = 0
games_chronorift_st.game_mode = 0
}
}
}
if game_mode == 3 {
if k == 0 { ack = 1 }
if games_chronorift_st.game_mode == 3 {
if k == 0 { games_chronorift_st.ack = 1 }
if k != 0 {
if ack == 1 { game_mode = 0 }
if games_chronorift_st.ack == 1 { games_chronorift_st.game_mode = 0 }
}
}
}

View file

@ -1,7 +1,7 @@
# draw.ludic — the Render system (overworld, battle, and overlay screens).
handler Draw phase Render {
let m = game_mode
handler Draw(games_chronorift_st: GamesChronoriftState) phase Render {
let m = games_chronorift_st.game_mode
Screen.clear(0x101018)
if m == 0 {
@ -31,7 +31,7 @@ handler Draw phase Render {
if c == 'D' { Screen.sprite(SPR_DOOR, sx, sy) }
if c == 'S' { Screen.sprite(SPR_DOOR, sx, sy) }
if c == 'B' {
if boss_down == 0 { Screen.sprite(SPR_BOSS, sx, sy) }
if games_chronorift_st.boss_down == 0 { Screen.sprite(SPR_BOSS, sx, sy) }
}
}
}
@ -47,9 +47,9 @@ handler Draw phase Render {
Screen.draw_text(8, 18, "HP", 0x88ff88, 1)
Screen.draw_number(24, 18, h.hp, 0xffffff, 1)
Screen.draw_text(8, 28, "G", 0xffd24a, 1)
Screen.draw_number(18, 28, gold, 0xffffff, 1)
Screen.draw_number(18, 28, games_chronorift_st.gold, 0xffffff, 1)
Screen.draw_text(54, 28, "PO", 0x88ffcc, 1)
Screen.draw_number(72, 28, potions, 0xffffff, 1)
Screen.draw_number(72, 28, games_chronorift_st.potions, 0xffffff, 1)
}
}
}
@ -58,13 +58,13 @@ handler Draw phase Render {
Screen.fill_rectangle(0, 0, 320, 176, 0x241a2e)
for (e, a) in query [Stats, Actor, {Enemy}] {
var bs = 5
if enemy_type == 2 { bs = 7 }
if games_chronorift_st.enemy_type == 2 { bs = 7 }
Screen.sprite_scaled(a.kind, 160 - bs * 8, 44, bs)
Screen.draw_text(100, 20, enemy_name(enemy_type), 0xffffff, 1)
Screen.draw_text(100, 20, enemy_name(games_chronorift_st.enemy_type), 0xffffff, 1)
Screen.fill_rectangle(100, 30, 120, 8, 0x401018)
Screen.fill_rectangle(100, 30, e.hp * 120 / e.maxhp, 8, 0xe04040)
}
let ph = turn_phase
let ph = games_chronorift_st.turn_phase
var act = 0
if ph >= 2 { act = 1 }
if ph >= 4 { act = 2 }
@ -83,14 +83,14 @@ handler Draw phase Render {
Screen.draw_text(hx + 36, 207, "MP", 0x88aaff, 1)
Screen.draw_number(hx + 56, 207, st.mp, 0xffffff, 1)
}
let cur = menu_cursor
let cur = games_chronorift_st.menu_cursor
if ph == 0 or ph == 1 {
Screen.draw_text(206, 181, "P1 KNIGHT", 0xffe08a, 1)
Screen.draw_text(214, 192, "ATTACK", 0xffffff, 1)
Screen.draw_text(214, 203, "DEFEND", 0xffffff, 1)
Screen.draw_text(214, 214, "ITEM", 0xffffff, 1)
Screen.draw_text(256, 214, "x", 0x777777, 1)
Screen.draw_number(264, 214, potions, 0xffd24a, 1)
Screen.draw_number(264, 214, games_chronorift_st.potions, 0xffd24a, 1)
Screen.draw_text(214, 225, "RUN", 0xffffff, 1)
if ph == 0 { Screen.draw_text(204, 192 + cur * 11, ">", 0xffff00, 1) }
}
@ -104,11 +104,11 @@ handler Draw phase Render {
if ph == 4 { Screen.draw_text(206, 200, "ENEMY TURN", 0xff8888, 1) }
if ph == 1 or ph == 3 {
Screen.draw_text(6, 232, "DMG", 0xffff88, 1)
Screen.draw_number(34, 232, player_hit, 0xffffff, 1)
Screen.draw_number(34, 232, games_chronorift_st.player_hit, 0xffffff, 1)
}
if ph == 4 {
Screen.draw_text(6, 232, "FOE HITS", 0xff8888, 1)
Screen.draw_number(66, 232, enemy_hit, 0xffffff, 1)
Screen.draw_number(66, 232, games_chronorift_st.enemy_hit, 0xffffff, 1)
}
}
@ -128,11 +128,11 @@ handler Draw phase Render {
Screen.draw_text(80, 104, "BUY POTION", 0xffffff, 1)
Screen.draw_text(180, 104, "10 G", 0xffd24a, 1)
Screen.draw_text(80, 122, "LEAVE", 0xffffff, 1)
Screen.draw_text(70, 104 + menu_cursor * 18, ">", 0xffff00, 1)
Screen.draw_text(70, 104 + games_chronorift_st.menu_cursor * 18, ">", 0xffff00, 1)
Screen.draw_text(80, 150, "GOLD", 0xffd24a, 1)
Screen.draw_number(120, 150, gold, 0xffffff, 1)
Screen.draw_number(120, 150, games_chronorift_st.gold, 0xffffff, 1)
Screen.draw_text(160, 150, "POTIONS", 0x88ffcc, 1)
Screen.draw_number(226, 150, potions, 0xffffff, 1)
Screen.draw_number(226, 150, games_chronorift_st.potions, 0xffffff, 1)
}
Screen.show()
}

View file

@ -1,6 +1,6 @@
# overworld.ludic — boot, movement/encounter input, and the shop system.
handler Boot phase Start {
handler Boot(games_chronorift_st: mut GamesChronoriftState) phase Start {
png_load("assets/kenney/tiny-town/Tiles/tile_0000.png") # 0 grass
png_load("assets/kenney/tiny-town/Tiles/tile_0004.png") # 1 tree
png_load("assets/kenney/tiny-town/Tiles/tile_0025.png") # 2 path
@ -25,16 +25,16 @@ handler Boot phase Start {
Party { slot: 1 }
Stats { hp: 26, maxhp: 26, mp: 16, maxmp: 16, atk: 8, def: 4, lvl: 1, xp: 0, guard: 0 }
}
game_mode = 0
encounter = 4
world_map = 0
boss_down = 0
gold = 20
potions = 2
games_chronorift_st.game_mode = 0
games_chronorift_st.encounter = 4
games_chronorift_st.world_map = 0
games_chronorift_st.boss_down = 0
games_chronorift_st.gold = 20
games_chronorift_st.potions = 2
}
handler Control phase Input {
if game_mode == 0 {
handler Control(games_chronorift_st: mut GamesChronoriftState) phase Input {
if games_chronorift_st.game_mode == 0 {
for (p) in query [Pos, {Player}] {
let k = Input.key()
var nx = p.x
@ -57,43 +57,43 @@ handler Control phase Input {
build_dungeon(0)
p.x = 3
p.y = 2
world_map = 1
games_chronorift_st.world_map = 1
}
if tc == 'S' {
build_field(0)
p.x = 36
p.y = 3
world_map = 0
games_chronorift_st.world_map = 0
}
if tc == 'B' {
if boss_down == 0 {
enemy_type = 2
if games_chronorift_st.boss_down == 0 {
games_chronorift_st.enemy_type = 2
spawn Enemy {
Actor { kind: 8 }
Stats { hp: 120, maxhp: 120, mp: 0, maxmp: 0, atk: 18, def: 10, lvl: 5, xp: 300, guard: 0 }
}
game_mode = 1
turn_phase = 0
menu_cursor = 0
games_chronorift_st.game_mode = 1
games_chronorift_st.turn_phase = 0
games_chronorift_st.menu_cursor = 0
}
}
if tc == 'h' {
game_mode = 4
menu_cursor = 0
games_chronorift_st.game_mode = 4
games_chronorift_st.menu_cursor = 0
}
if tc != 'D' {
if tc != 'S' {
if tc != 'B' {
if tc != 'h' {
encounter -= 1
if encounter <= 0 {
encounter = Random.range(4, 9)
games_chronorift_st.encounter -= 1
if games_chronorift_st.encounter <= 0 {
games_chronorift_st.encounter = Random.range(4, 9)
var et = 0
if world_map == 1 { et = 1 }
if world_map == 0 {
if games_chronorift_st.world_map == 1 { et = 1 }
if games_chronorift_st.world_map == 0 {
if Random.chance(40) { et = 1 }
}
enemy_type = et
games_chronorift_st.enemy_type = et
if et == 0 {
spawn Enemy {
Actor { kind: 6 }
@ -106,9 +106,9 @@ handler Control phase Input {
Stats { hp: 30, maxhp: 30, mp: 0, maxmp: 0, atk: 11, def: 5, lvl: 1, xp: 15, guard: 0 }
}
}
game_mode = 1
turn_phase = 0
menu_cursor = 0
games_chronorift_st.game_mode = 1
games_chronorift_st.turn_phase = 0
games_chronorift_st.menu_cursor = 0
}
}
}
@ -122,19 +122,19 @@ handler Control phase Input {
}
# shop (at the house 'h' tile): buy potions with gold
handler Shop phase Update {
if game_mode == 4 {
handler Shop(games_chronorift_st: mut GamesChronoriftState) phase Update {
if games_chronorift_st.game_mode == 4 {
let k = Input.key()
if k == 'w' { menu_cursor = max(0, menu_cursor - 1) }
if k == 's' { menu_cursor = min(1, menu_cursor + 1) }
if k == 'w' { games_chronorift_st.menu_cursor = max(0, games_chronorift_st.menu_cursor - 1) }
if k == 's' { games_chronorift_st.menu_cursor = min(1, games_chronorift_st.menu_cursor + 1) }
if is_confirm(k) {
if menu_cursor == 0 {
if gold >= 10 {
gold -= 10
potions += 1
if games_chronorift_st.menu_cursor == 0 {
if games_chronorift_st.gold >= 10 {
games_chronorift_st.gold -= 10
games_chronorift_st.potions += 1
}
}
if menu_cursor == 1 { game_mode = 0 }
if games_chronorift_st.menu_cursor == 1 { games_chronorift_st.game_mode = 0 }
}
}
}

View file

@ -29,15 +29,17 @@ const SPR_MAGE: int = 9
const SPR_FLOOR: int = 10
const SPR_WALL: int = 11
var game_mode: int = 0 # 0 field, 1 battle, 2 gameover, 3 victory
var turn_phase: int = 0
var menu_cursor: int = 0
var encounter: int = 0
var enemy_type: int = 0 # 0 slime, 1 skeleton, 2 boss
var player_hit: int = 0
var enemy_hit: int = 0
var gold: int = 0
var world_map: int = 0 # 0 overworld, 1 dungeon
var boss_down: int = 0 # boss defeated flag
var ack: int = 0 # debounce for end screens
var potions: int = 0 # potions in inventory
export state GamesChronoriftState {
game_mode: int = 0 # 0 field, 1 battle, 2 gameover, 3 victory
turn_phase: int = 0
menu_cursor: int = 0
encounter: int = 0
enemy_type: int = 0 # 0 slime, 1 skeleton, 2 boss
player_hit: int = 0
enemy_hit: int = 0
gold: int = 0
world_map: int = 0 # 0 overworld, 1 dungeon
boss_down: int = 0 # boss defeated flag
ack: int = 0 # debounce for end screens
potions: int = 0 # potions in inventory
}