scenes/boost: rework entirely the relative position system
This commit is contained in:
parent
1506701559
commit
f7582fbe16
3 changed files with 44 additions and 20 deletions
|
@ -5,7 +5,7 @@ return {
|
||||||
stats = {
|
stats = {
|
||||||
spd = 5,
|
spd = 5,
|
||||||
jmp = 3,
|
jmp = 3,
|
||||||
jumpaction = "doublejump",
|
jumpaction = "jumpdash",
|
||||||
jumpaction_power = 2,
|
jumpaction_power = 2,
|
||||||
action = "spinattack",
|
action = "spinattack",
|
||||||
action_power = 1,
|
action_power = 1,
|
||||||
|
|
|
@ -73,6 +73,9 @@ function Character:new(charcontroller, rail, character, id)
|
||||||
self.view.y = self.y
|
self.view.y = self.y
|
||||||
self.view.dx = 0
|
self.view.dx = 0
|
||||||
|
|
||||||
|
self.relx = 0
|
||||||
|
self.relxspeed= 0
|
||||||
|
|
||||||
self.grind = false
|
self.grind = false
|
||||||
|
|
||||||
self.ai = isAIControlled or false
|
self.ai = isAIControlled or false
|
||||||
|
@ -109,7 +112,6 @@ function Character:update(dt)
|
||||||
self:snaptoRails(dt)
|
self:snaptoRails(dt)
|
||||||
|
|
||||||
self:move()
|
self:move()
|
||||||
self:updateView()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ACTIONS FUNCTIONS --
|
-- ACTIONS FUNCTIONS --
|
||||||
|
@ -187,6 +189,8 @@ function Character:move()
|
||||||
|
|
||||||
self:setFilter()
|
self:setFilter()
|
||||||
|
|
||||||
|
self:updateRelativePosition()
|
||||||
|
|
||||||
self.x, self.y, self.z, cols, coll_number = Character.super.move(self)
|
self.x, self.y, self.z, cols, coll_number = Character.super.move(self)
|
||||||
|
|
||||||
for i=1, coll_number do
|
for i=1, coll_number do
|
||||||
|
@ -199,23 +203,40 @@ function Character:move()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Character:updateView()
|
function Character:updateRelativePosition()
|
||||||
local MAXVIEW = - 80
|
local MAXVIEW = 80
|
||||||
local MINVIEW = 20
|
local MINVIEW = -20
|
||||||
local targetView = 0
|
if not ((self.onGround == false) and (self.z < 0)) then
|
||||||
|
if (self.dashCam) or (self.dash) then
|
||||||
if self.dash or self.dashCam then
|
self.relx = math.min(self.relx + 0.4, MAXVIEW)
|
||||||
targetView = MAXVIEW
|
else
|
||||||
|
if self.keys["left"].isDown then
|
||||||
|
if self.relx > 0 then
|
||||||
|
self.relx = math.max(self.relx - 0.3, 0)
|
||||||
|
elseif self.relx <= 0 then
|
||||||
|
self.relx = math.max(self.relx - 0.1, MINVIEW)
|
||||||
|
end
|
||||||
|
elseif self.keys["right"].isDown then
|
||||||
|
if self.relx >= 0 then
|
||||||
|
if self.relx <= MAXVIEW*3/4 then
|
||||||
|
self.relx = math.min(self.relx + 0.2, MAXVIEW*3/4)
|
||||||
|
else
|
||||||
|
self.relx = math.max(self.relx - 0.1, MAXVIEW*3/4)
|
||||||
|
end
|
||||||
|
elseif self.relx < 0 then
|
||||||
|
self.relx = math.min(self.relx + 0.3, 0)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if self.relx > 0 then
|
||||||
|
self.relx = math.max(self.relx - 0.3, 0)
|
||||||
|
elseif self.relx < 0 then
|
||||||
|
self.relx = math.min(self.relx + 0.3, 0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local viewDirection = utils.math.sign(targetView - self.view.dx)
|
self.x = self.view.x + self.relx
|
||||||
self.view.dx = self.view.dx + phys.acc * viewDirection * 1.75
|
|
||||||
--self.view.dx = self.view.dx + (self.xspeed - self.data.stats.spd*60)
|
|
||||||
|
|
||||||
self.view.x = self.x + math.max(MAXVIEW, math.min(self.view.dx, MINVIEW))
|
|
||||||
|
|
||||||
print(self.dash)
|
|
||||||
print(targetView .. ";" .. self.x .. ";" .. self.view.x)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Character:getViewCenter()
|
function Character:getViewCenter()
|
||||||
|
@ -294,7 +315,7 @@ function Character:autoMove(dt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.x = self.x + self.xspeed * dt
|
self.view.x = self.view.x + self.xspeed * dt
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.x >= self.controller.world.width then
|
if self.x >= self.controller.world.width then
|
||||||
|
@ -489,7 +510,10 @@ function Character:die()
|
||||||
self.charcontroller:die()
|
self.charcontroller:die()
|
||||||
else
|
else
|
||||||
self.life = self.life - 1
|
self.life = self.life - 1
|
||||||
self.x = self.startx
|
self.view.x = self.startx
|
||||||
|
self.relx = 0
|
||||||
|
self.dash = false
|
||||||
|
self.dashCam= false
|
||||||
self.y = self.starty
|
self.y = self.starty
|
||||||
self.z = 0
|
self.z = 0
|
||||||
self.rings = 0
|
self.rings = 0
|
||||||
|
|
|
@ -104,7 +104,7 @@ function Player:getKeys()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:wrapActor()
|
function Player:wrapActor()
|
||||||
self.actor.x = math.floor(self.actor.x - self.controller.world.width)
|
self.actor.view.x = math.floor(self.actor.view.x - self.controller.world.width)
|
||||||
self.actor.turn = self.actor.turn + 1
|
self.actor.turn = self.actor.turn + 1
|
||||||
self.controller.camera.view.x = self.controller.camera.view.x - self.controller.world.width
|
self.controller.camera.view.x = self.controller.camera.view.x - self.controller.world.width
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue