Add percentage_clear on racers
This commit is contained in:
parent
8957b4427c
commit
92174baf7b
@ -239,9 +239,11 @@ end
|
||||
function world:ui_draw()
|
||||
local lw, lh = love.graphics.getDimensions()
|
||||
|
||||
draw_time_attack(lw/2, 20, 1.0, 0.0, 1.0, self.time_attacks)
|
||||
if (self.is_finish) then
|
||||
draw_finish(lw/2, lh/2, 1.0, 1.0, 0.0)
|
||||
if (self.show_pov) then
|
||||
draw_time_attack(lw/2, 20, 1.0, 0.0, 1.0, self.time_attacks)
|
||||
if (self.is_finish) then
|
||||
draw_finish(lw/2, lh/2, 1.0, 1.0, 0.0)
|
||||
end
|
||||
end
|
||||
-- debug_data(650, 0, 1.0, 0.0, 1.0, self.data)
|
||||
-- debug_data(650, 400, 1.0, 0.0, 1.0, magic_w)
|
||||
|
||||
@ -108,7 +108,7 @@ end
|
||||
function world:setup()
|
||||
local map
|
||||
local countdown
|
||||
local checkpoints
|
||||
self.checkpoints = {}
|
||||
self.world_state = {}
|
||||
self.racers = {}
|
||||
self.pov_index = 1
|
||||
@ -130,7 +130,7 @@ function world:setup()
|
||||
elseif e.type == "countdown" then
|
||||
countdown = e
|
||||
elseif e.type == "checkpoints" then
|
||||
checkpoints = e
|
||||
self.checkpoints = e
|
||||
elseif e.type == "racer" then
|
||||
table.insert(self.racers, e)
|
||||
if (e.components.actor.name == "player") then
|
||||
@ -143,7 +143,7 @@ function world:setup()
|
||||
e.components.racer.map = map.components.map
|
||||
e.components.racer.countdown = countdown.components.countdown
|
||||
e.components.racer.world_state = self.world_state.components.world_state
|
||||
e.components.racer.checkpoints = checkpoints.components.checkpoints
|
||||
e.components.racer.checkpoints = self.checkpoints.components.checkpoints
|
||||
elseif (e.type == "countdown") then
|
||||
e.components.countdown:load_world_state(self.world_state.components.world_state)
|
||||
end
|
||||
@ -178,6 +178,34 @@ local phase = "intro"
|
||||
|
||||
local x_is_down = false
|
||||
|
||||
local function percentage_clear(lap, max_lap, cp, max_cp)
|
||||
return lap + cp * (1/max_cp)
|
||||
end
|
||||
|
||||
function world:update_race_rank(dt)
|
||||
local rank = {}
|
||||
for k, v in pairs(self.racers) do
|
||||
local cp = v.components.racer.current_cp
|
||||
local lap = v.components.racer.lap
|
||||
local ts = v.components.racer.time_attacks
|
||||
local finish = v.components.racer.is_finish
|
||||
|
||||
local max_lap = self.checkpoints.components.checkpoints.data.max_lap
|
||||
local max_cp = #self.checkpoints.components.checkpoints.data.check
|
||||
|
||||
local percentage = percentage_clear(lap, max_lap, cp, max_cp)
|
||||
v.components.racer.percentage = percentage
|
||||
|
||||
if (finish) then
|
||||
local t = 0
|
||||
for _, lt in pairs(ts) do
|
||||
t = t + lt
|
||||
end
|
||||
local finish_time = t
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function world:update(dt)
|
||||
for _, e in ipairs(self.entities) do
|
||||
for t, c in pairs(e.components) do
|
||||
@ -199,6 +227,8 @@ function world:update(dt)
|
||||
elseif (not love.keyboard.isDown("x") and x_is_down == true) then
|
||||
x_is_down = false
|
||||
end
|
||||
|
||||
self:update_race_rank(dt)
|
||||
end
|
||||
|
||||
function world:draw()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user