Merge pull request 'racing_stat_prototype' (#2) from racing_stat_prototype into main

Reviewed-on: #2
This commit is contained in:
fnicon 2026-03-13 15:04:13 +00:00
commit 09bee87258
7 changed files with 239 additions and 1 deletions

View File

@ -1,3 +1,40 @@
local mode = {
require("src.modes.racing"),
require("src.modes.raising_sim")
};
local actor = require("src.entities.shared.actor")
local player = actor.load("player")
local mode_i = 1
function love.load()
print("hello")
mode[mode_i].load(player)
end
function love.update(dt)
mode[mode_i].update(dt)
end
function love.draw()
mode[mode_i].draw()
end
function love.keyreleased(key, scancode)
if (key == "right") then
mode_i = mode_i + 1
if (mode_i > 2) then
mode_i = 1
end
mode[mode_i].load(player)
end
mode[mode_i].keyreleased(key, scancode)
end
function love.keypressed(key, scancode, isrepeat)
mode[mode_i].keypressed(key, scancode, isrepeat)
end
function love.mousereleased(x, y, button, istouch, presses)
mode[mode_i].mousereleased(x, y, button, istouch, presses)
end

View File

@ -0,0 +1,49 @@
local entity = {}
entity.__index = entity
function entity.load(actor, finish)
local self = setmetatable({}, entity)
self.data = {
pos = {0, 100, 0},
color = {255/255, 255/255, 255/255},
actor = actor,
current_speed = 0.0,
current_accel = 0.0,
finish = finish
}
return self
end
function entity:update(dt)
if (self.data.pos[1] > self.data.finish[1]) then
self.data.pos[1] = 0
self.data.current_speed = 0
self.data.current_accel = 0
end
self:accel(dt)
self.data.pos[1] = self.data.pos[1] + self.data.current_speed * dt
end
function entity:accel(dt)
if (self.data.current_accel <= self.data.actor.data.accel) then
self.data.current_accel = self.data.current_accel + dt
end
if (self.data.current_speed <= self.data.actor.data.max_speed) then
self.data.current_speed = self.data.current_speed + self.data.current_accel * dt
end
end
function entity:draw()
love.graphics.push()
love.graphics.setColor(self.data.color[1], self.data.color[2], self.data.color[3])
love.graphics.points(self.data.pos[1], self.data.pos[2])
love.graphics.print(self.data.current_speed, self.data.pos[1], self.data.pos[2])
love.graphics.print(string.format("Current Accel : %s", self.data.current_accel), 0, 40)
love.graphics.pop()
self.data.actor:draw()
end
return entity

View File

@ -0,0 +1,41 @@
local entity = {}
entity.__index = entity
function entity.load(actor)
local self = setmetatable({}, entity)
self.data = {
actor = actor,
increase_max_speed = 1,
increase_accel = 1
}
return self
end
function entity:update(dt)
end
function entity:draw()
love.graphics.push()
love.graphics.print(string.format("[(a)-Max Speed+(d)] : %s", self.data.increase_max_speed), 0, 40)
love.graphics.print(string.format("[(q)-Accel+(e)] : %s", self.data.increase_accel), 0, 60)
love.graphics.pop()
self.data.actor:draw()
end
function entity:keyreleased(key, scancode)
if (key == "a") then
self.data.actor.data.max_speed = self.data.actor.data.max_speed - self.data.increase_max_speed
elseif (key == "d") then
self.data.actor.data.max_speed = self.data.actor.data.max_speed + self.data.increase_max_speed
elseif (key == "q") then
self.data.actor.data.accel = self.data.actor.data.accel - self.data.increase_accel
elseif (key == "e") then
self.data.actor.data.accel = self.data.actor.data.accel + self.data.increase_accel
end
end
return entity

View File

@ -0,0 +1,26 @@
local entity = {}
entity.__index = entity
function entity.load(name)
local self = setmetatable({}, entity)
self.data = {
max_speed = 100.0,
accel = 2.0,
}
return self
end
function entity:update(dt)
end
function entity:draw()
love.graphics.push()
love.graphics.print(string.format("Max Speed : %s", self.data.max_speed), 0, 0)
love.graphics.print(string.format("Accel : %s", self.data.accel), 0, 20)
love.graphics.pop()
end
return entity

24
game/src/modes/mode.lua Normal file
View File

@ -0,0 +1,24 @@
local mode = {}
function mode.load(player)
end
function mode.update(dt)
end
function mode.draw()
end
function mode.keyreleased(key, scancode)
end
function mode.keypressed(key, scancode, isrepeat)
end
function mode.mousereleased(x, y, button, istouch, presses)
end
return mode

30
game/src/modes/racing.lua Normal file
View File

@ -0,0 +1,30 @@
local racer = require("src.entities.racing.racer")
local mode = {}
local finish = {100, 100, 0}
local entities = {}
function mode.load(player)
entities.racer = racer.load(player, finish)
end
function mode.update(dt)
entities.racer:update(dt)
end
function mode.draw()
entities.racer:draw()
end
function mode.keyreleased(key, scancode)
end
function mode.keypressed(key, scancode, isrepeat)
end
function mode.mousereleased(x, y, button, istouch, presses)
end
return mode

View File

@ -0,0 +1,31 @@
local trainee = require("src.entities.raising.trainee")
local mode = {}
local entities = {}
function mode.load(player)
entities.trainee = trainee.load(player)
end
function mode.update(dt)
entities.trainee:update(dt)
end
function mode.draw()
entities.trainee:draw()
end
function mode.keyreleased(key, scancode)
entities.trainee:keyreleased(key, scancode)
end
function mode.keypressed(key, scancode, isrepeat)
end
function mode.mousereleased(x, y, button, istouch, presses)
end
return mode