added seconds since start, tweaked wall jump, added wall friction and isSliding

This commit is contained in:
lustlion 2022-02-27 05:30:46 +01:00
parent e3a5ab0c42
commit 2b9f605a0a
3 changed files with 25 additions and 12 deletions

View File

@ -8,7 +8,7 @@ function DebugUI()
love.graphics.print(light.pos.x,light.pos.x,light.pos.y+40) love.graphics.print(light.pos.x,light.pos.x,light.pos.y+40)
end end
love.graphics.print("fps: "..fps_current, 10*textScale, 0*textScale, 0, textScale) love.graphics.print("time: ".. tostring(math.floor(100*game.secondsSinceStart)/100) .." fps: "..fps_current, 10*textScale, 0*textScale, 0, textScale)
love.graphics.print(--[["CPUtime: "..checkCPUTime("total")..", CPU: "..(math.floor(checkCPUTime("get")*10000)/100).."%,]] "memoryUsage: "..memoryUsage.."kB", 10*textScale, 20*textScale, 0, textScale) love.graphics.print(--[["CPUtime: "..checkCPUTime("total")..", CPU: "..(math.floor(checkCPUTime("get")*10000)/100).."%,]] "memoryUsage: "..memoryUsage.."kB", 10*textScale, 20*textScale, 0, textScale)
love.graphics.setColor(1,1,1) love.graphics.setColor(1,1,1)

View File

@ -16,8 +16,6 @@ function Player:New(x,y)
o.jumpImpulse = 3.5 -- gameworld pixels o.jumpImpulse = 3.5 -- gameworld pixels
o.wallJumpImpulse = { x = 2.5, y = 3.5 }
o.coyoteValue = 5 -- frames o.coyoteValue = 5 -- frames
o.coyoteAmount = 5 -- int o.coyoteAmount = 5 -- int
@ -40,7 +38,9 @@ function Player:New(x,y)
} }
-- walljump values -- walljump values
o.walljumpNoDriftAmount = 7 o.walljumpNoDriftAmount = 12
o.walljumpImpulse = { x = 2.5, y = 3.5 }
o.walljumpFriction = 0.3 -- gameworld pixels
-- light values -- light values
o.lightRange = 40 -- screen pixels o.lightRange = 40 -- screen pixels
@ -54,8 +54,9 @@ function Player:New(x,y)
o.isDashing = false o.isDashing = false
o.isHooked = false o.isHooked = false
o.isSliding = false
o.isJumping = false o.isJumping = false
o.isOnGround = true o.isOnGround = false
o.isOnLadder = false o.isOnLadder = false
o.maskType = animation.moth_mask o.maskType = animation.moth_mask
@ -111,13 +112,16 @@ function Player:Smart()
-- jump if on ground (coyotevalue) or if 0 -- jump if on ground (coyotevalue) or if 0
if self.canJump and Keybind:CheckPressed(Keybind.move.jump) then if self.canJump and Keybind:CheckPressed(Keybind.move.jump) then
if self.coyoteValue > 0 then if self.canWalljump and self.wallHit ~= 0 then
self.isSliding = false
self.vel.y = -self.walljumpImpulse.y
self.vel.x = -self.walljumpImpulse.x * self.wallHit
self.move_x = 0
self.sprite_flip.x = -self.sprite_flip.x
self.noDriftFrames = self.walljumpNoDriftAmount
elseif self.coyoteValue > 0 then
self.vel.y = -self.jumpImpulse self.vel.y = -self.jumpImpulse
self.coyoteValue = 0 self.coyoteValue = 0
elseif self.canWalljump and self.wallHit ~= 0 then
self.vel.y = -self.wallJumpImpulse.y
self.vel.x = -self.wallJumpImpulse.x * self.wallHit
self.noDriftFrames = self.walljumpNoDriftAmount
end end
end end
end end
@ -183,7 +187,13 @@ function Player:DoPhysics()
self.vel.x = self.vel.x * (1-self.airFriction) self.vel.x = self.vel.x * (1-self.airFriction)
end end
self.isSliding = false
if self.wallHit == 0 then
self.vel.y = self.vel.y * (1-self.airFriction) self.vel.y = self.vel.y * (1-self.airFriction)
elseif self.noDriftFrames ~= self.walljumpNoDriftAmount then
self.isSliding = true
self.vel.y = self.vel.y * (1-self.walljumpFriction)
end
if math.abs(self.vel.x) < self.zeroSpeed then self.vel.x = 0 end if math.abs(self.vel.x) < self.zeroSpeed then self.vel.x = 0 end
end end
@ -301,7 +311,7 @@ function Player:HandleAnimation()
end end
-- animation priority -- animation priority
if self.vel.y > 1.25 then if self.vel.y > 1.25 or self.isSliding then
self.body = self.body:ChangeTo(animation.nancy.fall) self.body = self.body:ChangeTo(animation.nancy.fall)
self.mask = self.mask:ChangeTo(self.maskType.fall) self.mask = self.mask:ChangeTo(self.maskType.fall)
elseif self.vel.y < 0 then elseif self.vel.y < 0 then
@ -346,5 +356,6 @@ function Player:Unhook()
end end
function Player:Debug() function Player:Debug()
Entity.Debug(self)
love.graphics.print("wallHit: "..self.wallHit) love.graphics.print("wallHit: "..self.wallHit)
end end

View File

@ -17,6 +17,7 @@ function love.load()
love.graphics.setDefaultFilter("nearest") -- good pixel love.graphics.setDefaultFilter("nearest") -- good pixel
game = { game = {
secondsSinceStart = 0,
scale = 2, scale = 2,
width = love.graphics.getWidth(), width = love.graphics.getWidth(),
height = love.graphics.getHeight(), height = love.graphics.getHeight(),
@ -68,6 +69,7 @@ function love.update(dt)
fps_current = fps_history:Push(1/dt) fps_current = fps_history:Push(1/dt)
current_dt = dt current_dt = dt
game.secondsSinceStart = game.secondsSinceStart + dt
if DemoRecording or DemoPlayback then Demo:Step() end if DemoRecording or DemoPlayback then Demo:Step() end