summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-07-12 09:38:36 +0200
committerAki <nthirtyone@gmail.com>2017-07-12 09:38:36 +0200
commitd161510d2dc33046459e874e716c02c76d49f7d5 (patch)
tree5256abf758e0750aa2053e1ce4cc9492c4d3ca2f
parent094f9326d1e3ae6e451b21192b288220a8fab12e (diff)
downloadroflnauts-d161510d2dc33046459e874e716c02c76d49f7d5.zip
roflnauts-d161510d2dc33046459e874e716c02c76d49f7d5.tar.gz
roflnauts-d161510d2dc33046459e874e716c02c76d49f7d5.tar.bz2
Menu moved to new OOP model
-rw-r--r--main.lua2
-rw-r--r--not/Menu.lua86
-rw-r--r--not/World.lua2
3 files changed, 42 insertions, 48 deletions
diff --git a/main.lua b/main.lua
index 45d495b..74c3571 100644
--- a/main.lua
+++ b/main.lua
@@ -42,7 +42,7 @@ function love.load ()
love.graphics.setFont(Font)
Controller.load()
Settings.load()
- sceneManager:changeScene(Menu:new())
+ sceneManager:changeScene(Menu())
end
function love.draw ()
diff --git a/not/Menu.lua b/not/Menu.lua
index 4dcff5e..1688166 100644
--- a/not/Menu.lua
+++ b/not/Menu.lua
@@ -1,57 +1,49 @@
--- `Menu`
-- It creates single screen of a menu
-- I do know that model I used here and in `World` loading configuration files is not flawless but I did not want to rewrite `World`s one but wanted to keep things similar at least in project scope.
-Menu = {
- scale = getScale(),
- elements = --[[{not.Element}]]nil,
- active = 1,
- music = --[[not.Music]]nil,
- sprite = --[[love.graphics.newImage]]nil,
- background = --[[love.graphics.newImage]]nil,
- asteroids = --[[love.graphics.newImage]]nil,
- stars = --[[love.graphics.newImage]]nil,
- asteroids_bounce = 0,
- stars_frame = 1,
- stars_delay = 0.8,
- allowMove = true,
- quads = { -- TODO: Could be moved to config file or perhaps QuadManager to manage all quads for animations etc.
- button = {
- normal = love.graphics.newQuad(0, 0, 58,15, 80,130),
- active = love.graphics.newQuad(0, 0, 58,15, 80,130)
- },
- portrait = {
- normal = love.graphics.newQuad( 0, 15, 32,32, 80,130),
- active = love.graphics.newQuad(32, 15, 32,32, 80,130)
- },
- panorama = {
- normal = love.graphics.newQuad(0,47, 80,42, 80,130),
- active = love.graphics.newQuad(0,88, 80,42, 80,130)
- },
- arrow_l = love.graphics.newQuad(68, 0, 6, 6, 80,130),
- arrow_r = love.graphics.newQuad(74, 0, 6, 6, 80,130),
- stars = {
- love.graphics.newQuad( 0, 0, 320, 200, 640,200),
- love.graphics.newQuad(320, 0, 320, 200, 640,200)
- },
- }
-}
+Menu = require "not.Object":extends()
-Menu.__index = Menu
+Menu.scale = getScale()
+Menu.elements = --[[{not.Element}]]nil
+Menu.active = 1
+Menu.music = --[[not.Music]]nil
+Menu.sprite = --[[love.graphics.newImage]]nil
+Menu.background = --[[love.graphics.newImage]]nil
+Menu.asteroids = --[[love.graphics.newImage]]nil
+Menu.stars = --[[love.graphics.newImage]]nil
+Menu.asteroids_bounce = 0
+Menu.stars_frame = 1
+Menu.stars_delay = 0.8
+Menu.allowMove = true
+Menu.quads = { -- TODO: Could be moved to config file or perhaps QuadManager to manage all quads for animations etc.
+ button = {
+ normal = love.graphics.newQuad(0, 0, 58,15, 80,130),
+ active = love.graphics.newQuad(0, 0, 58,15, 80,130)
+ },
+ portrait = {
+ normal = love.graphics.newQuad( 0, 15, 32,32, 80,130),
+ active = love.graphics.newQuad(32, 15, 32,32, 80,130)
+ },
+ panorama = {
+ normal = love.graphics.newQuad(0,47, 80,42, 80,130),
+ active = love.graphics.newQuad(0,88, 80,42, 80,130)
+ },
+ arrow_l = love.graphics.newQuad(68, 0, 6, 6, 80,130),
+ arrow_r = love.graphics.newQuad(74, 0, 6, 6, 80,130),
+ stars = {
+ love.graphics.newQuad( 0, 0, 320, 200, 640,200),
+ love.graphics.newQuad(320, 0, 320, 200, 640,200)
+ },
+}
function Menu:new (name)
- local o = setmetatable({}, self)
-- Load statically.
- if self.sprite == nil then
- self.sprite = love.graphics.newImage("assets/menu.png")
- self.background = love.graphics.newImage("assets/backgrounds/menu.png")
- self.asteroids = love.graphics.newImage("assets/asteroids.png")
- self.stars = love.graphics.newImage("assets/stars.png")
+ if Menu.sprite == nil then
+ Menu.sprite = love.graphics.newImage("assets/menu.png")
+ Menu.background = love.graphics.newImage("assets/backgrounds/menu.png")
+ Menu.asteroids = love.graphics.newImage("assets/asteroids.png")
+ Menu.stars = love.graphics.newImage("assets/stars.png")
end
- o:init(name)
- return o
-end
-
-function Menu:init (name)
musicPlayer:setTrack("menu.ogg")
musicPlayer:play()
self:open(name)
@@ -139,3 +131,5 @@ function Menu:controlreleased (set, action, key)
element:controlreleased(set, action, key)
end
end
+
+return Menu
diff --git a/not/World.lua b/not/World.lua
index ab94ff4..be29557 100644
--- a/not/World.lua
+++ b/not/World.lua
@@ -195,7 +195,7 @@ function World:onNautKilled (naut)
self:createRay(naut)
local nauts = self:getNautsPlayable()
if self.lastNaut then
- changeScene(Menu:new())
+ changeScene(Menu())
elseif #nauts < 2 then
self.lastNaut = true
naut:playSound(5, true)