From b8f0d57a8acc223b6872e122ba614e45c0831437 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 4 Feb 2019 21:35:34 +0100 Subject: [PATCH] scenes/boost: add a relative camera system --- .../subgame/sonic-boost/actors/character.lua | 39 ++++++++++++++++++- .../subgame/sonic-boost/actors/parent.lua | 4 ++ .../subgame/sonic-boost/controller/camera.lua | 2 +- 3 files changed, 43 insertions(+), 2 deletions(-) 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 f80d218..6792aa6 100644 --- a/sonic-boost.love/scenes/subgame/sonic-boost/actors/character.lua +++ b/sonic-boost.love/scenes/subgame/sonic-boost/actors/character.lua @@ -47,6 +47,7 @@ function Character:new(charcontroller, rail, character, id) self.canAction = true self.dash = false + self.dashCam = false self:setDebugColor(0, 255, 0) @@ -67,6 +68,11 @@ function Character:new(charcontroller, rail, character, id) self.startx = self.x self.starty = self.y + self.view = {} + self.view.x = self.x + self.view.y = self.y + self.view.dx = 0 + self.grind = false self.ai = isAIControlled or false @@ -103,6 +109,7 @@ function Character:update(dt) self:snaptoRails(dt) self:move() + self:updateView() end -- ACTIONS FUNCTIONS -- @@ -153,11 +160,12 @@ end function Character:normalAction() if self.data.stats.action == "spinattack" then if (self.keys["B"].isPressed) and (self.onGround) and (self.canAction) and (self.grind == false) then - self.xspeed = math.max(self.xspeed, self.data.stats.spd * 60) + self.xspeed = math.max(self.xspeed, self.data.stats.spd * 60 * 1.5) self.isInAction = true self.canAction = false self:addTimer("action", .5) self:addTimer("action_cooldown", 1) + self.dashCam = true end end end @@ -181,6 +189,34 @@ 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 + 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) +end + +function Character:getViewCenter() + local x, y, z + x = math.floor(self.view.x + self.w / 2) + y = math.floor(self.y + self.h / 2) + z = math.floor(self.z + self.d / 2) + + return x, y, z +end + function Character:collisionResponse(other) if other == nil then return 0 end if other.type == "collectible" then @@ -460,6 +496,7 @@ function Character:endedTimer(name) self.bonus = 0 elseif name == "action" then self.isInAction = false + self.dashCam = false elseif name == "action_cooldown" then self.canAction = true end diff --git a/sonic-boost.love/scenes/subgame/sonic-boost/actors/parent.lua b/sonic-boost.love/scenes/subgame/sonic-boost/actors/parent.lua index 7bdb1c4..1d0d92f 100644 --- a/sonic-boost.love/scenes/subgame/sonic-boost/actors/parent.lua +++ b/sonic-boost.love/scenes/subgame/sonic-boost/actors/parent.lua @@ -127,6 +127,10 @@ function ParentEntity:getCenter() return x, y, z end +function ParentEntity:getViewCenter() + return self:getCenter() +end + function ParentEntity:getOrigin() local x, y, z y = math.floor(self.y + self.h / 2) diff --git a/sonic-boost.love/scenes/subgame/sonic-boost/controller/camera.lua b/sonic-boost.love/scenes/subgame/sonic-boost/controller/camera.lua index 4fa8fde..97fd9f4 100644 --- a/sonic-boost.love/scenes/subgame/sonic-boost/controller/camera.lua +++ b/sonic-boost.love/scenes/subgame/sonic-boost/controller/camera.lua @@ -92,7 +92,7 @@ function CameraSystem:followEntity(entity) if (entity ~= nil) then self.turn = entity.turn or 1 - local playx, playy = entity:getCenter() + local playx, playy = entity:getViewCenter() local camx, camy = self.view.x + (self.width/2), self.view.y + (self.height/2)