From 92174baf7b7622d73a9d1673818ed10ae89a45bb Mon Sep 17 00:00:00 2001 From: fnicon Date: Mon, 23 Mar 2026 03:00:30 +0900 Subject: [PATCH] Add percentage_clear on racers --- .../src/new/world/race/components/racer.lua | 8 +++-- game/love_src/src/new/world/race/init.lua | 36 +++++++++++++++++-- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/game/love_src/src/new/world/race/components/racer.lua b/game/love_src/src/new/world/race/components/racer.lua index f71a115..d6aaa13 100644 --- a/game/love_src/src/new/world/race/components/racer.lua +++ b/game/love_src/src/new/world/race/components/racer.lua @@ -239,9 +239,11 @@ end function world:ui_draw() local lw, lh = love.graphics.getDimensions() - draw_time_attack(lw/2, 20, 1.0, 0.0, 1.0, self.time_attacks) - if (self.is_finish) then - draw_finish(lw/2, lh/2, 1.0, 1.0, 0.0) + if (self.show_pov) then + draw_time_attack(lw/2, 20, 1.0, 0.0, 1.0, self.time_attacks) + if (self.is_finish) then + draw_finish(lw/2, lh/2, 1.0, 1.0, 0.0) + end end -- debug_data(650, 0, 1.0, 0.0, 1.0, self.data) -- debug_data(650, 400, 1.0, 0.0, 1.0, magic_w) diff --git a/game/love_src/src/new/world/race/init.lua b/game/love_src/src/new/world/race/init.lua index 0b3d53e..c0ce217 100644 --- a/game/love_src/src/new/world/race/init.lua +++ b/game/love_src/src/new/world/race/init.lua @@ -108,7 +108,7 @@ end function world:setup() local map local countdown - local checkpoints + self.checkpoints = {} self.world_state = {} self.racers = {} self.pov_index = 1 @@ -130,7 +130,7 @@ function world:setup() elseif e.type == "countdown" then countdown = e elseif e.type == "checkpoints" then - checkpoints = e + self.checkpoints = e elseif e.type == "racer" then table.insert(self.racers, e) if (e.components.actor.name == "player") then @@ -143,7 +143,7 @@ function world:setup() e.components.racer.map = map.components.map e.components.racer.countdown = countdown.components.countdown e.components.racer.world_state = self.world_state.components.world_state - e.components.racer.checkpoints = checkpoints.components.checkpoints + e.components.racer.checkpoints = self.checkpoints.components.checkpoints elseif (e.type == "countdown") then e.components.countdown:load_world_state(self.world_state.components.world_state) end @@ -178,6 +178,34 @@ local phase = "intro" local x_is_down = false +local function percentage_clear(lap, max_lap, cp, max_cp) + return lap + cp * (1/max_cp) +end + +function world:update_race_rank(dt) + local rank = {} + for k, v in pairs(self.racers) do + local cp = v.components.racer.current_cp + local lap = v.components.racer.lap + local ts = v.components.racer.time_attacks + local finish = v.components.racer.is_finish + + local max_lap = self.checkpoints.components.checkpoints.data.max_lap + local max_cp = #self.checkpoints.components.checkpoints.data.check + + local percentage = percentage_clear(lap, max_lap, cp, max_cp) + v.components.racer.percentage = percentage + + if (finish) then + local t = 0 + for _, lt in pairs(ts) do + t = t + lt + end + local finish_time = t + end + end +end + function world:update(dt) for _, e in ipairs(self.entities) do for t, c in pairs(e.components) do @@ -199,6 +227,8 @@ function world:update(dt) elseif (not love.keyboard.isDown("x") and x_is_down == true) then x_is_down = false end + + self:update_race_rank(dt) end function world:draw()