walljumps

This commit is contained in:
binarycat 2022-02-26 15:12:25 -05:00 committed by lustlion
parent 4efc99659c
commit e9754dc1dd
3 changed files with 15 additions and 1 deletions

View File

@ -22,6 +22,7 @@ function DebugUI()
end end
end end
-- player isOnGroundCheck -- player isOnGroundCheck
--love.graphics.main_Player
love.graphics.setColor(1,0,0) love.graphics.setColor(1,0,0)
end end

View File

@ -14,6 +14,8 @@ function Player:New(x,y)
o.jumpImpulse = 3.5 -- gameworld pixels o.jumpImpulse = 3.5 -- gameworld pixels
self.wallJumpImpulse = { x = 2.5, y = 3.5 }
o.coyoteAmount = 5 -- int o.coyoteAmount = 5 -- int
o.coyoteValue = 5 -- frames o.coyoteValue = 5 -- frames
@ -46,6 +48,7 @@ function Player:New(x,y)
o.canFall = true o.canFall = true
o.canFriction = true o.canFriction = true
o.maskType = animation.moth_mask o.maskType = animation.moth_mask
o.wallHit = 0
o.anchorRespawn = { o.anchorRespawn = {
x = o.pos.x, x = o.pos.x,
@ -93,6 +96,9 @@ function Player:Smart()
if self.coyoteValue > 0 then if self.coyoteValue > 0 then
self.vel.y = -self.jumpImpulse self.vel.y = -self.jumpImpulse
self.coyoteValue = 0 self.coyoteValue = 0
elseif self.wallHit ~= 0 then
self.vel.y = -self.wallJumpImpulse.y
self.vel.x = -self.wallJumpImpulse.x * self.wallHit
end end
end end
end end
@ -233,7 +239,9 @@ function Player:DoPhysics()
-- horizontal collision -- horizontal collision
if not self:isCollidingAt(self.pos.x + self.vel.x + self.move_x, self.pos.y, LoadedObjects.Collisions) then if not self:isCollidingAt(self.pos.x + self.vel.x + self.move_x, self.pos.y, LoadedObjects.Collisions) then
self.pos.x = self.pos.x + self.vel.x + self.move_x self.pos.x = self.pos.x + self.vel.x + self.move_x
self.wallHit = 0
else else
self.wallHit = math.sign(self.vel.x + self.move_x)
self.vel.x = 0 self.vel.x = 0
end end
@ -313,3 +321,7 @@ function Player:Unhook()
self.isHooked = false self.isHooked = false
self.hookAnchor = nil self.hookAnchor = nil
end end
function Player:Debug()
love.graphics.print("wallHit: "..self.wallHit)
end

View File

@ -158,7 +158,8 @@ function Entity:getBoundingBox(animation,top,left,bottom,right)
self.boxCollision.to.y = animation.imgs[1]:getHeight()/2 + bottom self.boxCollision.to.y = animation.imgs[1]:getHeight()/2 + bottom
end end
-- returns true if theres a collision at that point. also marks collisioned tile as collision true -- checks if the the reciever would collide with an object if it was positioned at the given point.
-- also marks collisioned tile as collision true
function Entity:isCollidingAt(x,y,object) function Entity:isCollidingAt(x,y,object)
for _, collision in pairs(object) do for _, collision in pairs(object) do
if collision.disable then if collision.disable then