# overworld.ludic — boot, movement/encounter input, and the shop system. 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 png_load("assets/kenney/tiny-town/Tiles/tile_0073.png") # 3 house png_load("assets/kenney/tiny-town/Tiles/tile_0112.png") # 4 arch png_load("assets/kenney/tiny-dungeon/Tiles/tile_0096.png") # 5 hero png_load("assets/kenney/tiny-dungeon/Tiles/tile_0108.png") # 6 slime png_load("assets/kenney/tiny-dungeon/Tiles/tile_0120.png") # 7 skeleton png_load("assets/kenney/tiny-dungeon/Tiles/tile_0110.png") # 8 boss png_load("assets/kenney/tiny-dungeon/Tiles/tile_0084.png") # 9 mage png_load("assets/kenney/tiny-dungeon/Tiles/tile_0048.png") # 10 floor png_load("assets/kenney/tiny-dungeon/Tiles/tile_0026.png") # 11 wall build_field(0) spawn Player { Pos { x: 11, y: 15 } Actor { kind: 5 } Party { slot: 0 } Stats { hp: 40, maxhp: 40, mp: 8, maxmp: 8, atk: 12, def: 6, lvl: 1, xp: 0, guard: 0 } } spawn Ally { Party { slot: 1 } Stats { hp: 26, maxhp: 26, mp: 16, maxmp: 16, atk: 8, def: 4, lvl: 1, xp: 0, guard: 0 } } 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(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 var ny = p.y if k == 'w' { ny = p.y - 1 } if k == 's' { ny = p.y + 1 } if k == 'a' { nx = p.x - 1 } if k == 'd' { nx = p.x + 1 } var moved = 0 if walkable(nx, ny) { if nx != p.x or ny != p.y { p.x = nx p.y = ny moved = 1 } } if moved == 1 { let tc = Map.tile(p.x, p.y) if tc == 'D' { build_dungeon(0) p.x = 3 p.y = 2 games_chronorift_st.world_map = 1 } if tc == 'S' { build_field(0) p.x = 36 p.y = 3 games_chronorift_st.world_map = 0 } if tc == 'B' { 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 } } games_chronorift_st.game_mode = 1 games_chronorift_st.turn_phase = 0 games_chronorift_st.menu_cursor = 0 } } if tc == 'h' { games_chronorift_st.game_mode = 4 games_chronorift_st.menu_cursor = 0 } if tc != 'D' { if tc != 'S' { if tc != 'B' { if tc != 'h' { games_chronorift_st.encounter -= 1 if games_chronorift_st.encounter <= 0 { games_chronorift_st.encounter = Random.range(4, 9) var et = 0 if games_chronorift_st.world_map == 1 { et = 1 } if games_chronorift_st.world_map == 0 { if Random.chance(40) { et = 1 } } games_chronorift_st.enemy_type = et if et == 0 { spawn Enemy { Actor { kind: 6 } Stats { hp: 18, maxhp: 18, mp: 0, maxmp: 0, atk: 8, def: 2, lvl: 1, xp: 7, guard: 0 } } } if et == 1 { spawn Enemy { Actor { kind: 7 } Stats { hp: 30, maxhp: 30, mp: 0, maxmp: 0, atk: 11, def: 5, lvl: 1, xp: 15, guard: 0 } } } games_chronorift_st.game_mode = 1 games_chronorift_st.turn_phase = 0 games_chronorift_st.menu_cursor = 0 } } } } } } if k == 'k' { save() } if k == 'l' { if load() { } } } } } # shop (at the house 'h' tile): buy potions with gold handler Shop(games_chronorift_st: mut GamesChronoriftState) phase Update { if games_chronorift_st.game_mode == 4 { let k = Input.key() 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 games_chronorift_st.menu_cursor == 0 { if games_chronorift_st.gold >= 10 { games_chronorift_st.gold -= 10 games_chronorift_st.potions += 1 } } if games_chronorift_st.menu_cursor == 1 { games_chronorift_st.game_mode = 0 } } } }