diff options
author | Juan J. Martinez <jjm@usebox.net> | 2024-01-01 17:17:42 +0000 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2024-01-01 17:17:42 +0000 |
commit | e08bf0a732db1efae4cbc9caa72cfc6f983c1232 (patch) | |
tree | bc28856d26fa32e564dfc31af5c8ad0e8dd9d99c /main.lua | |
parent | cadf402db8462a013f77a051914c9b953cf97d71 (diff) | |
download | storage-chaos-main.tar.gz storage-chaos-main.zip |
Diffstat (limited to 'main.lua')
-rw-r--r-- | main.lua | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -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) |