add sound effects

This commit is contained in:
fnicon 2026-03-22 19:57:25 +09:00
parent 5dbf8ce1d0
commit 0d8c45e621
6 changed files with 41 additions and 4 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -32,6 +32,8 @@ function world:load(entity, data)
self.data = data or default self.data = data or default
self.data.temp_color = self.data.bg_color self.data.temp_color = self.data.bg_color
self.mouse = "not click" self.mouse = "not click"
self.sfx_highlight = love.audio.newSource("love_src/asset/audio/sfx/book_flip.4.ogg", "static")
self.sfx_click = love.audio.newSource("love_src/asset/audio/sfx/book_flip.8.ogg", "static")
end end
-- x1 y1 -- (x1 + w1) y1 -- x1 y1 -- (x1 + w1) y1
@ -59,6 +61,16 @@ local function transform(x, y, w, h, ox, oy,lox, loy, s)
return x, y, w, h, ox, oy, lox, loy return x, y, w, h, ox, oy, lox, loy
end end
function world:highlight()
self.data.temp_color = self.data.highlight_color
self.sfx_highlight:play()
end
function world:click()
self.data.func()
self.sfx_click:play()
end
function world:update(dt) function world:update(dt)
local xm, ym = love.mouse.getPosition() local xm, ym = love.mouse.getPosition()
local x, y, w, h, ox, oy, lox, loy, s = self.data.pos[1], self.data.pos[2], local x, y, w, h, ox, oy, lox, loy, s = self.data.pos[1], self.data.pos[2],
@ -68,7 +80,7 @@ function world:update(dt)
self.data.scale self.data.scale
x, y, w, h, ox, oy, lox, loy = transform(x, y, w, h, ox, oy, lox, loy, s) x, y, w, h, ox, oy, lox, loy = transform(x, y, w, h, ox, oy, lox, loy, s)
if (is_inside(x, y, w, h, xm, ym)) then if (is_inside(x, y, w, h, xm, ym)) then
self.data.temp_color = self.data.highlight_color self:highlight()
if (love.mouse.isDown(1)) then if (love.mouse.isDown(1)) then
if (self.mouse == "not click") then if (self.mouse == "not click") then
self.mouse = "click" self.mouse = "click"
@ -76,7 +88,7 @@ function world:update(dt)
else else
if (self.mouse == "click") then if (self.mouse == "click") then
self.mouse = "not click" self.mouse = "not click"
self.data.func() self:click()
end end
end end
else else

View File

@ -107,12 +107,35 @@ function world:load(data, entities_data)
self:setup() self:setup()
end end
local phases = {
intro = {
is_played = false,
source = love.audio.newSource("love_src/asset/audio/sfx/race/va/test1.mp3", "static"),
},
mid = {
is_played = false,
source = love.audio.newSource("love_src/asset/audio/sfx/race/va/Test2.mp3", "static"),
},
ed = {
is_played = false,
source = love.audio.newSource("love_src/asset/audio/sfx/race/va/Test3.mp3", "static")
}
}
local phase = "intro"
function world:update(dt) function world:update(dt)
for _, e in ipairs(self.entities) do for _, e in ipairs(self.entities) do
for t, c in pairs(e.components) do for t, c in pairs(e.components) do
c:update(dt) c:update(dt)
end end
end end
if (phases[phase]) then
if (not phases[phase].source:isPlaying() and not phases[phase].is_played) then
phases[phase].source:play()
phases[phase].is_played = true
end
end
end end
function world:draw() function world:draw()

View File

@ -227,10 +227,12 @@ local world_data = {
current = wm["main_menu"] current = wm["main_menu"]
local bgm = love.audio.newSource("love_src/asset/audio/bgm/Ensemble.mp3", "stream")
bgm:setLooping(true)
bgm:play()
function load_world(world_to_load) function load_world(world_to_load)
print(current)
current = world_to_load current = world_to_load
print(current)
local c_w = world_data[current] local c_w = world_data[current]
world[current] = c_w.world world[current] = c_w.world
world[current]:load(c_w.data, c_w.entities_data) world[current]:load(c_w.data, c_w.entities_data)