Add checkpoint check
This commit is contained in:
parent
e916cf63fa
commit
a9f4d30803
@ -1,5 +1,7 @@
|
|||||||
local vm = require"lib.vornmath"
|
local vm = require"lib.vornmath"
|
||||||
local racing_force = require("love_src.src.system.racing_force")
|
local racing_force = require("love_src.src.system.racing_force")
|
||||||
|
local uib = require"love_src.src.system.ui_behavior"
|
||||||
|
local get_loop = require"love_src.src.system.animation".get_loop
|
||||||
|
|
||||||
local main_wrapper = require "love_src.wrapper.lappy.world"
|
local main_wrapper = require "love_src.wrapper.lappy.world"
|
||||||
---@class wrappers.Concord.world : lappy.world
|
---@class wrappers.Concord.world : lappy.world
|
||||||
@ -57,6 +59,9 @@ function world:load(entity, data)
|
|||||||
|
|
||||||
self.time_attacks = {}
|
self.time_attacks = {}
|
||||||
self.lap = 1
|
self.lap = 1
|
||||||
|
self.current_cp = 1
|
||||||
|
|
||||||
|
self.checkpoints = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function get(s)
|
function get(s)
|
||||||
@ -107,6 +112,15 @@ local function orientation_velocity(dt, force, mass, orientation_speed, orientat
|
|||||||
return new_orientation, new_speed
|
return new_orientation, new_speed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function world:update_checkpoint(dt)
|
||||||
|
local cp = self.checkpoints.data.check[self.current_cp]
|
||||||
|
local is_inside_cp = uib.is_inside(cp.pos[1], cp.pos[2], cp.wh[1], cp.wh[2], self.data.pos[1], self.data.pos[2])
|
||||||
|
if (is_inside_cp) then
|
||||||
|
self.current_cp = get_loop(self.current_cp + 1, #self.checkpoints.data.check)
|
||||||
|
end
|
||||||
|
print(self.current_cp)
|
||||||
|
end
|
||||||
|
|
||||||
function world:update_race(dt)
|
function world:update_race(dt)
|
||||||
local x, y = self.data.pos[1], self.data.pos[2]
|
local x, y = self.data.pos[1], self.data.pos[2]
|
||||||
local or_x, or_y = self.data.orientation[1], self.data.orientation[2]
|
local or_x, or_y = self.data.orientation[1], self.data.orientation[2]
|
||||||
@ -150,17 +164,24 @@ function world:update_race(dt)
|
|||||||
-- end
|
-- end
|
||||||
|
|
||||||
self.data.inertia = force
|
self.data.inertia = force
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function world:update_time_attack(dt)
|
||||||
|
if (self.time_attacks[self.lap] == nil) then
|
||||||
|
self.time_attacks[self.lap] = 0
|
||||||
|
end
|
||||||
|
if (self.world_state.data.state == "count down") then
|
||||||
|
|
||||||
|
else
|
||||||
self.time_attacks[self.lap] = self.time_attacks[self.lap] + dt
|
self.time_attacks[self.lap] = self.time_attacks[self.lap] + dt
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function world:update(dt)
|
function world:update(dt)
|
||||||
self:update_race(dt)
|
self:update_race(dt)
|
||||||
|
self:update_time_attack(dt)
|
||||||
if (self.time_attacks[self.lap] == nil) then
|
self:update_checkpoint(dt)
|
||||||
self.time_attacks[self.lap] = 0
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function world:draw()
|
function world:draw()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user