screen borders

This commit is contained in:
assada 2024-05-30 11:45:27 +03:00
parent 85225f7c2d
commit a71461dac0
Signed by: assada
GPG Key ID: D4860A938E541F06

View File

@ -9,7 +9,8 @@ function Player:init(x, y, gameManager)
local playerImageTable = gfx.imagetable.new("sprites/player-table-48-48")
Player.super.init(self, playerImageTable)
self:addState("run", 8,14, {tickStep = 2})
-- self:addState("run", 8,14, {tickStep = 2})
self:addState("run", 1,7, {tickStep = 2})
self:addState("up", 1,7, {tickStep = 6})
self:addState("down", 1,7, {tickStep = 6})
self:addState("boom", 15,21, {tickStep = 10, loop = false})
@ -63,10 +64,12 @@ function Player:handleGroundInput(state)
if pd.buttonIsPressed(pd.kButtonLeft) then
self:changeToRunState("left")
self:setRotation(10)
self.cantDown = true
Player.moveRight = false
elseif pd.buttonIsPressed(pd.kButtonRight) then
self:changeToRunState("right")
self:setRotation(10)
self.cantDown = true
Player.moveRight = true
end
@ -93,6 +96,7 @@ function Player:changeToDownState()
self.yVelocity = self.fallSpeed
self.xVelocity = 0
self:changeState("down")
self:setRotation(0)
end
function Player:changeToRunState(direction)
@ -108,7 +112,17 @@ function Player:changeToRunState(direction)
end
function Player:handleMovementAndCollisions()
local _, _, collisions, length = self:moveWithCollisions(self.x + self.xVelocity, self.y + self.yVelocity)
local _
local collisions
local length = 0
if self.x >= 20 and self.x <= 380 then
_, _, collisions, length = self:moveWithCollisions(self.x + self.xVelocity, self.y + self.yVelocity)
elseif self.x == 380 then
self.x = 380
else
self.x = 20
end
self.touchingGround = false
self.touchingCeiling = false