Merge pull request #35 from MarkGamed7794/origin/sound-effect-rework

Add some new behavior to sound effects
This commit is contained in:
Ishaan Bhardwaj 2021-10-17 11:42:45 -04:00 committed by GitHub
commit 75ee07a04d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 86 additions and 46 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto

View File

@ -1,39 +1,69 @@
sounds = { sound_paths = {
blocks = { blocks = {
I = love.audio.newSource("res/se/piece_i.wav", "static"), I = "res/se/piece_i.wav",
J = love.audio.newSource("res/se/piece_j.wav", "static"), J = "res/se/piece_j.wav",
L = love.audio.newSource("res/se/piece_l.wav", "static"), L = "res/se/piece_l.wav",
O = love.audio.newSource("res/se/piece_o.wav", "static"), O = "res/se/piece_o.wav",
S = love.audio.newSource("res/se/piece_s.wav", "static"), S = "res/se/piece_s.wav",
T = love.audio.newSource("res/se/piece_t.wav", "static"), T = "res/se/piece_t.wav",
Z = love.audio.newSource("res/se/piece_z.wav", "static") Z = "res/se/piece_z.wav"
}, },
move = love.audio.newSource("res/se/move.wav", "static"), move = "res/se/move.wav",
bottom = love.audio.newSource("res/se/bottom.wav", "static"), rotate = "res/se/rotate.wav",
cursor = love.audio.newSource("res/se/cursor.wav", "static"), kick = "res/se/kick.wav",
cursor_lr = love.audio.newSource("res/se/cursor_lr.wav", "static"), bottom = "res/se/bottom.wav",
main_decide = love.audio.newSource("res/se/main_decide.wav", "static"), cursor = "res/se/cursor.wav",
mode_decide = love.audio.newSource("res/se/mode_decide.wav", "static"), cursor_lr = "res/se/cursor_lr.wav",
lock = love.audio.newSource("res/se/lock.wav", "static"), main_decide = "res/se/main_decide.wav",
hold = love.audio.newSource("res/se/hold.wav", "static"), mode_decide = "res/se/mode_decide.wav",
erase = love.audio.newSource("res/se/erase.wav", "static"), lock = "res/se/lock.wav",
fall = love.audio.newSource("res/se/fall.wav", "static"), hold = "res/se/hold.wav",
ready = love.audio.newSource("res/se/ready.wav", "static"), erase = {
go = love.audio.newSource("res/se/go.wav", "static"), single = "res/se/single.wav",
irs = love.audio.newSource("res/se/irs.wav", "static"), double = "res/se/double.wav",
ihs = love.audio.newSource("res/se/ihs.wav", "static"), 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! -- 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) function playSE(sound, subsound)
if sound ~= nil then if sound ~= nil then
if sounds[sound] then
if subsound ~= nil then if subsound ~= nil then
if sounds[sound][subsound] then
sounds[sound][subsound]:setVolume(config.sfx_volume) sounds[sound][subsound]:setVolume(config.sfx_volume)
if sounds[sound][subsound]:isPlaying() then if sounds[sound][subsound]:isPlaying() then
sounds[sound][subsound]:stop() sounds[sound][subsound]:stop()
end end
sounds[sound][subsound]:play() sounds[sound][subsound]:play()
end
else else
sounds[sound]:setVolume(config.sfx_volume) sounds[sound]:setVolume(config.sfx_volume)
if sounds[sound]:isPlaying() then if sounds[sound]:isPlaying() then
@ -43,15 +73,19 @@ function playSE(sound, subsound)
end end
end end
end end
end
function playSEOnce(sound, subsound) function playSEOnce(sound, subsound)
if sound ~= nil then if sound ~= nil then
if sounds[sound] then
if subsound ~= nil then if subsound ~= nil then
if sounds[sound][subsound] then
sounds[sound][subsound]:setVolume(config.sfx_volume) sounds[sound][subsound]:setVolume(config.sfx_volume)
if sounds[sound][subsound]:isPlaying() then if sounds[sound][subsound]:isPlaying() then
return return
end end
sounds[sound][subsound]:play() sounds[sound][subsound]:play()
end
else else
sounds[sound]:setVolume(config.sfx_volume) sounds[sound]:setVolume(config.sfx_volume)
if sounds[sound]:isPlaying() then if sounds[sound]:isPlaying() then
@ -61,3 +95,4 @@ function playSEOnce(sound, subsound)
end end
end end
end end
end

BIN
res/se/double.wav Normal file

Binary file not shown.

BIN
res/se/quad.wav Normal file

Binary file not shown.

BIN
res/se/single.wav Normal file

Binary file not shown.

BIN
res/se/triple.wav Normal file

Binary file not shown.

View File

@ -268,7 +268,8 @@ function GameMode:update(inputs, ruleset)
end end
if cleared_row_count > 0 then 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.lcd = self:getLineClearDelay()
self.last_lcd = self.lcd self.last_lcd = self.lcd
self.are = ( self.are = (

View File

@ -98,10 +98,12 @@ function Ruleset:attemptRotate(new_inputs, piece, grid, initial)
if (grid:canPlacePiece(new_piece)) then if (grid:canPlacePiece(new_piece)) then
piece:setRelativeRotation(rot_dir) piece:setRelativeRotation(rot_dir)
self:onPieceRotate(piece, grid) self:onPieceRotate(piece, grid)
playSE("rotate")
else else
if not(initial and self.enable_IRS_wallkicks == false) then if not(initial and self.enable_IRS_wallkicks == false) then
self:attemptWallkicks(piece, new_piece, rot_dir, grid) self:attemptWallkicks(piece, new_piece, rot_dir, grid)
end end
playSE("kick")
end end
end end