diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/load/sounds.lua b/load/sounds.lua index 0dfae21..6e03b1f 100644 --- a/load/sounds.lua +++ b/load/sounds.lua @@ -1,63 +1,98 @@ -sounds = { +sound_paths = { blocks = { - I = love.audio.newSource("res/se/piece_i.wav", "static"), - J = love.audio.newSource("res/se/piece_j.wav", "static"), - L = love.audio.newSource("res/se/piece_l.wav", "static"), - O = love.audio.newSource("res/se/piece_o.wav", "static"), - S = love.audio.newSource("res/se/piece_s.wav", "static"), - T = love.audio.newSource("res/se/piece_t.wav", "static"), - Z = love.audio.newSource("res/se/piece_z.wav", "static") + I = "res/se/piece_i.wav", + J = "res/se/piece_j.wav", + L = "res/se/piece_l.wav", + O = "res/se/piece_o.wav", + S = "res/se/piece_s.wav", + T = "res/se/piece_t.wav", + Z = "res/se/piece_z.wav" }, - move = love.audio.newSource("res/se/move.wav", "static"), - bottom = love.audio.newSource("res/se/bottom.wav", "static"), - cursor = love.audio.newSource("res/se/cursor.wav", "static"), - cursor_lr = love.audio.newSource("res/se/cursor_lr.wav", "static"), - main_decide = love.audio.newSource("res/se/main_decide.wav", "static"), - mode_decide = love.audio.newSource("res/se/mode_decide.wav", "static"), - lock = love.audio.newSource("res/se/lock.wav", "static"), - hold = love.audio.newSource("res/se/hold.wav", "static"), - erase = love.audio.newSource("res/se/erase.wav", "static"), - fall = love.audio.newSource("res/se/fall.wav", "static"), - ready = love.audio.newSource("res/se/ready.wav", "static"), - go = love.audio.newSource("res/se/go.wav", "static"), - irs = love.audio.newSource("res/se/irs.wav", "static"), - ihs = love.audio.newSource("res/se/ihs.wav", "static"), + move = "res/se/move.wav", + rotate = "res/se/rotate.wav", + kick = "res/se/kick.wav", + bottom = "res/se/bottom.wav", + cursor = "res/se/cursor.wav", + cursor_lr = "res/se/cursor_lr.wav", + main_decide = "res/se/main_decide.wav", + mode_decide = "res/se/mode_decide.wav", + lock = "res/se/lock.wav", + hold = "res/se/hold.wav", + erase = { + single = "res/se/single.wav", + double = "res/se/double.wav", + triple = "res/se/triple.wav", + quad = "res/se/quad.wav" + }, + fall = "res/se/fall.wav", + ready = "res/se/ready.wav", + go = "res/se/go.wav", + irs = "res/se/irs.wav", + ihs = "res/se/ihs.wav", -- a secret sound! - welcome = love.audio.newSource("res/se/welcomeToCambridge.wav", "static"), + welcome = "res/se/welcomeToCambridge.wav", } +sounds = {} +-- Replace each sound effect string with its love audiosource counterpart, but only if it exists. This lets the game handle missing SFX. +for k,v in pairs(sound_paths) do + if(type(v) == "table") then + -- list of subsounds + for k2,v2 in pairs(v) do + if(love.filesystem.getInfo(sound_paths[k][k2])) then + -- this file exists + sounds[k] = sounds[k] or {} + sounds[k][k2] = love.audio.newSource(sound_paths[k][k2], "static") + end + end + else + if(love.filesystem.getInfo(sound_paths[k])) then + -- this file exists + sounds[k] = love.audio.newSource(sound_paths[k], "static") + end + end +end + function playSE(sound, subsound) if sound ~= nil then - if subsound ~= nil then - sounds[sound][subsound]:setVolume(config.sfx_volume) - if sounds[sound][subsound]:isPlaying() then - sounds[sound][subsound]:stop() + if sounds[sound] then + if subsound ~= nil then + if sounds[sound][subsound] then + sounds[sound][subsound]:setVolume(config.sfx_volume) + if sounds[sound][subsound]:isPlaying() then + sounds[sound][subsound]:stop() + end + sounds[sound][subsound]:play() + end + else + sounds[sound]:setVolume(config.sfx_volume) + if sounds[sound]:isPlaying() then + sounds[sound]:stop() + end + sounds[sound]:play() end - sounds[sound][subsound]:play() - else - sounds[sound]:setVolume(config.sfx_volume) - if sounds[sound]:isPlaying() then - sounds[sound]:stop() - end - sounds[sound]:play() end end end function playSEOnce(sound, subsound) if sound ~= nil then - if subsound ~= nil then - sounds[sound][subsound]:setVolume(config.sfx_volume) - if sounds[sound][subsound]:isPlaying() then - return + if sounds[sound] then + if subsound ~= nil then + if sounds[sound][subsound] then + sounds[sound][subsound]:setVolume(config.sfx_volume) + if sounds[sound][subsound]:isPlaying() then + return + end + sounds[sound][subsound]:play() + end + else + sounds[sound]:setVolume(config.sfx_volume) + if sounds[sound]:isPlaying() then + return + end + sounds[sound]:play() end - sounds[sound][subsound]:play() - else - sounds[sound]:setVolume(config.sfx_volume) - if sounds[sound]:isPlaying() then - return - end - sounds[sound]:play() end end end \ No newline at end of file diff --git a/res/se/double.wav b/res/se/double.wav new file mode 100644 index 0000000..ca326cf Binary files /dev/null and b/res/se/double.wav differ diff --git a/res/se/quad.wav b/res/se/quad.wav new file mode 100644 index 0000000..ca326cf Binary files /dev/null and b/res/se/quad.wav differ diff --git a/res/se/single.wav b/res/se/single.wav new file mode 100644 index 0000000..ca326cf Binary files /dev/null and b/res/se/single.wav differ diff --git a/res/se/triple.wav b/res/se/triple.wav new file mode 100644 index 0000000..ca326cf Binary files /dev/null and b/res/se/triple.wav differ diff --git a/tetris/modes/gamemode.lua b/tetris/modes/gamemode.lua index a3782f4..2c805e3 100644 --- a/tetris/modes/gamemode.lua +++ b/tetris/modes/gamemode.lua @@ -268,7 +268,8 @@ function GameMode:update(inputs, ruleset) end if cleared_row_count > 0 then - playSE("erase") + local row_count_names = {"single","double","triple","quad"} + playSE("erase",row_count_names[cleared_row_count] or "quad") self.lcd = self:getLineClearDelay() self.last_lcd = self.lcd self.are = ( diff --git a/tetris/rulesets/ruleset.lua b/tetris/rulesets/ruleset.lua index 61c42f7..48b1da0 100644 --- a/tetris/rulesets/ruleset.lua +++ b/tetris/rulesets/ruleset.lua @@ -98,10 +98,12 @@ function Ruleset:attemptRotate(new_inputs, piece, grid, initial) if (grid:canPlacePiece(new_piece)) then piece:setRelativeRotation(rot_dir) self:onPieceRotate(piece, grid) + playSE("rotate") else if not(initial and self.enable_IRS_wallkicks == false) then self:attemptWallkicks(piece, new_piece, rot_dir, grid) end + playSE("kick") end end