From 8c5a91acb224312ea511c7ff502c44bb9fe7452b Mon Sep 17 00:00:00 2001 From: cursed22bc Date: Wed, 11 Mar 2026 12:50:56 +0200 Subject: sfx and other polish --- player.lua | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'player.lua') diff --git a/player.lua b/player.lua index 6e73691..42e56ad 100644 --- a/player.lua +++ b/player.lua @@ -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() -- cgit v1.2.3