summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--not/Menu.lua9
-rw-r--r--not/MusicPlayer.lua14
-rw-r--r--not/SceneManager.lua2
-rw-r--r--not/World.lua5
4 files changed, 19 insertions, 11 deletions
diff --git a/not/Menu.lua b/not/Menu.lua
index cd6d963..4dcff5e 100644
--- a/not/Menu.lua
+++ b/not/Menu.lua
@@ -38,8 +38,6 @@ Menu = {
Menu.__index = Menu
-require "not.MusicPlayer"
-
function Menu:new (name)
local o = setmetatable({}, self)
-- Load statically.
@@ -54,13 +52,12 @@ function Menu:new (name)
end
function Menu:init (name)
- self.music = MusicPlayer("menu.ogg")
+ musicPlayer:setTrack("menu.ogg")
+ musicPlayer:play()
self:open(name)
end
-function Menu:delete ()
- self.music:delete()
-end
+function Menu:delete () end
function Menu:open (name)
local name = name or "main"
diff --git a/not/MusicPlayer.lua b/not/MusicPlayer.lua
index d2a89c3..e838d96 100644
--- a/not/MusicPlayer.lua
+++ b/not/MusicPlayer.lua
@@ -6,12 +6,15 @@ MusicPlayer = Object:extends()
function MusicPlayer:new (trackName)
self.tracks = {}
- self:setTrack(trackName)
+ if trackName then
+ self:setTrack(trackName)
+ self:play()
+ end
end
function MusicPlayer:delete ()
self.tracks = nil
- self.source:stop()
+ self:stop()
end
function MusicPlayer:setTrack (trackName)
@@ -27,7 +30,14 @@ function MusicPlayer:setTrack (trackName)
self.source = source
self.tracks[trackName] = source
end
+end
+
+function MusicPlayer:play ()
self.source:play()
end
+function MusicPlayer:stop ()
+ self.source:stop()
+end
+
return MusicPlayer
diff --git a/not/SceneManager.lua b/not/SceneManager.lua
index 0a6cb4b..755548a 100644
--- a/not/SceneManager.lua
+++ b/not/SceneManager.lua
@@ -2,6 +2,8 @@
-- This is work for scene manager
-- TODO: Create SceneManager or similar class.
Scene = nil
+musicPlayer = require("not.MusicPlayer")()
+
function changeScene (scene)
if Scene ~= nil then
Scene:delete()
diff --git a/not/World.lua b/not/World.lua
index 112846a..ab94ff4 100644
--- a/not/World.lua
+++ b/not/World.lua
@@ -26,7 +26,6 @@ require "not.Cloud"
require "not.Effect"
require "not.Decoration"
require "not.Ray"
-require "not.MusicPlayer"
-- Constructor of `World` ZA WARUDO!
function World:new (map, nauts)
@@ -46,7 +45,8 @@ function World:new (map, nauts)
self:loadMap(map)
self:spawnNauts(nauts)
self.camera = Camera:new(self)
- self.music = MusicPlayer(self.map.theme)
+ musicPlayer:setTrack(self.map.theme)
+ musicPlayer:play()
end
-- The end of the world
@@ -57,7 +57,6 @@ function World:delete ()
for _,naut in pairs(self.Nauts) do
naut:delete()
end
- self.music:delete()
self.world:destroy()
end