From e08bf0a732db1efae4cbc9caa72cfc6f983c1232 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Mon, 1 Jan 2024 17:17:42 +0000 Subject: Added sound effects --- main.lua | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'main.lua') diff --git a/main.lua b/main.lua index 3391780..832afea 100644 --- a/main.lua +++ b/main.lua @@ -35,6 +35,13 @@ function love.load() goal = love.graphics.newImage("data/goal.png") crate_goal = love.graphics.newImage("data/crate_goal.png") + -- load sounds + move_sound = love.audio.newSource("data/move.wav", "static") + crate_sound = love.audio.newSource("data/crate_move.wav", "static") + undo_sound = love.audio.newSource("data/undo.wav", "static") + restart_sound = love.audio.newSource("data/restart.wav", "static") + win_sound = love.audio.newSource("data/win.wav", "static") + player_frames = { love.graphics.newImage("data/player_01.png"), love.graphics.newImage("data/player_02.png") @@ -107,6 +114,7 @@ function move(target_x, target_y) end end + local playing = false -- pushing a box if destination == '$' or destination == '*' then local destination_crate = level[player_y + target_y * 2][player_x + target_x * 2] @@ -127,6 +135,9 @@ function move(target_x, target_y) else level[player_y + target_y * 2][player_x + target_x * 2] = '*' end + + playing = true + crate_sound:play() else -- we can't, so we don't move return @@ -151,6 +162,10 @@ function move(target_x, target_y) player_y = player_y + target_y moves = moves + 1 + if playing == false then + move_sound:play() + end + -- save the previous move for UNDO table.insert(state_undo, 1, {undo, undo_x, undo_y}) end @@ -173,8 +188,9 @@ end -- keypressed handler during play function keypressed_play(key) if key == "r" then - -- reset level + -- restart level set_level(current_level) + restart_sound:play() return elseif key == "u" and #state_undo > 0 then -- undo move @@ -183,6 +199,7 @@ function keypressed_play(key) player_x = state[2] player_y = state[3] moves = moves - 1 + undo_sound:play() end -- where are we moving @@ -294,6 +311,9 @@ function love.draw() if state == "win" then if win_delay < 64 then win_delay = win_delay + 1 + if win_delay == 64 then + win_sound:play() + end else love.graphics.setColor(0.3, 0.3, 0.5) love.graphics.rectangle("fill", 0, 80 * game.scale, game.width * game.scale, 60 * game.scale) -- cgit v1.2.3