scenes/boost: add a relative camera system
This commit is contained in:
parent
c09138df5e
commit
b8f0d57a8a
3 changed files with 43 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue