diff options
author | Aki <nthirtyone@gmail.com> | 2016-05-28 22:34:00 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2016-05-28 22:34:00 +0200 |
commit | 4f119e0e39a8055fd955d37224bda9c91f84e1a3 (patch) | |
tree | 858bde95b339ef4c1dbd3fbc4fd7eb20b21cc9ac /menu.lua | |
parent | 928440ab67f4c0536f98d40061b0096ad2833271 (diff) | |
download | roflnauts-4f119e0e39a8055fd955d37224bda9c91f84e1a3.zip roflnauts-4f119e0e39a8055fd955d37224bda9c91f84e1a3.tar.gz roflnauts-4f119e0e39a8055fd955d37224bda9c91f84e1a3.tar.bz2 |
Menu almost
Diffstat (limited to 'menu.lua')
-rw-r--r-- | menu.lua | 91 |
1 files changed, 90 insertions, 1 deletions
@@ -4,9 +4,98 @@ -- WHOLE CODE HAS FLAG OF "need a cleanup" +require "selector" + -- Metatable of `Menu` -Menu = {} +Menu = { + logo = nil, + selectors = nil, + selected = nil, + nauts = require "nautslist", + portrait_sprite = nil, + portrait_sheet = require "portraits", + scale = 4, + countdown = 3 +} -- Constructor of `Menu` function Menu:new () + -- Meta + local o = {} + setmetatable(o, self) + self.__index = self + -- initialize + o.logo = nil + o.selectors = {} + o.selected = {} + o.portrait_sprite = love.graphics.newImage("assets/portraits.png") + return o +end + +-- Naut selector +function Menu:newSelector() + table.insert(self.selectors,Selector:new(self)) +end + +-- +function Menu:draw() + for _,selector in pairs(self.selectors) do + selector:draw() + end + for _,selector in pairs(self.selected) do + selector:draw() + end + love.graphics.print(self.countdown,2,2,0,self.scale,self.scale) +end + +function Menu:update(dt) + local state = true + if #self.selected > 1 then + for _,selector in pairs(self.selected) do + state = state and selector.state + end + else + state = false + end + if state then + self.countdown = self.countdown - dt + else + self.countdown = 3 + end +end + +-- +function Menu:unselectSelector(selector) + local i = 0 + for _,v in pairs(self.selected) do + if v == selector then + i = _ + break + end + end + if i ~= 0 then + table.remove(self.selected, i) + table.insert(self.selectors, selector) + self:assignController(selector:getController()) + selector:clear() + end +end + +-- Controllers +function Menu:assignController(controller) + controller:setParent(self) +end + +function Menu:controllerPressed(control, controller) + local selector = self.selectors[1] + if selector ~= nil then + table.remove(self.selectors, 1) + table.insert(self.selected, selector) + selector:assignController(controller) + selector:controllerPressed(control) + end +end + +-- It just must be here +function Menu:controllerReleased(control, controller) end
\ No newline at end of file |