Compare commits

..

2 Commits

Author SHA1 Message Date
a4576b4233 add accel and max speed 2026-03-13 22:10:51 +09:00
dbdf338f3e add simple start - finish movement 2026-03-13 21:55:43 +09:00
2 changed files with 74 additions and 1 deletions

View File

@ -1,3 +1,13 @@
local racing = require("src.modes.racing")
function love.load() function love.load()
print("hello") racing.load()
end
function love.update(dt)
racing.update(dt)
end
function love.draw()
racing.draw()
end end

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

@ -0,0 +1,63 @@
local mode = {}
local finish = {100, 100, 0}
local entities = {
racer = {
pos = {0, 100, 0},
color = {255/255, 255/255, 255/255},
race_stats = {
max_speed = 100.0,
accel = 2.0,
current_speed = 2.0,
current_accel = 0.0,
},
draw = function (self)
love.graphics.push()
love.graphics.setColor(self.color[1], self.color[2], self.color[3])
love.graphics.points(self.pos[1], self.pos[2])
love.graphics.print(self.race_stats.current_speed, self.pos[1], self.pos[2])
love.graphics.print(string.format("Max Speed : %s", self.race_stats.max_speed), 0, 0)
love.graphics.print(string.format("Accel : %s", self.race_stats.accel), 0, 20)
love.graphics.print(string.format("Current Accel : %s", self.race_stats.current_accel), 0, 40)
love.graphics.pop()
end,
update = function (self, dt)
if (self.pos[1] > finish[1]) then
self.pos[1] = 0
self.race_stats.current_speed = 0
self.race_stats.current_accel = 0
end
self:accel(dt)
self.pos[1] = self.pos[1] + self.race_stats.current_speed * dt
end,
accel = function(self, dt)
if (self.race_stats.current_accel <= self.race_stats.accel) then
self.race_stats.current_accel = self.race_stats.current_accel + dt
end
if (self.race_stats.current_speed <= self.race_stats.max_speed) then
self.race_stats.current_speed = self.race_stats.current_speed + self.race_stats.current_accel
end
end
}
}
function mode.load()
end
function mode.update(dt)
entities.racer:update(dt)
end
function mode.draw()
entities.racer:draw()
end
return mode