add min_speed

This commit is contained in:
fnicon 2026-03-22 09:24:00 +09:00
parent 11bfd4404e
commit 7899b1444c
4 changed files with 25 additions and 10 deletions

View File

@ -5,6 +5,7 @@ local components = {}
components.dict = {
velocity = "race.velocity",
max_speed = "race.max_speed",
min_speed = "race.min_speed",
accel = "race.accel",
grip = "race.grip",
steer = "race.steer",
@ -22,6 +23,10 @@ function components.max_speed (c, x)
c.data = x
end
function components.min_speed (c, x)
c.data = x
end
function components.accel (c, x)
c.data = x
end

View File

@ -32,13 +32,14 @@ function wrapper:load(_args)
assemblage = racer.assemble,
data = {
velocity = {0.0, 0.0},
max_speed = 10.0,
max_speed = 1.0,
min_speed = 0.0,
inertia = {0.0, 0.0},
accel = 0.0,
brake = 0.0,
accel = 0.1,
brake = 0.1,
grip = 0.0,
steer = 0.0,
steer = 0.1,
mass = 0.0,
streamline = 0.0
}

View File

@ -14,6 +14,7 @@ system.__index = system
system.pool = {
pool = {
race.dict.max_speed,
race.dict.min_speed,
race.dict.velocity,
race.dict.accel,
race.dict.brake,
@ -27,6 +28,7 @@ system.pool = {
system.components = {
[race.dict.max_speed] = race.max_speed,
[race.dict.min_speed] = race.min_speed,
[race.dict.velocity] = race.velocity,
[race.dict.accel] = race.accel,
@ -53,6 +55,7 @@ end
local function get(e)
return
e[race.dict.max_speed].data,
e[race.dict.min_speed].data,
e[race.dict.velocity].data,
e[race.dict.accel].data,
e[race.dict.brake].data,
@ -141,8 +144,8 @@ end
local magic_w = {
tire = 0.0,
floor = 0.0,
forward = 0.0,
steer = 0.0,
forward = 0.01,
steer = 0.1,
drag_boost = 0.0,
drag_halt = 0.0,
inertia = 0.0,
@ -179,6 +182,7 @@ local p_right = love.keyboard.isDown("l")
dict_debugs = {
race.dict.max_speed,
race.dict.min_speed,
race.dict.velocity,
race.dict.accel,
race.dict.brake,
@ -218,7 +222,7 @@ function system:update(dt)
e[dict_debug_current].data = e[dict_debug_current].data + 1
end
local max_speed, velocity, accel, brake, grip, steer, inertia, mass, streamline = get(e)
local max_speed, min_speed, velocity, accel, brake, grip, steer, inertia, mass, streamline = get(e)
local pos_x, pos_y = e["race.pos"].data[1], e["race.pos"].data[2]
@ -245,8 +249,10 @@ function system:update(dt)
local a = force * dt / mass
e[race.dict.velocity].data = e[race.dict.velocity].data + a
e[race.dict.velocity].data[1] = vm.clamp(e[race.dict.velocity].data[1], -max_speed, max_speed)
e["race.pos"].data = e["race.pos"].data + e[race.dict.velocity].data
e[race.dict.velocity].data[1] = vm.clamp(e[race.dict.velocity].data[1], min_speed, max_speed)
if (desire_forward ~= 0) then
e["race.pos"].data = e["race.pos"].data + e[race.dict.velocity].data
end
e[race.dict.inertia].data = force
end
@ -271,9 +277,10 @@ end
function system:ui_draw()
for _, e in ipairs(self.pool) do
local max_speed, velocity, accel, brake, grip, steer, inertia, mass, streamline = get(e)
local max_speed, min_speed, velocity, accel, brake, grip, steer, inertia, mass, streamline = get(e)
draw_debug(640, 0, 1.0, 0.0, 1.0, {
string.format("%s max_speed : %s", (debug_current == 1 and ">") or "", max_speed),
string.format("%s max_speed : %s", (debug_current == 21 and ">") or "", min_speed),
string.format("%s velocity : %s", (debug_current == 2 and ">") or "", velocity),
string.format("%s accel : %s", (debug_current == 3 and ">") or "", accel),
string.format("%s brake : %s", (debug_current == 4 and ">") or "", brake),

View File

@ -5,6 +5,7 @@ local template = {}
template.default_data = {
velocity = {0.0, 0.0},
max_speed = 10.0,
min_speed = 0.0,
accel = 10.0,
brake = 10.0,
@ -16,6 +17,7 @@ template.default_data = {
}
function template.assemble(e, data)
e:give(race.dict.max_speed, data.max_speed)
e:give(race.dict.min_speed, data.min_speed)
e:give(race.dict.velocity, data.velocity[1], data.velocity[2])
e:give(race.dict.accel, data.accel)