require("game/gauge") AIBattleOverlay = {} AIBattleOverlay.__index = AIBattleOverlay local DIR = "ai_battle/" local TILES = 19 local TILE_WIDTH = 72 local SECTIONS = 5 local GAUGE_SCALE = 0.5 local GAUGE_X, GAUGE_Y = 10, 15 local PROGRESS = { x = 177, y = 160, w = 148, h = 20 } -- A triangle wave between 0 and 1. local function flash(ms, period) return 1 - math.abs(2 * ((ms % period) / period) - 1) end function AIBattleOverlay.new() local self = setmetatable({}, AIBattleOverlay) self.ids = {} self.wins = {} return self end function AIBattleOverlay:id(key) self.ids[key] = self.ids[key] or tex.get_texture(key) return self.ids[key] end function AIBattleOverlay:reset() self.wins = {} end function AIBattleOverlay:set_section_result(section, won) self.wins[section] = won end function AIBattleOverlay:draw_back(ms, territory) local red = math.min(math.max(1, territory + 10), TILES - 1) local blue = TILES - red local highlight = flash(ms, 332) local scroll = (ms % 8500) / 8500 * 1152 tex.draw_texture(self:id(DIR .. "bg_lower")) for i = 0, red - 1 do tex.draw_texture(self:id(DIR .. "red_tile_lower"), { frame = i, x = i * TILE_WIDTH }) end for i = 0, blue - 1 do tex.draw_texture(self:id(DIR .. "blue_tile_lower"), { frame = i, x = (TILES - 1 - i) * TILE_WIDTH }) end tex.draw_texture(self:id(DIR .. "lower_triangles_1"), { y = scroll, fade = 0.5 }) tex.draw_texture(self:id(DIR .. "lower_triangles_2"), { y = scroll, fade = 0.5 }) tex.draw_texture(self:id(DIR .. "highlight_tile_lower"), { x = red * TILE_WIDTH, fade = highlight }) tex.draw_texture(self:id(DIR .. "bg_upper")) for i = 0, red - 1 do tex.draw_texture(self:id(DIR .. "red_tile_upper"), { frame = i, index = i }) end for i = 0, blue - 1 do tex.draw_texture(self:id(DIR .. "blue_tile_upper"), { frame = i, index = TILES - 1 - i }) end tex.draw_texture(self:id(DIR .. "bg_outline_upper")) local params = { frame = red - 1, index = red - 1, fade = highlight } if red > 9 then params.frame = TILES - red params.mirror = "horizontal" end tex.draw_texture(self:id(DIR .. "highlight_tile_upper"), params) end function AIBattleOverlay:draw_front(ms, section, section_count, progress) local scale = tex.get_screen_scale() local r, g, b, a = 0, 228, 48, 255 if progress >= 0.75 then r, g, b, a = 253, 249, 0, 255 * flash(ms, 266) end tex.draw_rect(PROGRESS.x * scale, PROGRESS.y * scale, PROGRESS.w * scale, PROGRESS.h * scale, 130, 130, 130, 255) tex.draw_rect(PROGRESS.x * scale, PROGRESS.y * scale, progress * PROGRESS.w * scale, PROGRESS.h * scale, r, g, b, a) tex.draw_texture(self:id(DIR .. "progress_bar")) if section < section_count then tex.draw_texture(self:id(DIR .. "section_text"), { index = 0, frame = section }) end if section < section_count - 1 then tex.draw_texture(self:id(DIR .. "section_text"), { index = 1, frame = section + 1 }) end tex.draw_texture(self:id(DIR .. "sections")) if section < section_count then tex.draw_texture(self:id(DIR .. "section_highlight_green"), { index = section }) tex.draw_texture(self:id(DIR .. "section_highlight_white"), { index = section, fade = flash(ms, 700) }) end for i = 0, SECTIONS - 1 do if self.wins[i] ~= nil then tex.draw_texture(self:id(DIR .. (self.wins[i] and "section_win" or "section_lose")), { index = i }) end end end function AIBattleOverlay:draw_scoreboard(is_ai, good, ok, bad, drumroll) tex.draw_texture(self:id(DIR .. (is_ai and "scoreboard_ai" or "scoreboard"))) local digit = self:id(DIR .. "scoreboard_num") local margin = 8 for row, counter in ipairs({ good, ok, bad, drumroll }) do local digits = tostring(counter) local width = #digits * margin for i = 1, #digits do tex.draw_texture(digit, { frame = tonumber(digits:sub(i, i)), x = -(width // 2) + (i - 1) * margin, index = (row - 1) + (is_ai and 4 or 0), }) end end end AIGauge = setmetatable({}, { __index = Gauge }) AIGauge.__index = AIGauge function AIGauge.new(is_2p, dan, string_diff) local opts = { folder = "gauge_ai", scale = GAUGE_SCALE, footer = true, no_border = true } return setmetatable(Gauge.new(is_2p, dan, string_diff, opts), AIGauge) end function AIGauge:blit(t, mirror, x, y, ...) return Gauge.blit(self, t, mirror, (x or 0) + GAUGE_X / GAUGE_SCALE, y + GAUGE_Y, ...) end function AIGauge:draw(_, ...) return Gauge.draw(self, 0, ...) end