From f7582fbe16431d51b6e05652b88f9385841f0966 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 5 Feb 2019 22:37:10 +0100 Subject: [PATCH] scenes/boost: rework entirely the relative position system --- .../datas/subgame/sonic-boost/characters.lua | 2 +- .../subgame/sonic-boost/actors/character.lua | 60 +++++++++++++------ .../sonic-boost/controller/characters.lua | 2 +- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/sonic-boost.love/datas/subgame/sonic-boost/characters.lua b/sonic-boost.love/datas/subgame/sonic-boost/characters.lua index 80ac91e..c4b5a04 100644 --- a/sonic-boost.love/datas/subgame/sonic-boost/characters.lua +++ b/sonic-boost.love/datas/subgame/sonic-boost/characters.lua @@ -5,7 +5,7 @@ return { stats = { spd = 5, jmp = 3, - jumpaction = "doublejump", + jumpaction = "jumpdash", jumpaction_power = 2, action = "spinattack", action_power = 1, diff --git a/sonic-boost.love/scenes/subgame/sonic-boost/actors/character.lua b/sonic-boost.love/scenes/subgame/sonic-boost/actors/character.lua index ec10776..82b8565 100644 --- a/sonic-boost.love/scenes/subgame/sonic-boost/actors/character.lua +++ b/sonic-boost.love/scenes/subgame/sonic-boost/actors/character.lua @@ -73,6 +73,9 @@ function Character:new(charcontroller, rail, character, id) self.view.y = self.y self.view.dx = 0 + self.relx = 0 + self.relxspeed= 0 + self.grind = false self.ai = isAIControlled or false @@ -109,7 +112,6 @@ function Character:update(dt) self:snaptoRails(dt) self:move() - self:updateView() end -- ACTIONS FUNCTIONS -- @@ -187,6 +189,8 @@ function Character:move() self:setFilter() + self:updateRelativePosition() + self.x, self.y, self.z, cols, coll_number = Character.super.move(self) for i=1, coll_number do @@ -199,23 +203,40 @@ function Character:move() end -function Character:updateView() - local MAXVIEW = - 80 - local MINVIEW = 20 - local targetView = 0 - - if self.dash or self.dashCam then - targetView = MAXVIEW +function Character:updateRelativePosition() + local MAXVIEW = 80 + local MINVIEW = -20 + if not ((self.onGround == false) and (self.z < 0)) then + if (self.dashCam) or (self.dash) then + self.relx = math.min(self.relx + 0.4, 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 - local viewDirection = utils.math.sign(targetView - self.view.dx) - 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) + self.x = self.view.x + self.relx end function Character:getViewCenter() @@ -294,7 +315,7 @@ function Character:autoMove(dt) end end - self.x = self.x + self.xspeed * dt + self.view.x = self.view.x + self.xspeed * dt end if self.x >= self.controller.world.width then @@ -489,7 +510,10 @@ function Character:die() self.charcontroller:die() else 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.z = 0 self.rings = 0 diff --git a/sonic-boost.love/scenes/subgame/sonic-boost/controller/characters.lua b/sonic-boost.love/scenes/subgame/sonic-boost/controller/characters.lua index 38b532c..0e8f46a 100644 --- a/sonic-boost.love/scenes/subgame/sonic-boost/controller/characters.lua +++ b/sonic-boost.love/scenes/subgame/sonic-boost/controller/characters.lua @@ -104,7 +104,7 @@ function Player:getKeys() end 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.controller.camera.view.x = self.controller.camera.view.x - self.controller.world.width end