add accel and max speed
This commit is contained in:
parent
dbdf338f3e
commit
a4576b4233
@ -8,10 +8,10 @@ local entities = {
|
||||
color = {255/255, 255/255, 255/255},
|
||||
|
||||
race_stats = {
|
||||
max_speed = 100,
|
||||
speed = 2,
|
||||
accel = 10,
|
||||
|
||||
max_speed = 100.0,
|
||||
accel = 2.0,
|
||||
current_speed = 2.0,
|
||||
current_accel = 0.0,
|
||||
},
|
||||
|
||||
draw = function (self)
|
||||
@ -19,16 +19,31 @@ local entities = {
|
||||
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.speed, 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
|
||||
self.pos[1] = self.pos[1] + self.race_stats.speed * dt
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user