From bf5f449516673d63e03b7a8859f419a9667ac295 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 5 Aug 2016 16:30:51 +0200 Subject: Main menu music --- assets/music/ROFLmenu.ogg | Bin 0 -> 1041812 bytes main.lua | 4 ++++ menu.lua | 3 +++ music.lua | 27 +++++++++++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 assets/music/ROFLmenu.ogg create mode 100644 music.lua diff --git a/assets/music/ROFLmenu.ogg b/assets/music/ROFLmenu.ogg new file mode 100644 index 0000000..07bcb89 Binary files /dev/null and b/assets/music/ROFLmenu.ogg differ diff --git a/main.lua b/main.lua index cb9b1f2..280f5d9 100644 --- a/main.lua +++ b/main.lua @@ -5,6 +5,9 @@ -- This is work for scene manager Scene = nil function changeScene(scene) + if Scene ~= nil then + Scene:delete() + end Scene = scene end @@ -36,6 +39,7 @@ require "world" require "camera" require "menu" require "controller" +require "music" -- Temporary debug debug = false diff --git a/menu.lua b/menu.lua index 96d9fca..52e2fdc 100644 --- a/menu.lua +++ b/menu.lua @@ -33,11 +33,14 @@ function Menu:new () for i=0,3 do o:newSelector() end + -- music + o.music = Music:new("ROFLmenu.ogg") return o end -- Destructor function Menu:delete() + self.music:delete() end -- Naut selector diff --git a/music.lua b/music.lua new file mode 100644 index 0000000..1ac26bb --- /dev/null +++ b/music.lua @@ -0,0 +1,27 @@ +-- `Music` +-- Simple music player object that plays and loops selected track in single Scene. + +-- WHOLE CODE HAS FLAG OF "need a cleanup" + +-- Metatable of `Music` +-- nils initialized in constructor +Music = { + track = nil, + source = nil +} +function Music:new(track) + -- Meta + local o = {} + setmetatable(o, self) + self.__index = self + -- Init + o.track = track + o.source = love.audio.newSource("assets/music/" .. o.track) + o.source:setLooping(true) + o.source:setVolume(.7) + o.source:play() + return o +end +function Music:delete() + self.source:stop() +end \ No newline at end of file -- cgit v1.1