minimal sound engine
This commit is contained in:
parent
ea83d2431a
commit
deb8199f9c
BIN
src/assets/sound/gebet.ogg
Normal file
BIN
src/assets/sound/gebet.ogg
Normal file
Binary file not shown.
@ -4,9 +4,10 @@ local HC = require 'engine/libs/hardoncollider'
|
|||||||
-- has to come before the sti initialization so I can add the collision tiles
|
-- has to come before the sti initialization so I can add the collision tiles
|
||||||
collider = HC(100)
|
collider = HC(100)
|
||||||
|
|
||||||
local sti = require "engine/libs/sti"
|
local sti = require 'engine/libs/sti'
|
||||||
local object = require "engine/object"
|
local object = require 'engine/object'
|
||||||
local ui = require "engine/ui"
|
local ui = require 'engine/ui'
|
||||||
|
local sound = require 'engine/sound'
|
||||||
local story = require 'story'
|
local story = require 'story'
|
||||||
|
|
||||||
Engine = class()
|
Engine = class()
|
||||||
@ -20,6 +21,10 @@ function Engine:__init()
|
|||||||
story:start(self)
|
story:start(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Engine:playSound(soundName, loop, finishedFunc)
|
||||||
|
return love.audio.play('assets/sound/' .. soundName .. '.ogg', 'stream', loop, finishedFunc)
|
||||||
|
end
|
||||||
|
|
||||||
function Engine:checkObjectAnimation(key)
|
function Engine:checkObjectAnimation(key)
|
||||||
for _, object in ipairs(self.objects) do
|
for _, object in ipairs(self.objects) do
|
||||||
if object.relevantKeys then
|
if object.relevantKeys then
|
||||||
@ -33,10 +38,12 @@ function Engine:checkObjectAnimation(key)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Engine:checkObjectKeys(dt)
|
function Engine:checkObjectKeys(dt)
|
||||||
if not ui.active then
|
|
||||||
for _, object in ipairs(self.objects) do
|
for _, object in ipairs(self.objects) do
|
||||||
object.controller.animation:update(dt)
|
object.controller.animation:update(dt)
|
||||||
|
end
|
||||||
|
|
||||||
|
if not ui.active then
|
||||||
|
for _, object in ipairs(self.objects) do
|
||||||
if object.relevantKeys then
|
if object.relevantKeys then
|
||||||
for _, relevantKey in ipairs(object.relevantKeys) do
|
for _, relevantKey in ipairs(object.relevantKeys) do
|
||||||
if love.keyboard.isDown(relevantKey) then
|
if love.keyboard.isDown(relevantKey) then
|
||||||
@ -58,6 +65,7 @@ function Engine:update(dt)
|
|||||||
self:checkObjectKeys(dt)
|
self:checkObjectKeys(dt)
|
||||||
collider:update(dt)
|
collider:update(dt)
|
||||||
self.map:update(dt)
|
self.map:update(dt)
|
||||||
|
love.audio.update()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Engine:draw()
|
function Engine:draw()
|
||||||
@ -143,3 +151,12 @@ function Engine:animate(objectName, animationName)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Engine:stopAnimate(objectName)
|
||||||
|
for _, object in ipairs(self.objects) do
|
||||||
|
if object.name == objectName then
|
||||||
|
object.controller:stopAnimation()
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
43
src/engine/sound.lua
Normal file
43
src/engine/sound.lua
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
--will hold the currently playing sources
|
||||||
|
local sources = {}
|
||||||
|
|
||||||
|
-- check for sources that finished playing and remove them
|
||||||
|
-- add to love.update
|
||||||
|
function love.audio.update()
|
||||||
|
local remove = {}
|
||||||
|
for _,s in pairs(sources) do
|
||||||
|
if s.audio:isStopped() then
|
||||||
|
if s.finishedFunc then s.finishedFunc() end
|
||||||
|
|
||||||
|
remove[#remove + 1] = s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for i,s in ipairs(remove) do
|
||||||
|
sources[s] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- overwrite love.audio.play to create and register source if needed
|
||||||
|
local play = love.audio.play
|
||||||
|
function love.audio.play(what, how, loop, finishedFunc)
|
||||||
|
local src = {}
|
||||||
|
if type(what) ~= "userdata" or not what:typeOf("Source") then
|
||||||
|
src.audio = love.audio.newSource(what, how)
|
||||||
|
src.finishedFunc = finishedFunc
|
||||||
|
src.audio:setLooping(loop or false)
|
||||||
|
end
|
||||||
|
|
||||||
|
play(src.audio)
|
||||||
|
sources[src] = src
|
||||||
|
|
||||||
|
return src
|
||||||
|
end
|
||||||
|
|
||||||
|
-- stops a source
|
||||||
|
local stop = love.audio.stop
|
||||||
|
function love.audio.stop(src)
|
||||||
|
if not src then return end
|
||||||
|
stop(src.audio)
|
||||||
|
sources[src] = nil
|
||||||
|
end
|
@ -2,8 +2,15 @@ local story = {}
|
|||||||
|
|
||||||
function story:start(engine)
|
function story:start(engine)
|
||||||
engine:loadLevel('01')
|
engine:loadLevel('01')
|
||||||
engine:showMessage('Du befindest dich auf einer sturmgebeutelten Insel. Wo ist denn nur die Milch?')
|
|
||||||
|
local stopRomata = function()
|
||||||
|
engine:stopAnimate('romata')
|
||||||
|
end
|
||||||
|
|
||||||
engine:animate('romata', 'play')
|
engine:animate('romata', 'play')
|
||||||
|
engine:playSound('gebet', false, stopRomata)
|
||||||
|
|
||||||
|
engine:showMessage('Du befindest dich auf einer sturmgebeutelten Insel. Wo ist denn nur die Milch?')
|
||||||
end
|
end
|
||||||
|
|
||||||
return story
|
return story
|
Loading…
Reference in New Issue
Block a user