From c84cf41222d768d04f0a54f714f51f7606e1bd78 Mon Sep 17 00:00:00 2001 From: fnicon Date: Mon, 23 Mar 2026 02:02:44 +0900 Subject: [PATCH] add finish --- .../src/new/world/race/components/racer.lua | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 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 4dd62e9..051c864 100644 --- a/game/love_src/src/new/world/race/components/racer.lua +++ b/game/love_src/src/new/world/race/components/racer.lua @@ -60,8 +60,11 @@ function world:load(entity, data) self.time_attacks = {} self.lap = 1 self.current_cp = 1 + self.prev_cp = 0 self.checkpoints = {} + + self.is_finish = false end function get(s) @@ -116,9 +119,16 @@ function world:update_checkpoint(dt) local cp = self.checkpoints.data.check[self.current_cp] local is_inside_cp = uib.is_inside(cp.pos[1], cp.pos[2], cp.wh[1], cp.wh[2], self.data.pos[1], self.data.pos[2]) if (is_inside_cp) then + self.prev_cp = self.current_cp self.current_cp = get_loop(self.current_cp + 1, #self.checkpoints.data.check) + if (self.current_cp < self.prev_cp) then + self.lap = self.lap + 1 + end + + if (self.lap > self.checkpoints.data.max_lap) then + self.is_finish = true + end end - print(self.current_cp) end function world:update_race(dt) @@ -151,7 +161,7 @@ function world:update_race(dt) if (self.world_state.data.state == "count down") then - else + elseif (not self.is_finish) then if (self.late_timer < 1 and not self.initial_boost and f_v > 0) then f_v = f_v + 0.1 self.initial_boost = true @@ -168,12 +178,12 @@ function world:update_race(dt) end function world:update_time_attack(dt) - if (self.time_attacks[self.lap] == nil) then + if (self.time_attacks[self.lap] == nil and not self.is_finish) then self.time_attacks[self.lap] = 0 end if (self.world_state.data.state == "count down") then - else + elseif (not self.is_finish) then self.time_attacks[self.lap] = self.time_attacks[self.lap] + dt end end @@ -200,6 +210,12 @@ local function draw_time_attack(x, y, r, g, b, to_debug) end end +local function draw_finish(x, y, r, g, b) + local font_ix = test.draw_font_start() + test.draw_font_set_base_color(r, g, b) + y = y + test.draw_font(font_ix, "FINISH", x, y) +end + local function debug_data(x, y, r, g, b, to_debug) local font_ix = test.draw_font_start() test.draw_font_set_base_color(r, g, b) @@ -220,6 +236,9 @@ 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) + 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)