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 --- data/crate_move.wav | Bin 0 -> 102444 bytes data/move.wav | Bin 0 -> 48932 bytes data/restart.wav | Bin 0 -> 59746 bytes data/undo.wav | Bin 0 -> 9950 bytes data/win.wav | Bin 0 -> 397116 bytes main.lua | 22 +++++++++++++++++++++- 6 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 data/crate_move.wav create mode 100644 data/move.wav create mode 100644 data/restart.wav create mode 100644 data/undo.wav create mode 100644 data/win.wav diff --git a/data/crate_move.wav b/data/crate_move.wav new file mode 100644 index 0000000..e8fa8b9 Binary files /dev/null and b/data/crate_move.wav differ diff --git a/data/move.wav b/data/move.wav new file mode 100644 index 0000000..04ff3f6 Binary files /dev/null and b/data/move.wav differ diff --git a/data/restart.wav b/data/restart.wav new file mode 100644 index 0000000..932004b Binary files /dev/null and b/data/restart.wav differ diff --git a/data/undo.wav b/data/undo.wav new file mode 100644 index 0000000..64e4567 Binary files /dev/null and b/data/undo.wav differ diff --git a/data/win.wav b/data/win.wav new file mode 100644 index 0000000..89233dd Binary files /dev/null and b/data/win.wav differ 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