# draw.ludic — the Render system (overworld, battle, and overlay screens). handler Draw(games_chronorift_st: GamesChronoriftState) phase Render { let m = games_chronorift_st.game_mode Screen.clear(0x101018) if m == 0 { var cx = 0 var cy = 0 for (p) in query [Pos, {Player}] { cx = clamp(p.x * 16 - 152, 0, MW * 16 - 320) cy = clamp(p.y * 16 - 112, 0, MH * 16 - 240) } let tx0 = cx / 16 let ty0 = cy / 16 for ty in ty0 .. ty0 + 16 { for tx in tx0 .. tx0 + 21 { let c = Map.tile(tx, ty) let sx = tx * 16 - cx let sy = ty * 16 - cy var base = SPR_GRASS match c { 'r' => base = SPR_PATH ',', 'S', 'B' => base = SPR_FLOOR '=' => base = SPR_WALL } Screen.sprite(base, sx, sy) if c == 'T' { Screen.sprite(SPR_TREE, sx, sy) } if c == '#' { Screen.sprite(SPR_TREE, sx, sy) } if c == 'H' { Screen.sprite(SPR_HOUSE, sx, sy) } if c == 'D' { Screen.sprite(SPR_DOOR, sx, sy) } if c == 'S' { Screen.sprite(SPR_DOOR, sx, sy) } if c == 'B' { if games_chronorift_st.boss_down == 0 { Screen.sprite(SPR_BOSS, sx, sy) } } } } for (p, a) in query [Pos, Actor] { Screen.sprite(a.kind, p.x * 16 - cx, p.y * 16 - cy) } for (h, pp) in query [Stats, Party] { if pp.slot == 0 { Screen.fill_rectangle(4, 4, 96, 38, 0x0c0c16) Screen.draw_rectangle(4, 4, 96, 38, 0x3a3a55) Screen.draw_text(8, 8, "LV", 0xffe08a, 1) Screen.draw_number(24, 8, h.lvl, 0xffffff, 1) 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, games_chronorift_st.gold, 0xffffff, 1) Screen.draw_text(54, 28, "PO", 0x88ffcc, 1) Screen.draw_number(72, 28, games_chronorift_st.potions, 0xffffff, 1) } } } if m == 1 { Screen.fill_rectangle(0, 0, 320, 176, 0x241a2e) for (e, a) in query [Stats, Actor, {Enemy}] { var bs = 5 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(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 = games_chronorift_st.turn_phase var act = 0 if ph >= 2 { act = 1 } if ph >= 4 { act = 2 } Screen.fill_rectangle(0, 176, 320, 64, 0x0c0c16) Screen.draw_rectangle(0, 176, 320, 64, 0x3a3a55) for (st, pt) in query [Stats, Party] { let hx = 6 + pt.slot * 92 var spr = 5 if pt.slot == 1 { spr = 9 } if pt.slot == act { Screen.draw_rectangle(hx - 2, 180, 88, 44, 0xffff00) } Screen.sprite_scaled(spr, hx, 184, 2) if pt.slot == 0 { Screen.draw_text(hx + 36, 182, "KNIGHT", 0xffe08a, 1) } if pt.slot == 1 { Screen.draw_text(hx + 36, 182, "MAGE", 0xc9a0ff, 1) } Screen.draw_text(hx + 36, 195, "HP", 0x88ff88, 1) Screen.draw_number(hx + 56, 195, st.hp, 0xffffff, 1) Screen.draw_text(hx + 36, 207, "MP", 0x88aaff, 1) Screen.draw_number(hx + 56, 207, st.mp, 0xffffff, 1) } 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, 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) } } if ph == 2 or ph == 3 { Screen.draw_text(206, 182, "P2 MAGE", 0xc9a0ff, 1) Screen.draw_text(214, 196, "ATTACK", 0xffffff, 1) Screen.draw_text(214, 208, "HEAL", 0xffffff, 1) Screen.draw_text(214, 220, "DEFEND", 0xffffff, 1) if ph == 2 { Screen.draw_text(204, 196 + cur * 12, ">", 0xffff00, 1) } } 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, games_chronorift_st.player_hit, 0xffffff, 1) } if ph == 4 { Screen.draw_text(6, 232, "FOE HITS", 0xff8888, 1) Screen.draw_number(66, 232, games_chronorift_st.enemy_hit, 0xffffff, 1) } } if m == 2 { Screen.draw_text(112, 104, "YOU FELL", 0xff5555, 2) Screen.draw_text(84, 140, "PRESS ANY KEY", 0xffffff, 1) } if m == 3 { Screen.draw_text(60, 96, "THE RIFT IS SEALED", 0x88ffcc, 2) Screen.draw_text(96, 132, "VICTORY!", 0xffe060, 3) Screen.draw_text(84, 170, "PRESS ANY KEY", 0xffffff, 1) } if m == 4 { Screen.fill_rectangle(60, 60, 200, 120, 0x141422) Screen.draw_rectangle(60, 60, 200, 120, 0x6a6a95) Screen.draw_text(96, 72, "ITEM SHOP", 0xffe060, 2) 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 + games_chronorift_st.menu_cursor * 18, ">", 0xffff00, 1) Screen.draw_text(80, 150, "GOLD", 0xffd24a, 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, games_chronorift_st.potions, 0xffffff, 1) } Screen.show() }