diff options
| author | cursed22bc <admin@pixeldawn.org> | 2026-03-11 12:50:56 +0200 |
|---|---|---|
| committer | cursed22bc <admin@pixeldawn.org> | 2026-03-11 12:50:56 +0200 |
| commit | 8c5a91acb224312ea511c7ff502c44bb9fe7452b (patch) | |
| tree | 194a2aee7f92fabbab79cc0ab64f0d2989b7d55e /player.lua | |
| parent | cd432860828a84aca93852a09cf05fc0e6294bab (diff) | |
sfx and other polish
Diffstat (limited to 'player.lua')
| -rw-r--r-- | player.lua | 27 |
1 files changed, 24 insertions, 3 deletions
@@ -1,5 +1,6 @@ local Entity = require("entity") local Animation = require("animation") +local sfx = require("sfx") local Player = {} Player.__index = Player @@ -27,7 +28,7 @@ function Player.new(world, spawnX, spawnY) self:enablePhysics(world, "dynamic") self.fixture:setFriction(0) - self.doubleJump = true + self.doubleJump = false self.jumpsUsed = 0 self.animations = { idle = Animation.new("assets/player/idle.png", 16, 16, 0.6), @@ -162,7 +163,9 @@ function Player:update(dt) self.body:applyForce(move * SWIM_SPEED, moveY * SWIM_SPEED) elseif onFloor or onWaterSurface then self.body:setLinearDamping(0) - self.jumpsUsed = 0 + if not prevOnFloor then + self.jumpsUsed = 0 + end if move ~= 0 then self.lastFacing = move self.body:setLinearVelocity(move * MOVE_SPEED, vy) @@ -203,6 +206,19 @@ function Player:update(dt) end end + if self.state ~= prevState then + if self.state == "running" then + sfx.loop("running") + elseif prevState == "running" then + sfx.stop("running") + end + if self.state == "ground_hit" then + sfx.play("land") + end + end + + sfx.setLiquidEffect(self.isInLiquid) + self.wasOnFloor = onFloor self.wasInLiquid = self.isInLiquid @@ -225,6 +241,8 @@ function Player:die(nx, ny) self.isDead = true self.state = "dead" self.respawnTimer = 4 + sfx.stop("running") + sfx.play("die") local len = math.sqrt(nx * nx + ny * ny) if len < 0.01 then @@ -260,7 +278,8 @@ function Player:jump() return false end - local maxJumps = self.doubleJump and 1 or 0 + self.doubleJump = (self.pickups["dbljump"] or 0) > 0 + local maxJumps = self.doubleJump and 2 or 1 if self.jumpsUsed >= maxJumps then return false @@ -272,6 +291,8 @@ function Player:jump() self.body:setLinearVelocity(self.body:getLinearVelocity(), JUMP_FORCE) + sfx.play("jump") + self.state = "jumping" self.animations.going_up:reset() |
