summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--main.lua22
-rw-r--r--menu.lua91
-rw-r--r--nautslist.lua31
-rw-r--r--selector.lua70
4 files changed, 207 insertions, 7 deletions
diff --git a/main.lua b/main.lua
index 05a21f4..575b7c8 100644
--- a/main.lua
+++ b/main.lua
@@ -3,7 +3,7 @@
require "world"
require "camera"
--- require "menu"
+require "menu"
require "controller"
-- Temporary debug
@@ -25,6 +25,17 @@ function love.load ()
-- ZU WARUDO!
w = World:new("default", "leon", "lonestar", third, fourth)
+ -- Menu bijaczes
+ -- m = Menu:new()
+ -- m:newSelector()
+ -- m:newSelector()
+ -- m:newSelector()
+ -- m:newSelector()
+ -- m.selectors[1]:setPosition(40+33*1,33)
+ -- m.selectors[2]:setPosition(40+33*2,33)
+ -- m.selectors[3]:setPosition(40+33*3,33)
+ -- m.selectors[4]:setPosition(40+33*4,33)
+
-- Controllers
Controllers = {}
table.insert(Controllers, Controller:new())
@@ -32,16 +43,15 @@ function love.load ()
w.Nauts[1]:assignController(Controllers[1])
w.Nauts[2]:assignController(Controllers[2])
- -- Menu bijaczes
- -- m = Menu:new()
- -- m:newSelector()
- -- m:newSelector()
- -- m.selectors[2]:setPosition(33,33)
+ -- Menu Controllers
+ -- m:assignController(Controllers[1])
+ -- m:assignController(Controllers[2])
end
-- Update
function love.update (dt)
w:update(dt)
+ -- m:update(dt)
end
-- KeyPressed
diff --git a/menu.lua b/menu.lua
index 9ba2df2..dcfd859 100644
--- a/menu.lua
+++ b/menu.lua
@@ -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
diff --git a/nautslist.lua b/nautslist.lua
new file mode 100644
index 0000000..cfccb21
--- /dev/null
+++ b/nautslist.lua
@@ -0,0 +1,31 @@
+-- List of characters with empty character included
+return {
+ "empty",
+ "frog",
+ "lonestar",
+ "leon",
+ "scoop",
+ "gnaw",
+ "raelynn",
+ "ayla",
+ "clunk",
+ "voltar",
+ "coco",
+ "skolldir",
+ "yuri",
+ "derpl",
+ "vinnie",
+ "genji",
+ "swiggins",
+ "rocco",
+ "ksenia",
+ "ted",
+ "penny",
+ "sentry",
+ "skree",
+ "nibbs",
+ "yoolip",
+ "chucho",
+ "lux",
+ "ix"
+} \ No newline at end of file
diff --git a/selector.lua b/selector.lua
new file mode 100644
index 0000000..8d1ef78
--- /dev/null
+++ b/selector.lua
@@ -0,0 +1,70 @@
+-- `Selector`
+-- Used in menu; selecting nauts?
+Selector = {
+ naut = 1,
+ x = 0,
+ y = 0,
+ parent = nil,
+ controller = nil,
+ state = false
+}
+function Selector:new(menu)
+ local o = {}
+ setmetatable(o, self)
+ self.__index = self
+ o.parent = menu
+ return o
+end
+function Selector:setPosition (x,y)
+ self.x = x
+ self.y = y
+end
+function Selector:getPosition ()
+ return self.x, self.y
+end
+function Selector:draw ()
+ local p = self.parent.portrait_sheet[self.parent.nauts[self.naut]]
+ local scale = self.parent.scale
+ if not self.state then
+ love.graphics.draw(self.parent.portrait_sprite, p.normal, self.x*scale, self.y*scale, 0, 1*scale, 1*scale)
+ else
+ love.graphics.draw(self.parent.portrait_sprite, p.active, self.x*scale, self.y*scale, 0, 1*scale, 1*scale)
+ end
+end
+function Selector:assignController(controller)
+ controller:setParent(self)
+ self.controller = controller
+end
+function Selector:getController()
+ if self.controller ~= nil then
+ return self.controller
+ end
+end
+function Selector:clear()
+ self.controller = nil
+ self.naut = 1
+ self.state = false
+end
+function Selector:controllerPressed(control, controller)
+ local n = #self.parent.nauts
+ if control == "left" and not self.state then
+ if self.naut == 1 then
+ self.naut = n
+ else
+ self.naut = self.naut - 1
+ end
+ elseif control == "right" and not self.state then
+ self.naut = (self.naut % n) + 1
+ elseif control == "attack" then
+ self.state = true
+ elseif control == "jump" then
+ if self.state == true then
+ self.state = false
+ else
+ self.parent:unselectSelector(self)
+ end
+ end
+end
+-- It just must be here
+function Selector:controllerReleased(control, controller)
+end \ No newline at end of file