summaryrefslogtreecommitdiff
path: root/player.lua
diff options
context:
space:
mode:
authorcursed22bc <admin@pixeldawn.org>2026-03-08 23:15:16 +0200
committercursed22bc <admin@pixeldawn.org>2026-03-08 23:15:16 +0200
commit97d0d1ecc0cfd5516cfad2d477faa4d35992e7ba (patch)
tree5ba61a59723d5c9ceb8059388d35bdcb069af743 /player.lua
parentaeb596379bbf1bec84efb294ff5bbbee922364ba (diff)
liquid shader and basic text render
Diffstat (limited to 'player.lua')
-rw-r--r--player.lua39
1 files changed, 28 insertions, 11 deletions
diff --git a/player.lua b/player.lua
index b6bc4b5..81e56bc 100644
--- a/player.lua
+++ b/player.lua
@@ -22,6 +22,9 @@ function Player.new(world, spawnX, spawnY)
self.availableJumps = 0
self:enablePhysics(world, "dynamic")
+ self.fixture:setFriction(0)
+ self.doubleJump = true
+ self.jumpsUsed = 0
self.animations = {
idle = Animation.new("assets/player/idle.png", 16, 16, 0.6),
running = Animation.new("assets/player/running.png", 16, 16, 0.9),
@@ -139,7 +142,7 @@ function Player:update(dt)
self.body:applyForce(move * SWIM_SPEED, moveY * SWIM_SPEED)
elseif onFloor or onWaterSurface then
self.body:setLinearDamping(0)
- self.availableJumps = 1
+ self.jumpsUsed = 0
if move ~= 0 then
self.lastFacing = move
self.body:setLinearVelocity(move * MOVE_SPEED, vy)
@@ -198,18 +201,32 @@ end
function Player:jump()
local c = self.contact or { floor = 0, wall = 0, ceiling = 0 }
+ local onFloor = c.floor == 1
+ local onWall = c.wall == 1
local onWaterSurface = self.waterSurfaceContact
- local canJump = (c.floor == 1 or c.wall == 1 or onWaterSurface) and (self.availableJumps or 0) > 0
- if not canJump then return false end
- if self.isInLiquid and not onWaterSurface then return false end
- if canJump then
- self.body:setLinearVelocity(self.body:getLinearVelocity(), JUMP_FORCE)
- self.state = "jumping"
- self.animations.going_up:reset()
- self.availableJumps = self.availableJumps - 1
- return true
+
+ if onWall and not onFloor then
+ return false
+ end
+
+ local maxJumps = self.doubleJump and 2 or 1
+
+ if self.jumpsUsed >= maxJumps then
+ return false
end
- return false
+
+ if self.isInLiquid and not onWaterSurface then
+ return false
+ end
+
+ self.body:setLinearVelocity(self.body:getLinearVelocity(), JUMP_FORCE)
+
+ self.state = "jumping"
+ self.animations.going_up:reset()
+
+ self.jumpsUsed = self.jumpsUsed + 1
+
+ return true
end
function Player:draw()