add initial boost

This commit is contained in:
fnicon 2026-03-23 00:48:21 +09:00
parent 5c2aa31153
commit 6a300c5b8f
3 changed files with 35 additions and 15 deletions

View File

@ -22,7 +22,7 @@ end
function world:load_world_state(world_state) function world:load_world_state(world_state)
self.e.components.animation.data.triggers_fn[4] = function () self.e.components.animation.data.triggers_fn[4] = function ()
if (not self.disappear) then if (not self.disappear) then
world_state.components.world_state.data.state = "START" world_state.data.state = "start"
self.e.components.animation.data.anim_direction = 0 self.e.components.animation.data.anim_direction = 0
self.disappear = 2 self.disappear = 2
end end
@ -48,7 +48,8 @@ function world:ui_draw()
self.data.label_color self.data.label_color
) )
else else
uir.draw_text("", self.data.label = ""
uir.draw_text(self.data.label,
self.data.pos[1], self.data.pos[2], self.data.pos[1], self.data.pos[2],
self.data.label_color self.data.label_color
) )

View File

@ -49,6 +49,11 @@ function world:load(entity, data)
self.e = entity self.e = entity
self.data = data or default self.data = data or default
self.map = {} self.map = {}
self.countdown = {}
self.world_state = {}
self.late_timer = 0
end end
function get(s) function get(s)
@ -108,6 +113,11 @@ function world:update_race(dt)
local desire_forward, desire_steer = self.e.components.actor.data.forward, self.e.components.actor.data.steer local desire_forward, desire_steer = self.e.components.actor.data.forward, self.e.components.actor.data.steer
if (self.world_state.data.state == "start" and self.countdown.data.label == "go") then
self.late_timer = self.late_timer + dt
self.initial_boost = false
end
local force = racing_force( local force = racing_force(
desire_forward, desire_steer, desire_forward, desire_steer,
grip, friction, grip, friction,
@ -122,6 +132,13 @@ function world:update_race(dt)
local f_v = forward_velocity(dt, force, mass, velocity, max_speed, min_speed, magic_w.dampening) local f_v = forward_velocity(dt, force, mass, velocity, max_speed, min_speed, magic_w.dampening)
local o, o_v = orientation_velocity(dt, force, mass, self.data.orientation_speed, self.data.orientation, self.data.max_orientation_speed, self.data.min_orientation_speed) local o, o_v = orientation_velocity(dt, force, mass, self.data.orientation_speed, self.data.orientation, self.data.max_orientation_speed, self.data.min_orientation_speed)
if (self.world_state.data.state == "count down") then
else
if (self.late_timer < 1 and not self.initial_boost) then
f_v = f_v + 0.1
self.initial_boost = true
end
self.data.velocity[1] = f_v self.data.velocity[1] = f_v
-- self.data.orientation_speed = o_v -- self.data.orientation_speed = o_v
self.data.orientation = o self.data.orientation = o
@ -131,6 +148,7 @@ function world:update_race(dt)
self.data.inertia = force self.data.inertia = force
end end
end
function world:update(dt) function world:update(dt)
self:update_race(dt) self:update_race(dt)

View File

@ -106,6 +106,7 @@ end
function world:setup() function world:setup()
local map local map
local countdown
self.world_state = {} self.world_state = {}
for _, d in pairs(self.entities_data) do for _, d in pairs(self.entities_data) do
local e = { local e = {
@ -122,17 +123,17 @@ function world:setup()
map = e map = e
elseif e.type == "world_state" then elseif e.type == "world_state" then
self.world_state = e self.world_state = e
elseif e.type == "countdown" then
countdown = e
end end
end end
for _, e in ipairs(self.entities) do for _, e in ipairs(self.entities) do
if (e.type == "racer") then if (e.type == "racer") then
for t, c in pairs(e.components) do e.components.racer.map = map.components.map
if (c.name == "racer") then e.components.racer.countdown = countdown.components.countdown
c.map = map.components.map e.components.racer.world_state = self.world_state.components.world_state
end
end
elseif (e.type == "countdown") then elseif (e.type == "countdown") then
e.components.countdown:load_world_state(self.world_state) e.components.countdown:load_world_state(self.world_state.components.world_state)
end end
end end
end end