Compare commits
2 Commits
d015cc7271
...
a4576b4233
| Author | SHA1 | Date | |
|---|---|---|---|
| a4576b4233 | |||
| dbdf338f3e |
@ -1,3 +1,13 @@
|
||||
local racing = require("src.modes.racing")
|
||||
|
||||
function love.load()
|
||||
print("hello")
|
||||
racing.load()
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
racing.update(dt)
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
racing.draw()
|
||||
end
|
||||
|
||||
63
game/src/modes/racing.lua
Normal file
63
game/src/modes/racing.lua
Normal 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
|
||||
Loading…
x
Reference in New Issue
Block a user