From 55183fc87f645a5a36a1d5a2be8c4052c9ef425f Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 20 Aug 2016 19:02:03 +0200 Subject: Cleanup --- main.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/main.lua b/main.lua index cb66aa0..8c6eb8e 100644 --- a/main.lua +++ b/main.lua @@ -44,7 +44,6 @@ require "music" debug = false -- LÖVE2D callbacks --- Load function love.load() -- Graphics love.graphics.setBackgroundColor(90, 90, 90) @@ -59,11 +58,9 @@ function love.load() -- Scene Scene = Menu:new() end --- Update function love.update(dt) Scene:update(dt) end --- Draw function love.draw() Scene:draw() if debug then -- cgit v1.1 From bc865e29d15d15ba31e4d43c6272ad31a4e28244 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 20 Aug 2016 19:02:17 +0200 Subject: Start for new menu --- menu.lua | 221 ++++++++++----------------------------------------------------- 1 file changed, 35 insertions(+), 186 deletions(-) diff --git a/menu.lua b/menu.lua index e41e7a1..34cb539 100644 --- a/menu.lua +++ b/menu.lua @@ -1,215 +1,64 @@ --- `Menu` --- It is one of the last things I will need to mess around with. I'm happy and surprised everything works so far. --- For sure I have learnt a lot about lua during this journey. Still a lot ahead. I will continue writing in the same style though, to not make it even worse. - --- WHOLE CODE HAS FLAG OF "need a cleanup" +-- `Menu` (Scene) +-- It creates single screen of a menu require "selector" +require "button" --- Metatable of `Menu` +-- Here it begins Menu = { - -- move selectors to one table; make functions to retrieve selectors w or w/o controller - selectors = nil, - nauts = require "nautslist", - portrait_sprite = nil, - portrait_sheet = require "portraits", scale = getScale(), - countdown = 10, - maplist = require "maplist", - map = 1, - header_move = 0 + elements, --table + active = 1 } - --- Constructor of `Menu` -function Menu:new() - -- Meta +function Menu:new(name) local o = {} setmetatable(o, self) self.__index = self - -- initialize - o.selectors = {} - o.portrait_sprite = love.graphics.newImage("assets/portraits.png") - -- selectors - for i=0,3 do - o:newSelector() - end - -- music - o.music = Music:new("ROFLmenu.ogg") + o.elements = {} + o:load(name) return o end +function Menu:delete() end --- Destructor -function Menu:delete() - self.music:delete() -end - --- Naut selector -function Menu:newSelector() - local selector = Selector:new(self) - local w, h = love.graphics.getWidth()/self.scale, love.graphics.getHeight()/self.scale - local n = #self.selectors - 1 - table.insert(self.selectors, selector) - local x = (w-76)/2+n*44 - local y = h/2-8 - selector:setPosition(x, y) -end - --- Selectors tables getters --- all of them -function Menu:getSelectors() - return self.selectors -end --- with control set -function Menu:getSelectorsActive() - local t = {} - for _,selector in pairs(self.selectors) do - if selector:getState() ~= 0 then - table.insert(t, selector) - end - end - return t -end --- without control set -function Menu:getSelectorsInactive() - local t = {} - for _,selector in pairs(self.selectors) do - if selector:getState() == 0 then - table.insert(t, selector) - end - end - return t -end --- with locked character -function Menu:getSelectorsLocked() - local t = {} - for _,selector in pairs(self.selectors) do - if selector:getState() == 2 then - table.insert(t, selector) - end - end - return t -end - --- Tests if Control set is assigned to any selector (1.) and if it is locked (2.) -function Menu:isSetUsed(set) - for k,selector in pairs(self:getSelectorsActive()) do - if selector:getControlSet() == set then - if selector:getState() == 2 then - return true, true - else - return true, false - end - end - end - return false, false +-- Load menu from file +function Menu:load(name) + local name = "config/" .. (name or "menumain") .. ".lua" + print(name) + local menu = love.filesystem.load(name) + self.elements = menu() end --- Header get bounce move -function Menu:getBounce(f) - local f = f or 1 - return math.sin(self.header_move*f*math.pi) -end - --- Speed up countdown -function Menu:countdownJump() - if self.countdown ~= Menu.countdown then -- Menu.countdown is initial - self.countdown = self.countdown - 1 - end -end - --- Get table of nauts currently selected by locked selectors -function Menu:getNauts() - local nauts = {} - for _,selector in pairs(self:getSelectorsLocked()) do - table.insert(nauts, {selector:getSelectionName(), selector:getControlSet()}) - end - return nauts -end - --- WARUDO -function Menu:startGame() - local world = World:new(self.maplist[self.map], self:getNauts()) - changeScene(world) +-- Creators +function Menu:newButton() + local button = Button:new() end -- LÖVE2D callbacks --- Update -function Menu:update(dt) - if #self:getSelectorsLocked() > 1 then - self.countdown = self.countdown - dt - else - self.countdown = Menu.countdown -- Menu.countdown is initial - end - if self.countdown < 0 then - self:startGame() - end - -- Bounce header - self.header_move = self.header_move + dt - if self.header_move > 2 then - self.header_move = self.header_move - 2 - end -end --- Draw +function Menu:update(dt) end function Menu:draw() - -- locals - local w, h = love.graphics.getWidth()/self.scale, love.graphics.getHeight()/self.scale local scale = self.scale - -- map selection love.graphics.setFont(Font) - love.graphics.printf("Map: " .. self.maplist[self.map], (w/2)*scale, (h/2-22)*scale, 150, "center", 0, scale, scale, 75, 4) - -- character selection - for _,selector in pairs(self:getSelectors()) do - selector:draw() - end - -- header - love.graphics.setFont(Bold) - local angle = self:getBounce(2) - local dy = self:getBounce()*4 - love.graphics.printf("ROFLNAUTS2",(w/2)*scale,(32+dy)*scale,336,"center",(angle*5)*math.pi/180,scale,scale,168,12) - -- footer - love.graphics.setFont(Font) - love.graphics.printf("Use W,S,A,D,G,H or Arrows,Enter,Rshift or Gamepad\n\nA game by the Awesomenauts community\nSeltzy, PlasmaWisp, ParaDoX, MilkingChicken, Burningdillo, Bronkey, Aki, 04font\nBased on a game by Jan Willem Nijman, Paul Veer and Bits_Beats XOXO", (w/2)*scale, (h-42)*scale, 336, "center", 0, scale, scale, 168, 4) - -- countdown - local countdown = math.floor(self.countdown) - if self.countdown < Menu.countdown then -- Menu.countdown is initial - love.graphics.setFont(Bold) - love.graphics.print(countdown,(w/2-6.5)*self.scale,(h/2+30)*self.scale,0,self.scale,self.scale) + for i,v in ipairs(self.elements) do + if self.active == i then + love.graphics.setColor(255, 128, 0, 255) + else + love.graphics.setColor(255, 255, 255, 255) + end + love.graphics.print(v, 10, (80-5*#self.elements+10*i)*scale, 0, scale, scale) end end -- Controller callbacks function Menu:controlpressed(set, action, key) - local used, locked = self:isSetUsed(set) - -- Pass to active selectors - for k,selector in pairs(self:getSelectorsActive()) do - selector:controlpressed(set, action, key) - end - if not used then - if action == "attack" then - self:getSelectorsInactive()[1]:assignControlSet(set) - end - -- map selection chaos! - if action == "left" then - if self.map ~= 1 then - self.map = self.map - 1 - else - self.map = #self.maplist - end - end - if action == "right" then - if self.map ~= #self.maplist then - self.map = self.map + 1 - else - self.map = 1 - end - end + if action == "down" then + self.active = (self.active%#self.elements)+1 end - -- speed up the countdown - if action ~= "jump" then - if set == nil or locked then - self:countdownJump() -- that's funny isn't it? if not jump then jump + if action == "up" then + if self.active == 1 then + self.active = #self.elements + else + self.active = self.active - 1 end end end -function Menu:controlreleased(set, action, key) -end \ No newline at end of file +function Menu:controlreleased(set, action, key) end \ No newline at end of file -- cgit v1.1 From 43fa5953e4c9f226c2579097b3f42bd97bc587c4 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 20 Aug 2016 19:02:38 +0200 Subject: Config files directory; soon to be moved --- config/menumain.lua | 1 + 1 file changed, 1 insertion(+) create mode 100644 config/menumain.lua diff --git a/config/menumain.lua b/config/menumain.lua new file mode 100644 index 0000000..a4374ad --- /dev/null +++ b/config/menumain.lua @@ -0,0 +1 @@ +return {"Start", "Join", "Settings", "Credits", "Exit"} \ No newline at end of file -- cgit v1.1 From 6e9aa28e70ec842db643a06609454fff54b5d86a Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 22 Aug 2016 02:24:32 +0200 Subject: Werking! --- button.lua | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ config/menumain.lua | 29 +++++++++++++++++++++++++++- config/menustart.lua | 11 +++++++++++ menu.lua | 25 +++++++++++------------- 4 files changed, 104 insertions(+), 15 deletions(-) create mode 100644 button.lua create mode 100644 config/menustart.lua diff --git a/button.lua b/button.lua new file mode 100644 index 0000000..925baf3 --- /dev/null +++ b/button.lua @@ -0,0 +1,54 @@ +-- `Button` +-- Button used in `Menu` + +Button = { + text = "button", + focused = false, + x = 0, + y = 0 +} + +function Button:new(text) + local o = {} + setmetatable(o, self) + self.__index = self + o.text = text or self.text + return o +end +function Button:setPosition(x, y) + self.x = x or 0 + self.y = y or 0 + return self +end +function Button:getPosition() return self.x,self.y end +function Button:focus() + self.focused = true +end +function Button:blur() + self.focused = false +end +function Button:active() end +function Button:set(name, func) + if type(name) == "string" and type(func) == "function" then + self[name] = func + end + return self +end +function Button:draw(scale) + local x,y = self:getPosition() + if self.focused then + love.graphics.setColor(255, 128, 0, 255) + else + love.graphics.setColor(255, 255, 255, 255) + end + love.graphics.print(self.text, x*scale, y*scale, 0, scale, scale) +end +function Button:update(dt) end +function Button:controlpressed(set, action, key) + if action == "attack" and self.focused then + self:active() + end +end +function Button:controlreleased(set, action, key) end + +return Button \ No newline at end of file diff --git a/config/menumain.lua b/config/menumain.lua index a4374ad..7c8ddf9 100644 --- a/config/menumain.lua +++ b/config/menumain.lua @@ -1 +1,28 @@ -return {"Start", "Join", "Settings", "Credits", "Exit"} \ No newline at end of file +local button = require "button" + +return { + button + :new("start") + :setPosition(10,40) + :set("active", function () + changeScene(Menu:new("menustart")) + end) + , + button + :new("join") + :setPosition(10,50) + , + button + :new("settings") + :setPosition(10,60) + , + button + :new("credits") + :setPosition(10,70) + , + button + :new("exit") + :setPosition(10,80) + :set("active", love.event.quit) + , +} \ No newline at end of file diff --git a/config/menustart.lua b/config/menustart.lua new file mode 100644 index 0000000..03ca2f2 --- /dev/null +++ b/config/menustart.lua @@ -0,0 +1,11 @@ +local button = require "button" + +return { + button + :new("WORKED") + :setPosition(10,40) + :set("active", function () + changeScene(Menu:new("menumain")) + end) + , +} \ No newline at end of file diff --git a/menu.lua b/menu.lua index 34cb539..87369da 100644 --- a/menu.lua +++ b/menu.lua @@ -1,8 +1,8 @@ -- `Menu` (Scene) -- 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. require "selector" -require "button" -- Here it begins Menu = { @@ -23,14 +23,9 @@ function Menu:delete() end -- Load menu from file function Menu:load(name) local name = "config/" .. (name or "menumain") .. ".lua" - print(name) local menu = love.filesystem.load(name) self.elements = menu() -end - --- Creators -function Menu:newButton() - local button = Button:new() + self.elements[self.active]:focus() end -- LÖVE2D callbacks @@ -38,27 +33,29 @@ function Menu:update(dt) end function Menu:draw() local scale = self.scale love.graphics.setFont(Font) - for i,v in ipairs(self.elements) do - if self.active == i then - love.graphics.setColor(255, 128, 0, 255) - else - love.graphics.setColor(255, 255, 255, 255) - end - love.graphics.print(v, 10, (80-5*#self.elements+10*i)*scale, 0, scale, scale) + for _,element in pairs(self.elements) do + element:draw(scale) end end -- Controller callbacks function Menu:controlpressed(set, action, key) if action == "down" then + self.elements[self.active]:blur() self.active = (self.active%#self.elements)+1 + self.elements[self.active]:focus() end if action == "up" then + self.elements[self.active]:blur() if self.active == 1 then self.active = #self.elements else self.active = self.active - 1 end + self.elements[self.active]:focus() + end + for _,element in pairs(self.elements) do + element:controlpressed(set, action, key) end end function Menu:controlreleased(set, action, key) end \ No newline at end of file -- cgit v1.1 From e57a5b0b77c1ba3a2f05371c551d0e61fc9ce709 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 22 Aug 2016 17:10:20 +0200 Subject: Graphics, animation, general improvements --- assets/menu.png | Bin 0 -> 279 bytes button.lua | 34 ++++++++++++++++++++++++---------- config/menumain.lua | 46 +++++++++++++++++++++++++++++++--------------- config/menustart.lua | 6 ++++-- menu.lua | 36 ++++++++++++++++++++++++------------ 5 files changed, 83 insertions(+), 39 deletions(-) create mode 100644 assets/menu.png diff --git a/assets/menu.png b/assets/menu.png new file mode 100644 index 0000000..ec5a398 Binary files /dev/null and b/assets/menu.png differ diff --git a/button.lua b/button.lua index 925baf3..fc4ca8b 100644 --- a/button.lua +++ b/button.lua @@ -2,26 +2,37 @@ -- Button used in `Menu` Button = { - text = "button", + text = "", focused = false, x = 0, - y = 0 + y = 0, + sprite, + quad = love.graphics.newQuad(0, 0, 58,15, 68,15), + arrow_l = love.graphics.newQuad(58, 0, 5, 5, 68,15), + arrow_r = love.graphics.newQuad(63, 0, 5, 5, 68,15), + delay = 0, + parent } -function Button:new(text) +function Button:new(parent) local o = {} setmetatable(o, self) self.__index = self - o.text = text or self.text + o.parent = parent + self.sprite = love.graphics.newImage("assets/menu.png") return o end +function Button:setText(text) + self.text = text or "" + return self +end function Button:setPosition(x, y) self.x = x or 0 self.y = y or 0 return self end function Button:getPosition() return self.x,self.y end -function Button:focus() +function Button:focus(next) self.focused = true end function Button:blur() @@ -36,14 +47,17 @@ function Button:set(name, func) end function Button:draw(scale) local x,y = self:getPosition() + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(self.sprite, self.quad, x*scale, y*scale, 0, scale, scale) if self.focused then - love.graphics.setColor(255, 128, 0, 255) - else - love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(self.sprite, self.arrow_l, (x+54+math.floor(self.delay))*scale, (y+5)*scale, 0, scale, scale) + love.graphics.draw(self.sprite, self.arrow_r, (x-1-math.floor(self.delay))*scale, (y+5)*scale, 0, scale, scale) end - love.graphics.print(self.text, x*scale, y*scale, 0, scale, scale) + love.graphics.printf(string.upper(self.text), (x+2)*scale, (y+4)*scale, 54, "center", 0, scale, scale) +end +function Button:update(dt) + self.delay = (self.delay + dt)%2 end -function Button:update(dt) end function Button:controlpressed(set, action, key) if action == "attack" and self.focused then self:active() diff --git a/config/menumain.lua b/config/menumain.lua index 7c8ddf9..543a858 100644 --- a/config/menumain.lua +++ b/config/menumain.lua @@ -1,28 +1,44 @@ +local menu = ... + local button = require "button" +local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() +local button_x = width/2-29 + return { - button - :new("start") - :setPosition(10,40) + button:new(menu) + :setText("start") + :setPosition(button_x,60) :set("active", function () changeScene(Menu:new("menustart")) end) , - button - :new("join") - :setPosition(10,50) + button:new(menu) + :setText("join") + :setPosition(button_x,76) , - button - :new("settings") - :setPosition(10,60) + button:new(menu) + :setText("settings") + :setPosition(button_x,92) , - button - :new("credits") - :setPosition(10,70) + button:new(menu) + :setText("credits") + :setPosition(button_x,108) , - button - :new("exit") - :setPosition(10,80) + button:new(menu) + :setText("exit") + :setPosition(button_x,124) :set("active", love.event.quit) , + button:new(menu) + :setText("NEVER") + :setPosition(button_x,140) + :set("focus", function (self, next) + if next then + self.parent:next() + else + self.parent:previous() + end + end) + , } \ No newline at end of file diff --git a/config/menustart.lua b/config/menustart.lua index 03ca2f2..46015a9 100644 --- a/config/menustart.lua +++ b/config/menustart.lua @@ -1,8 +1,10 @@ +local menu = ... + local button = require "button" return { - button - :new("WORKED") + button:new(menu) + :setText("Go back") :setPosition(10,40) :set("active", function () changeScene(Menu:new("menumain")) diff --git a/menu.lua b/menu.lua index 87369da..9c7481b 100644 --- a/menu.lua +++ b/menu.lua @@ -24,12 +24,32 @@ function Menu:delete() end function Menu:load(name) local name = "config/" .. (name or "menumain") .. ".lua" local menu = love.filesystem.load(name) - self.elements = menu() + self.elements = menu(self) + self.elements[self.active]:focus() +end + +-- Cycle elements +function Menu:next() + self.elements[self.active]:blur() + self.active = (self.active%#self.elements)+1 + self.elements[self.active]:focus(true) +end +function Menu:previous() + self.elements[self.active]:blur() + if self.active == 1 then + self.active = #self.elements + else + self.active = self.active - 1 + end self.elements[self.active]:focus() end -- LÖVE2D callbacks -function Menu:update(dt) end +function Menu:update(dt) + for _,element in pairs(self.elements) do + element:update(dt) + end +end function Menu:draw() local scale = self.scale love.graphics.setFont(Font) @@ -41,18 +61,10 @@ end -- Controller callbacks function Menu:controlpressed(set, action, key) if action == "down" then - self.elements[self.active]:blur() - self.active = (self.active%#self.elements)+1 - self.elements[self.active]:focus() + self:next() end if action == "up" then - self.elements[self.active]:blur() - if self.active == 1 then - self.active = #self.elements - else - self.active = self.active - 1 - end - self.elements[self.active]:focus() + self:previous() end for _,element in pairs(self.elements) do element:controlpressed(set, action, key) -- cgit v1.1 From dd32c9c620918a3b0da59e42ff343cdd78a12a39 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 22 Aug 2016 17:22:49 +0200 Subject: added music --- assets/music/ROFLmenu.ogg | Bin 1041812 -> 0 bytes assets/music/menu.ogg | Bin 0 -> 1041812 bytes menu.lua | 5 ++++- 3 files changed, 4 insertions(+), 1 deletion(-) delete mode 100644 assets/music/ROFLmenu.ogg create mode 100644 assets/music/menu.ogg diff --git a/assets/music/ROFLmenu.ogg b/assets/music/ROFLmenu.ogg deleted file mode 100644 index 07bcb89..0000000 Binary files a/assets/music/ROFLmenu.ogg and /dev/null differ diff --git a/assets/music/menu.ogg b/assets/music/menu.ogg new file mode 100644 index 0000000..07bcb89 Binary files /dev/null and b/assets/music/menu.ogg differ diff --git a/menu.lua b/menu.lua index 9c7481b..49c067d 100644 --- a/menu.lua +++ b/menu.lua @@ -3,12 +3,14 @@ -- 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. require "selector" +require "music" -- Here it begins Menu = { scale = getScale(), elements, --table - active = 1 + active = 1, + music } function Menu:new(name) local o = {} @@ -16,6 +18,7 @@ function Menu:new(name) self.__index = self o.elements = {} o:load(name) + o.music = Music:new("menu.ogg") return o end function Menu:delete() end -- cgit v1.1 From 3aeabc496465cbd2569d9b0f5687242f374b4375 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 22 Aug 2016 17:23:18 +0200 Subject: change elements not menu object --- config/menumain.lua | 4 ++-- config/menustart.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/menumain.lua b/config/menumain.lua index 543a858..def1ab7 100644 --- a/config/menumain.lua +++ b/config/menumain.lua @@ -9,8 +9,8 @@ return { button:new(menu) :setText("start") :setPosition(button_x,60) - :set("active", function () - changeScene(Menu:new("menustart")) + :set("active", function (self) + self.parent:load("menustart") end) , button:new(menu) diff --git a/config/menustart.lua b/config/menustart.lua index 46015a9..2472df5 100644 --- a/config/menustart.lua +++ b/config/menustart.lua @@ -6,8 +6,8 @@ return { button:new(menu) :setText("Go back") :setPosition(10,40) - :set("active", function () - changeScene(Menu:new("menumain")) + :set("active", function (self) + self.parent:load("menumain") end) , } \ No newline at end of file -- cgit v1.1 From 402e19b8bf19fb24af0fdc5b77f44088f48814ed Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 22 Aug 2016 17:24:07 +0200 Subject: initial frame delay --- button.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/button.lua b/button.lua index fc4ca8b..7262813 100644 --- a/button.lua +++ b/button.lua @@ -10,7 +10,7 @@ Button = { quad = love.graphics.newQuad(0, 0, 58,15, 68,15), arrow_l = love.graphics.newQuad(58, 0, 5, 5, 68,15), arrow_r = love.graphics.newQuad(63, 0, 5, 5, 68,15), - delay = 0, + delay = 2, parent } @@ -56,7 +56,7 @@ function Button:draw(scale) love.graphics.printf(string.upper(self.text), (x+2)*scale, (y+4)*scale, 54, "center", 0, scale, scale) end function Button:update(dt) - self.delay = (self.delay + dt)%2 + self.delay = (self.delay + dt)%Button.delay -- Button.delay is initial end function Button:controlpressed(set, action, key) if action == "attack" and self.focused then -- cgit v1.1 From 4bcaf1770c0aa693e24359ee52f7552f301917d3 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 22 Aug 2016 18:17:08 +0200 Subject: Faster --- button.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/button.lua b/button.lua index 7262813..f221cda 100644 --- a/button.lua +++ b/button.lua @@ -56,7 +56,10 @@ function Button:draw(scale) love.graphics.printf(string.upper(self.text), (x+2)*scale, (y+4)*scale, 54, "center", 0, scale, scale) end function Button:update(dt) - self.delay = (self.delay + dt)%Button.delay -- Button.delay is initial + self.delay = self.delay + dt + if self.delay < Button.delay then -- Button.delay is initial + self.delay = self.delay - Button.delay + end end function Button:controlpressed(set, action, key) if action == "attack" and self.focused then -- cgit v1.1 From 7d9d6a04c0bf916da50b5ab6dbafcee4a492398f Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 22 Aug 2016 18:17:47 +0200 Subject: it even works now --- button.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/button.lua b/button.lua index f221cda..de9ef56 100644 --- a/button.lua +++ b/button.lua @@ -57,7 +57,7 @@ function Button:draw(scale) end function Button:update(dt) self.delay = self.delay + dt - if self.delay < Button.delay then -- Button.delay is initial + if self.delay > Button.delay then -- Button.delay is initial self.delay = self.delay - Button.delay end end -- cgit v1.1 From 213c783bdde0fe5bf9709e19168a8e5049c7b13a Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 22 Aug 2016 18:27:14 +0200 Subject: game title --- config/menumain.lua | 34 ++++++++++++----------------- header.lua | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 20 deletions(-) create mode 100644 header.lua diff --git a/config/menumain.lua b/config/menumain.lua index def1ab7..629284c 100644 --- a/config/menumain.lua +++ b/config/menumain.lua @@ -1,44 +1,38 @@ local menu = ... local button = require "button" +local header = require "header" local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() local button_x = width/2-29 return { button:new(menu) - :setText("start") - :setPosition(button_x,60) + :setText("Start") + :setPosition(button_x, 80) :set("active", function (self) self.parent:load("menustart") end) , button:new(menu) - :setText("join") - :setPosition(button_x,76) + :setText("Join") + :setPosition(button_x, 96) , button:new(menu) - :setText("settings") - :setPosition(button_x,92) + :setText("Settings") + :setPosition(button_x, 112) , button:new(menu) - :setText("credits") - :setPosition(button_x,108) + :setText("Credits") + :setPosition(button_x, 128) , button:new(menu) - :setText("exit") - :setPosition(button_x,124) + :setText("Exit") + :setPosition(button_x, 144) :set("active", love.event.quit) , - button:new(menu) - :setText("NEVER") - :setPosition(button_x,140) - :set("focus", function (self, next) - if next then - self.parent:next() - else - self.parent:previous() - end - end) + header:new(menu) + :setText("Roflnauts") + :setPosition(width/2,40) , } \ No newline at end of file diff --git a/header.lua b/header.lua new file mode 100644 index 0000000..d538ab3 --- /dev/null +++ b/header.lua @@ -0,0 +1,61 @@ +-- `Header` +-- It dances! + +Header = { + x = 0, + y = 0, + text = "", + parent, + bounce = 2, +} +function Header:new(parent) + local o = {} + setmetatable(o, self) + self.__index = self + o.parent = parent + return o +end +function Header:setText(text) + self.text = text or "" + return self +end +function Header:setPosition(x, y) + self.x = x or 0 + self.y = y or 0 + return self +end +function Header:getBounce(f) + local f = f or 1 + return math.sin(self.bounce*f*math.pi) +end +function Header:getPosition() return self.x,self.y end -- gives x,y of Element +function Header:focus(next) + if next and self.parent then + self.parent:next() + else + self.parent:previous() + end +end +function Header:blur() end -- Called when Element loses focus + +-- LÖVE2D callbacks +function Header:draw(scale) + local angle = self:getBounce(2) + local dy = self:getBounce()*4 + local x,y = self:getPosition() + love.graphics.setColor(255,255,255,255) + love.graphics.setFont(Bold) + love.graphics.printf(string.upper(self.text),x*scale,(y+dy)*scale,400,"center",(angle*5)*math.pi/180,scale,scale,200,12) +end +function Header:update(dt) + self.bounce = self.bounce + dt*0.7 + if self.bounce > Header.bounce then -- Header.bounce is initial + self.bounce = self.bounce - Header.bounce + end +end + +-- Controller callbacks +function Header:controlpressed(set, action, key) end +function Header:controlreleased(set, action, key) end + +return Header \ No newline at end of file -- cgit v1.1 From 3279bd5a968111260eb3f488976a1024958dc283 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 22 Aug 2016 18:27:26 +0200 Subject: case --- button.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/button.lua b/button.lua index de9ef56..9c33885 100644 --- a/button.lua +++ b/button.lua @@ -53,7 +53,7 @@ function Button:draw(scale) love.graphics.draw(self.sprite, self.arrow_l, (x+54+math.floor(self.delay))*scale, (y+5)*scale, 0, scale, scale) love.graphics.draw(self.sprite, self.arrow_r, (x-1-math.floor(self.delay))*scale, (y+5)*scale, 0, scale, scale) end - love.graphics.printf(string.upper(self.text), (x+2)*scale, (y+4)*scale, 54, "center", 0, scale, scale) + love.graphics.printf(self.text, (x+2)*scale, (y+4)*scale, 54, "center", 0, scale, scale) end function Button:update(dt) self.delay = self.delay + dt -- cgit v1.1 From 63d90193f50f5fec561f725d8bda1fcb7ad6c3b8 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 23 Aug 2016 18:15:29 +0200 Subject: just in case --- button.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/button.lua b/button.lua index 9c33885..d7caf74 100644 --- a/button.lua +++ b/button.lua @@ -53,6 +53,7 @@ function Button:draw(scale) love.graphics.draw(self.sprite, self.arrow_l, (x+54+math.floor(self.delay))*scale, (y+5)*scale, 0, scale, scale) love.graphics.draw(self.sprite, self.arrow_r, (x-1-math.floor(self.delay))*scale, (y+5)*scale, 0, scale, scale) end + love.graphics.setFont(Font) love.graphics.printf(self.text, (x+2)*scale, (y+4)*scale, 54, "center", 0, scale, scale) end function Button:update(dt) -- cgit v1.1 From d41d75e723cfd7d49456da1e27d98f0c806afaca Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 23 Aug 2016 18:15:55 +0200 Subject: 2 --- config/menumain.lua | 12 ++++++++++++ config/menustart.lua | 5 ++++- element.lua | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 element.lua diff --git a/config/menumain.lua b/config/menumain.lua index 629284c..24f66ef 100644 --- a/config/menumain.lua +++ b/config/menumain.lua @@ -2,6 +2,7 @@ local menu = ... local button = require "button" local header = require "header" +local element = require "element" local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() local button_x = width/2-29 @@ -31,6 +32,17 @@ return { :setPosition(button_x, 144) :set("active", love.event.quit) , + element:new(menu) + :setPosition(width/2, 15) + :set("sprite", love.graphics.newImage("assets/two.png")) + :set("draw", function (self, scale) + local x,y = self:getPosition() + love.graphics.setColor(255, 255, 255, 255) + love.graphics.setFont(Bold) + love.graphics.print("1", (x-17)*scale, y*scale, 0, scale*2, scale*2, 12) + love.graphics.print("1", (x+13)*scale, y*scale, 0, scale*2, scale*2, 12) + end) + , header:new(menu) :setText("Roflnauts") :setPosition(width/2,40) diff --git a/config/menustart.lua b/config/menustart.lua index 2472df5..1830f0d 100644 --- a/config/menustart.lua +++ b/config/menustart.lua @@ -1,11 +1,14 @@ local menu = ... local button = require "button" +local selector = require "selector" + +local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() return { button:new(menu) :setText("Go back") - :setPosition(10,40) + :setPosition(10,height-25) :set("active", function (self) self.parent:load("menumain") end) diff --git a/element.lua b/element.lua new file mode 100644 index 0000000..bc8bc6d --- /dev/null +++ b/element.lua @@ -0,0 +1,46 @@ +-- `Element` +-- Empty element for `Menu` creation. Can be anything. +Element = { + x = 0, + y = 0, + parent +} +function Element:new(parent) + local o = {} + setmetatable(o, self) + self.__index = self + o.parent = parent + return o +end +function Element:delete() end -- deletes Element +function Element:getPosition() return self.x, self.y end -- gives x,y of Element +function Element:setPosition(x,y) + self.x, self.y = x, y + return self +end +function Element:set(name, func) + if type(name) == "string" and func ~= nil then + self[name] = func + end + return self +end + +-- Menu callbacks +function Header:focus(next) -- Called when Element gains focus + if next and self.parent then + self.parent:next() + else + self.parent:previous() + end +end +function Element:blur() end -- Called when Element loses focus + +-- LÖVE2D callbacks +function Element:draw(scale) end +function Element:update(dt) end + +-- Controller callbacks +function Element:controlpressed(set, action, key) end +function Element:controlreleased(set, action, key) end + +return Element \ No newline at end of file -- cgit v1.1 From f6c593d02271bbbea839ac9c0b0ae5543b29dfab Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 23 Aug 2016 18:16:06 +0200 Subject: cleanup --- menu.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/menu.lua b/menu.lua index 49c067d..3ef477d 100644 --- a/menu.lua +++ b/menu.lua @@ -2,7 +2,6 @@ -- 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. -require "selector" require "music" -- Here it begins -- cgit v1.1 From 6bd45fd9a32439b50b114c39eee569a58d354b73 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 23 Aug 2016 18:21:12 +0200 Subject: Obsolete; bug --- config/menumain.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/config/menumain.lua b/config/menumain.lua index 24f66ef..f442c8d 100644 --- a/config/menumain.lua +++ b/config/menumain.lua @@ -34,7 +34,6 @@ return { , element:new(menu) :setPosition(width/2, 15) - :set("sprite", love.graphics.newImage("assets/two.png")) :set("draw", function (self, scale) local x,y = self:getPosition() love.graphics.setColor(255, 255, 255, 255) -- cgit v1.1 From 33386113c6bade59314b557a051b7206521e4cf0 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 23 Aug 2016 19:09:36 +0200 Subject: Yes, I copied it --- element.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/element.lua b/element.lua index bc8bc6d..5ca013b 100644 --- a/element.lua +++ b/element.lua @@ -26,7 +26,7 @@ function Element:set(name, func) end -- Menu callbacks -function Header:focus(next) -- Called when Element gains focus +function Element:focus(next) -- Called when Element gains focus if next and self.parent then self.parent:next() else -- cgit v1.1 From 9b8f5e3d356be281d8ef25227b087bb99b07b58d Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 23 Aug 2016 19:24:06 +0200 Subject: start > select --- config/menumain.lua | 2 +- config/menuselect.lua | 16 ++++++++++++++++ config/menustart.lua | 16 ---------------- 3 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 config/menuselect.lua delete mode 100644 config/menustart.lua diff --git a/config/menumain.lua b/config/menumain.lua index f442c8d..2d92817 100644 --- a/config/menumain.lua +++ b/config/menumain.lua @@ -12,7 +12,7 @@ return { :setText("Start") :setPosition(button_x, 80) :set("active", function (self) - self.parent:load("menustart") + self.parent:load("menuselect") end) , button:new(menu) diff --git a/config/menuselect.lua b/config/menuselect.lua new file mode 100644 index 0000000..1830f0d --- /dev/null +++ b/config/menuselect.lua @@ -0,0 +1,16 @@ +local menu = ... + +local button = require "button" +local selector = require "selector" + +local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() + +return { + button:new(menu) + :setText("Go back") + :setPosition(10,height-25) + :set("active", function (self) + self.parent:load("menumain") + end) + , +} \ No newline at end of file diff --git a/config/menustart.lua b/config/menustart.lua deleted file mode 100644 index 1830f0d..0000000 --- a/config/menustart.lua +++ /dev/null @@ -1,16 +0,0 @@ -local menu = ... - -local button = require "button" -local selector = require "selector" - -local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() - -return { - button:new(menu) - :setText("Go back") - :setPosition(10,height-25) - :set("active", function (self) - self.parent:load("menumain") - end) - , -} \ No newline at end of file -- cgit v1.1 From cd72b080bd949d9ec0b42c29e0ea31e300464dad Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 00:10:33 +0200 Subject: Focus() return bool --- button.lua | 1 + element.lua | 8 ++------ header.lua | 8 ++------ menu.lua | 8 ++++++-- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/button.lua b/button.lua index d7caf74..fd12e0b 100644 --- a/button.lua +++ b/button.lua @@ -34,6 +34,7 @@ end function Button:getPosition() return self.x,self.y end function Button:focus(next) self.focused = true + return true end function Button:blur() self.focused = false diff --git a/element.lua b/element.lua index 5ca013b..f9d1c3d 100644 --- a/element.lua +++ b/element.lua @@ -26,12 +26,8 @@ function Element:set(name, func) end -- Menu callbacks -function Element:focus(next) -- Called when Element gains focus - if next and self.parent then - self.parent:next() - else - self.parent:previous() - end +function Element:focus() -- Called when Element gains focus + return false end function Element:blur() end -- Called when Element loses focus diff --git a/header.lua b/header.lua index d538ab3..d67e582 100644 --- a/header.lua +++ b/header.lua @@ -29,12 +29,8 @@ function Header:getBounce(f) return math.sin(self.bounce*f*math.pi) end function Header:getPosition() return self.x,self.y end -- gives x,y of Element -function Header:focus(next) - if next and self.parent then - self.parent:next() - else - self.parent:previous() - end +function Header:focus() + return false end function Header:blur() end -- Called when Element loses focus diff --git a/menu.lua b/menu.lua index 3ef477d..95e764b 100644 --- a/menu.lua +++ b/menu.lua @@ -34,7 +34,9 @@ end function Menu:next() self.elements[self.active]:blur() self.active = (self.active%#self.elements)+1 - self.elements[self.active]:focus(true) + if not self.elements[self.active]:focus() then + self:next() + end end function Menu:previous() self.elements[self.active]:blur() @@ -43,7 +45,9 @@ function Menu:previous() else self.active = self.active - 1 end - self.elements[self.active]:focus() + if not self.elements[self.active]:focus() then + self:previous() + end end -- LÖVE2D callbacks -- cgit v1.1 From db941f6b371774b7b9f5de0e8db86a9b4f5a1d7b Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 01:25:07 +0200 Subject: get sets --- controller.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/controller.lua b/controller.lua index 513af45..5ed7dd2 100644 --- a/controller.lua +++ b/controller.lua @@ -29,6 +29,11 @@ function Controller.registerSet(left, right, up, down, attack, jump, joystick) return set end +-- Get table of controls sets. +function Controller.getSets() + return Controller.sets +end + -- Tests all sets if they have control assigned to given key and joystick. function Controller.testSets(key, joystick) for i,set in pairs(Controller.sets) do -- cgit v1.1 From a1d3d14781565f226e7795e4d426c28614baab88 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 01:57:39 +0200 Subject: First steps in new selector --- selector.lua | 147 ++++++++++++++++++++++------------------------------------- 1 file changed, 55 insertions(+), 92 deletions(-) diff --git a/selector.lua b/selector.lua index afdfed7..9e2ad23 100644 --- a/selector.lua +++ b/selector.lua @@ -1,112 +1,75 @@ --- `Selector` --- Used in menu; selecting nauts? +-- `Selector` (Element) +-- Used in Menu for selecting various things from list. Works for each Controller set or globally. +--[[ +How to use `Selector` in `Menu` config file? +selector:new(menu) + :setPosition(x, y) + :set("list", require "file_with_list") + :set("global", true/false) -- true: single selector; false: selector for each controller set present +]] + Selector = { - naut = 1, + parent, x = 0, y = 0, - parent = nil, - controlset = nil, - locked = false + focused = false, + global = false, + list, + sets, + locks, + selections } -function Selector:new(menu) + +-- Constructor +function Selector:new(parent) local o = {} setmetatable(o, self) self.__index = self - o.parent = menu + o.parent = parent + o.list = {} + o.sets = {} + o.locks = {} + o.selections = {} return o end + -- Position -function Selector:setPosition(x,y) - self.x = x - self.y = y -end function Selector:getPosition() return self.x, self.y end --- Control Sets -function Selector:assignControlSet(set) - self.controlset = set - self.naut = 2 -end -function Selector:getControlSet() - if self.controlset ~= nil then - return self.controlset - end +function Selector:setPosition(x,y) + self.x, self.y = x, y + return self end --- States -function Selector:getState() - if self:getControlSet() ~= nil then - if self.locked then - return 2 -- has controls and locked - end - return 1 -- has controls but not locked + +-- General setter for Menu configuration files +function Selector:set(name, func) + if type(name) == "string" and func ~= nil then + self[name] = func end - return 0 -- no controls and not locked -end -function Selector:clear() - self.controlset = nil - self.naut = 1 - self.locked = false -end -function Selector:getSelectionName() - return self.parent.nauts[self.naut] + return self end +-- Selecting functions +function Selector:getSelection(n) end +function Selector:next(n) end +function Selector:previous(n) end + +-- Menu callbacks +function Selector:focus() -- Called when Element gains focus + self.focused = true + return true +end +function Selector:blur() -- Called when Element loses focus + self.focused = false +end + -- LÖVE2D callbacks -function Selector:draw() - -- portrait, sprite - local name = self.parent.nauts[self.naut] - local p = self.parent.portrait_sheet[name] - local sprite = self.parent.portrait_sprite - -- scale, position - local scale = self.parent.scale - local x,y = self:getPosition() - -- arrows - local arrowl = self.parent.portrait_sheet.arrow_left - local arrowr = self.parent.portrait_sheet.arrow_right - if not self.locked then - love.graphics.draw(sprite, p.normal, x*scale, y*scale, 0, scale, scale) - if self.controlset ~= nil then - love.graphics.draw(sprite, arrowl, (x-2)* scale, (y+13)*scale, 0, scale, scale) - love.graphics.draw(sprite, arrowr, (x+30)*scale, (y+13)*scale, 0, scale, scale) - end - else - love.graphics.draw(sprite, p.active, x*scale, y*scale, 0, scale, scale) - end - if self.naut ~= 1 then - love.graphics.printf(string.upper(name), (x-8)*scale, (y+33)*scale, 48, "center", 0, scale, scale) - end -end +function Selector:draw(scale) end +function Selector:update(dt) end -- Controller callbacks -function Selector:controlpressed(set, action, key) - -- locals - local n = #self.parent.nauts - if set == self:getControlSet() then - if action == "left" and not self.locked then - if self.naut == 2 or self.naut == 1 then - self.naut = n - else - self.naut = self.naut - 1 - end - elseif action == "right" and not self.locked then - if self.naut == n then - self.naut = 2 - else - self.naut = self.naut + 1 - end - elseif action == "attack" then - if self.naut ~= 1 then - self.locked = true - end - elseif action == "jump" then - if self.locked == true then - self.locked = false - else - self:clear() - end - end - end -end -function Selector:controlreleased(set, action, key) -end \ No newline at end of file +function Selector:controlpressed(set, action, key) end +function Selector:controlreleased(set, action, key) end + +return Selector \ No newline at end of file -- cgit v1.1 From e22d7b380513aec4d83dc06c59dfd461b5d3a8b2 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 04:12:07 +0200 Subject: locks, selections, init --- selector.lua | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/selector.lua b/selector.lua index 9e2ad23..96113df 100644 --- a/selector.lua +++ b/selector.lua @@ -6,6 +6,7 @@ selector:new(menu) :setPosition(x, y) :set("list", require "file_with_list") :set("global", true/false) -- true: single selector; false: selector for each controller set present + :init() ]] Selector = { @@ -26,10 +27,6 @@ function Selector:new(parent) setmetatable(o, self) self.__index = self o.parent = parent - o.list = {} - o.sets = {} - o.locks = {} - o.selections = {} return o end @@ -50,11 +47,55 @@ function Selector:set(name, func) return self end --- Selecting functions -function Selector:getSelection(n) end +-- Initialize Selector with current settings. +function Selector:init() + -- Make sure that there is list present + if self.list == nil then + self.list = {} + end + -- Initialize global Selector + if self.global then + self.locks = {false} + self.selections = {1} + -- Initialize Selector for Controllers + else + self.sets = Controller.getSets() + self.locks = {} + self.selections = {} + for i=1,#self.sets do + self.locks[i] = false + self.selections[i] = 1 + end + end +end + +-- Cycle through list on given number function Selector:next(n) end function Selector:previous(n) end +-- Get number associated with a given set +function Selector:checkNumber(set) + if self.global then return 1 end -- For global Selector + for n,check in pairs(self.sets) do + if check == set then return n end + end +end + +-- Check if given number is locked +function Selector:isLocked(n) + return self.locks[n] +end + +-- Get value of selection of given number +function Selector:getSelectionValue(n) + return self.selections[n] +end + +-- Get value from list by selection +function Selector:getListValue(i) + return self.list[i] +end + -- Menu callbacks function Selector:focus() -- Called when Element gains focus self.focused = true -- cgit v1.1 From 9fab96edd18260aaa2586901e7d28dfc387f17d2 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 04:57:23 +0200 Subject: Testing: next/prev --- selector.lua | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/selector.lua b/selector.lua index 96113df..fb2decb 100644 --- a/selector.lua +++ b/selector.lua @@ -62,16 +62,35 @@ function Selector:init() self.sets = Controller.getSets() self.locks = {} self.selections = {} - for i=1,#self.sets do - self.locks[i] = false - self.selections[i] = 1 + for n=1,#self.sets do + self.locks[n] = false + self.selections[n] = 1 end end + return self end -- Cycle through list on given number -function Selector:next(n) end -function Selector:previous(n) end +function Selector:next(n) + local total = #self.list + local current = self.selections[n] + local locked = self:isLocked(n) + if not locked then + self.selections[n] = (current % total) + 1 + end +end +function Selector:previous(n) + local total = #self.list + local current = self.selections[n] + local locked = self:isLocked(n) + if not locked then + if current == 1 then + self.selections[n] = total + else + self.selections[n] = current - 1 + end + end +end -- Get number associated with a given set function Selector:checkNumber(set) @@ -87,7 +106,7 @@ function Selector:isLocked(n) end -- Get value of selection of given number -function Selector:getSelectionValue(n) +function Selector:getSelection(n) return self.selections[n] end @@ -106,11 +125,19 @@ function Selector:blur() -- Called when Element loses focus end -- LÖVE2D callbacks -function Selector:draw(scale) end +function Selector:draw(scale) + local x,y = self:getPosition() + local text = self:getListValue(self:getSelection(1)) + love.graphics.setFont(Font) + love.graphics.setColor(255, 255, 255, 255) + love.graphics.printf(text, (x)*scale, (y)*scale, 54, "center", 0, scale, scale) +end function Selector:update(dt) end -- Controller callbacks -function Selector:controlpressed(set, action, key) end +function Selector:controlpressed(set, action, key) + self:next(1) +end function Selector:controlreleased(set, action, key) end return Selector \ No newline at end of file -- cgit v1.1 From 3ab0342ad678ceec3b708ac56e2b7e5bd70185ac Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 04:57:56 +0200 Subject: Add selector to select menu cfg --- config/menuselect.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config/menuselect.lua b/config/menuselect.lua index 1830f0d..fcfcc16 100644 --- a/config/menuselect.lua +++ b/config/menuselect.lua @@ -13,4 +13,10 @@ return { self.parent:load("menumain") end) , + selector:new(menu) + :setPosition(10,10) + :set("list", require "nautslist") + :set("global", false) + :init() + , } \ No newline at end of file -- cgit v1.1 From 3139857cee53affa1c642f92da8d6a595a18c52e Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 04:59:23 +0200 Subject: And moved it to top --- config/menuselect.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config/menuselect.lua b/config/menuselect.lua index fcfcc16..b1ce2cd 100644 --- a/config/menuselect.lua +++ b/config/menuselect.lua @@ -6,6 +6,12 @@ local selector = require "selector" local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() return { + selector:new(menu) + :setPosition(10,10) + :set("list", require "nautslist") + :set("global", false) + :init() + , button:new(menu) :setText("Go back") :setPosition(10,height-25) @@ -13,10 +19,4 @@ return { self.parent:load("menumain") end) , - selector:new(menu) - :setPosition(10,10) - :set("list", require "nautslist") - :set("global", false) - :init() - , } \ No newline at end of file -- cgit v1.1 From 2aef35b0bbb72595977cddc2c2bbb3f65beb6bc6 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 05:30:57 +0200 Subject: Draw me like one of your french girls --- config/menuselect.lua | 3 +++ selector.lua | 53 ++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/config/menuselect.lua b/config/menuselect.lua index b1ce2cd..c070f4c 100644 --- a/config/menuselect.lua +++ b/config/menuselect.lua @@ -8,8 +8,11 @@ local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.get return { selector:new(menu) :setPosition(10,10) + :setSpacing(42, 0) :set("list", require "nautslist") :set("global", false) + :set("sprite", love.graphics.newImage("assets/portraits.png")) + :set("quads", require "portraits") :init() , button:new(menu) diff --git a/selector.lua b/selector.lua index fb2decb..38e7eb9 100644 --- a/selector.lua +++ b/selector.lua @@ -4,8 +4,11 @@ How to use `Selector` in `Menu` config file? selector:new(menu) :setPosition(x, y) - :set("list", require "file_with_list") - :set("global", true/false) -- true: single selector; false: selector for each controller set present + :setSpacing(42, 0) + :set("list", require "nautslist") + :set("sprite", love.graphics.newImage("assets/portraits.png")) + :set("quads", require "portraits") + :set("global", false) -- true: single selector; false: selector for each controller set present :init() ]] @@ -13,12 +16,16 @@ Selector = { parent, x = 0, y = 0, + horizontal = 0, + height = 0, focused = false, global = false, list, sets, locks, - selections + selections, + sprite, + quads } -- Constructor @@ -39,6 +46,15 @@ function Selector:setPosition(x,y) return self end +-- Spacing between positions of two blocks +function Selector:getSpacing() + return self.horizontal, self.vertical +end +function Selector:setSpacing(horizontal, vertical) + self.horizontal, self.vertical = horizontal, vertical + return self +end + -- General setter for Menu configuration files function Selector:set(name, func) if type(name) == "string" and func ~= nil then @@ -115,6 +131,29 @@ function Selector:getListValue(i) return self.list[i] end +-- Draw single block of Selector +function Selector:drawBlock(n, x, y, scale) + local x, y = x or 0, y or 0 + if self.quads == nil or self.sprite == nil then return end + love.graphics.setFont(Font) + love.graphics.setColor(255, 255, 255, 255) + local name = self:getListValue(self:getSelection(n)) + local locked = self:isLocked(n) + local sprite = self.sprite + local quad = self.quads[name] + local arrowl = self.quads.arrow_left + local arrowr = self.quads.arrow_right + if not locked then + love.graphics.draw(sprite, quad.normal, x*scale, y*scale, 0, scale, scale) + if self.focused then + love.graphics.draw(sprite, arrowl, (x-2)* scale, (y+13)*scale, 0, scale, scale) + love.graphics.draw(sprite, arrowr, (x+30)*scale, (y+13)*scale, 0, scale, scale) + end + else + love.graphics.draw(sprite, quad.active, x*scale, y*scale, 0, scale, scale) + end +end + -- Menu callbacks function Selector:focus() -- Called when Element gains focus self.focused = true @@ -127,10 +166,10 @@ end -- LÖVE2D callbacks function Selector:draw(scale) local x,y = self:getPosition() - local text = self:getListValue(self:getSelection(1)) - love.graphics.setFont(Font) - love.graphics.setColor(255, 255, 255, 255) - love.graphics.printf(text, (x)*scale, (y)*scale, 54, "center", 0, scale, scale) + local h,v = self:getSpacing() + for n=1,#self.selections do + self:drawBlock(n, x+h*n, y+v*n, scale) + end end function Selector:update(dt) end -- cgit v1.1 From bf9ad0478e6b72f0e19af9cb7e65337521721e77 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 05:32:21 +0200 Subject: reset active element --- menu.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/menu.lua b/menu.lua index 95e764b..206c45e 100644 --- a/menu.lua +++ b/menu.lua @@ -26,6 +26,7 @@ function Menu:delete() end function Menu:load(name) local name = "config/" .. (name or "menumain") .. ".lua" local menu = love.filesystem.load(name) + self.active = 1 self.elements = menu(self) self.elements[self.active]:focus() end -- cgit v1.1 From 4bb25bb6c752efba17ffbc97bd4de9b3f33a190b Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 05:46:11 +0200 Subject: it's alive! (almost) --- selector.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/selector.lua b/selector.lua index 38e7eb9..f07b9e7 100644 --- a/selector.lua +++ b/selector.lua @@ -152,6 +152,9 @@ function Selector:drawBlock(n, x, y, scale) else love.graphics.draw(sprite, quad.active, x*scale, y*scale, 0, scale, scale) end + if self:getSelection(n) ~= 1 then + love.graphics.printf(string.upper(name), (x-8)*scale, (y+33)*scale, 48, "center", 0, scale, scale) + end end -- Menu callbacks @@ -175,7 +178,12 @@ function Selector:update(dt) end -- Controller callbacks function Selector:controlpressed(set, action, key) - self:next(1) + if set and self.focused then + local n = self:checkNumber(set) + local locked = self:isLocked(n) + if action == "left" and not locked then self:previous(n) end + if action == "right" and not locked then self:next(n) end + end end function Selector:controlreleased(set, action, key) end -- cgit v1.1 From b739e555026471db11e24cb4a92f55509e717761 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 06:43:11 +0200 Subject: Unique joysticks for sets --- controller.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/controller.lua b/controller.lua index 5ed7dd2..fde63c1 100644 --- a/controller.lua +++ b/controller.lua @@ -16,6 +16,7 @@ function Controller.controlreleased(set, action, key) end -- Create new controls set. function Controller.registerSet(left, right, up, down, attack, jump, joystick) + if not Controller.isJoystickUnique(joystick) then return end local set = {} set.left = left or "left" set.right = right or "right" @@ -34,6 +35,16 @@ function Controller.getSets() return Controller.sets end +-- Checks if given joystick is unique in current set of Controller sets +function Controller.isJoystickUnique(joystick) + if joystick ~= nil then + for _,set in pairs(Controller.sets) do + if set.joystick == joystick then return false end + end + end + return true +end + -- Tests all sets if they have control assigned to given key and joystick. function Controller.testSets(key, joystick) for i,set in pairs(Controller.sets) do -- cgit v1.1 From 53d8dde1eb82bfdf0e3513d288bdb295cd84873f Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 06:51:22 +0200 Subject: centered draw --- selector.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/selector.lua b/selector.lua index f07b9e7..f7f3474 100644 --- a/selector.lua +++ b/selector.lua @@ -170,6 +170,7 @@ end function Selector:draw(scale) local x,y = self:getPosition() local h,v = self:getSpacing() + x = #self.sets*h*0.5 for n=1,#self.selections do self:drawBlock(n, x+h*n, y+v*n, scale) end -- cgit v1.1 From 5c9146f74c1cd522c22a9affa403cf1f4b96921d Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 07:10:02 +0200 Subject: Now it's fine --- config/menuselect.lua | 5 +++-- selector.lua | 32 ++++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/config/menuselect.lua b/config/menuselect.lua index c070f4c..ffdda7f 100644 --- a/config/menuselect.lua +++ b/config/menuselect.lua @@ -7,8 +7,9 @@ local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.get return { selector:new(menu) - :setPosition(10,10) - :setSpacing(42, 0) + :setPosition(width/2,10) + :setMargin(8) + :setSize(32, 32) :set("list", require "nautslist") :set("global", false) :set("sprite", love.graphics.newImage("assets/portraits.png")) diff --git a/selector.lua b/selector.lua index f7f3474..240716e 100644 --- a/selector.lua +++ b/selector.lua @@ -4,7 +4,8 @@ How to use `Selector` in `Menu` config file? selector:new(menu) :setPosition(x, y) - :setSpacing(42, 0) + :setMargin(8) + :setSize(32, 32) :set("list", require "nautslist") :set("sprite", love.graphics.newImage("assets/portraits.png")) :set("quads", require "portraits") @@ -16,8 +17,9 @@ Selector = { parent, x = 0, y = 0, - horizontal = 0, + width = 0, height = 0, + margin = 0, focused = false, global = false, list, @@ -46,12 +48,21 @@ function Selector:setPosition(x,y) return self end --- Spacing between positions of two blocks -function Selector:getSpacing() - return self.horizontal, self.vertical +-- Size of single block +function Selector:getSize() + return self.width, self.height end -function Selector:setSpacing(horizontal, vertical) - self.horizontal, self.vertical = horizontal, vertical +function Selector:setSize(width, height) + self.width, self.height = width, height + return self +end + +-- Spacing between two blocks +function Selector:getMargin() + return self.margin +end +function Selector:setMargin(margin) + self.margin = margin return self end @@ -169,10 +180,11 @@ end -- LÖVE2D callbacks function Selector:draw(scale) local x,y = self:getPosition() - local h,v = self:getSpacing() - x = #self.sets*h*0.5 + local margin = self:getMargin() + local width = self:getSize() + x = x - #self.selections*0.5*(margin+margin+width) for n=1,#self.selections do - self:drawBlock(n, x+h*n, y+v*n, scale) + self:drawBlock(n, x+(margin+width)*(n-1)+margin*n, y, scale) end end function Selector:update(dt) end -- cgit v1.1 From 78cf905ac5fa190dbd8a84678330a0479747c0e7 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 12:23:01 +0200 Subject: More universal drawing --- selector.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/selector.lua b/selector.lua index 240716e..043a08b 100644 --- a/selector.lua +++ b/selector.lua @@ -154,17 +154,19 @@ function Selector:drawBlock(n, x, y, scale) local quad = self.quads[name] local arrowl = self.quads.arrow_left local arrowr = self.quads.arrow_right + local w,h = self:getSize() if not locked then love.graphics.draw(sprite, quad.normal, x*scale, y*scale, 0, scale, scale) if self.focused then - love.graphics.draw(sprite, arrowl, (x-2)* scale, (y+13)*scale, 0, scale, scale) - love.graphics.draw(sprite, arrowr, (x+30)*scale, (y+13)*scale, 0, scale, scale) + local dy = (h-6)/2 + love.graphics.draw(sprite, arrowl, (x+0-2)* scale, (y+dy)*scale, 0, scale, scale) + love.graphics.draw(sprite, arrowr, (x+w-2)*scale, (y+dy)*scale, 0, scale, scale) end else love.graphics.draw(sprite, quad.active, x*scale, y*scale, 0, scale, scale) end if self:getSelection(n) ~= 1 then - love.graphics.printf(string.upper(name), (x-8)*scale, (y+33)*scale, 48, "center", 0, scale, scale) + love.graphics.printf(string.upper(name), (x-w)*scale, (y+h+1)*scale, w*3, "center", 0, scale, scale) end end -- cgit v1.1 From 1213e1e2831805ebb5d193702e02c59c2927e54a Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 13:29:13 +0200 Subject: Almost the same functionality --- config/menumain.lua | 12 ++++++------ config/menuselect.lua | 16 +++++++++++++--- selector.lua | 28 ++++++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/config/menumain.lua b/config/menumain.lua index 2d92817..cb53714 100644 --- a/config/menumain.lua +++ b/config/menumain.lua @@ -5,31 +5,31 @@ local header = require "header" local element = require "element" local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() -local button_x = width/2-29 +local bx = width/2-29 return { button:new(menu) :setText("Start") - :setPosition(button_x, 80) + :setPosition(bx, 80) :set("active", function (self) self.parent:load("menuselect") end) , button:new(menu) :setText("Join") - :setPosition(button_x, 96) + :setPosition(bx, 96) , button:new(menu) :setText("Settings") - :setPosition(button_x, 112) + :setPosition(bx, 112) , button:new(menu) :setText("Credits") - :setPosition(button_x, 128) + :setPosition(bx, 128) , button:new(menu) :setText("Exit") - :setPosition(button_x, 144) + :setPosition(bx, 144) :set("active", love.event.quit) , element:new(menu) diff --git a/config/menuselect.lua b/config/menuselect.lua index ffdda7f..8d646ba 100644 --- a/config/menuselect.lua +++ b/config/menuselect.lua @@ -4,10 +4,13 @@ local button = require "button" local selector = require "selector" local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() +local bx = width/2-29 + +local naut_selector = selector:new(menu) return { - selector:new(menu) - :setPosition(width/2,10) + naut_selector + :setPosition(width/2,60) :setMargin(8) :setSize(32, 32) :set("list", require "nautslist") @@ -17,8 +20,15 @@ return { :init() , button:new(menu) + :setText("Force start") + :setPosition(bx,101) + :set("active", function (self) + changeScene(World:new(nil,naut_selector:getFullSelection(false))) + end) + , + button:new(menu) :setText("Go back") - :setPosition(10,height-25) + :setPosition(bx,117) :set("active", function (self) self.parent:load("menumain") end) diff --git a/selector.lua b/selector.lua index 043a08b..0b3fe8a 100644 --- a/selector.lua +++ b/selector.lua @@ -4,8 +4,8 @@ How to use `Selector` in `Menu` config file? selector:new(menu) :setPosition(x, y) - :setMargin(8) - :setSize(32, 32) + :setMargin(8) -- each block has marigin on both sides; they do stack + :setSize(32, 32) -- size of single graphics frame :set("list", require "nautslist") :set("sprite", love.graphics.newImage("assets/portraits.png")) :set("quads", require "portraits") @@ -142,6 +142,20 @@ function Selector:getListValue(i) return self.list[i] end +-- Get list of selections, checks if not locked are allowed. +function Selector:getFullSelection(allowed) + local allowed = allowed or false + local t = {} + for n,v in ipairs(self.selections) do + local name = self:getListValue(self:getSelection(n)) + local locked = self:isLocked(n) + if not (not locked and not allow) then + table.insert(t, {name, self.sets[n], self:isLocked(n)}) + end + end + return t +end + -- Draw single block of Selector function Selector:drawBlock(n, x, y, scale) local x, y = x or 0, y or 0 @@ -198,6 +212,16 @@ function Selector:controlpressed(set, action, key) local locked = self:isLocked(n) if action == "left" and not locked then self:previous(n) end if action == "right" and not locked then self:next(n) end + if action == "attack" then + if self:getSelection(n) ~= 1 then + self.locks[n] = true + end + end + if action == "jump" then + if locked then + self.locks[n] = false + end + end end end function Selector:controlreleased(set, action, key) end -- cgit v1.1 From 8b0698abc1290cbdbfef3c8b48a2dc7a0388c9d1 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 14:19:18 +0200 Subject: Blink button, fix empty error --- button.lua | 14 +++++++++++++- config/menuselect.lua | 7 ++++++- selector.lua | 9 +++++---- world.lua | 13 +++---------- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/button.lua b/button.lua index fd12e0b..6b8ef25 100644 --- a/button.lua +++ b/button.lua @@ -11,6 +11,7 @@ Button = { arrow_l = love.graphics.newQuad(58, 0, 5, 5, 68,15), arrow_r = love.graphics.newQuad(63, 0, 5, 5, 68,15), delay = 2, + blinker = 1, parent } @@ -40,6 +41,9 @@ function Button:blur() self.focused = false end function Button:active() end +function Button:blink() + self.blinker = 0 +end function Button:set(name, func) if type(name) == "string" and type(func) == "function" then self[name] = func @@ -48,7 +52,12 @@ function Button:set(name, func) end function Button:draw(scale) local x,y = self:getPosition() - love.graphics.setColor(255, 255, 255, 255) + local blinker = math.floor(self.blinker*4) + if blinker%2 == 0 then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(255, 100, 100, 255) + end love.graphics.draw(self.sprite, self.quad, x*scale, y*scale, 0, scale, scale) if self.focused then love.graphics.draw(self.sprite, self.arrow_l, (x+54+math.floor(self.delay))*scale, (y+5)*scale, 0, scale, scale) @@ -62,6 +71,9 @@ function Button:update(dt) if self.delay > Button.delay then -- Button.delay is initial self.delay = self.delay - Button.delay end + if self.blinker < Button.blinker then -- Button.blink is initial + self.blinker = self.blinker + dt + end end function Button:controlpressed(set, action, key) if action == "attack" and self.focused then diff --git a/config/menuselect.lua b/config/menuselect.lua index 8d646ba..c3a05c1 100644 --- a/config/menuselect.lua +++ b/config/menuselect.lua @@ -23,7 +23,12 @@ return { :setText("Force start") :setPosition(bx,101) :set("active", function (self) - changeScene(World:new(nil,naut_selector:getFullSelection(false))) + local nauts = naut_selector:getFullSelection(false) + if #nauts > 1 then + changeScene(World:new(nil, nauts)) + else + self:blink() + end end) , button:new(menu) diff --git a/selector.lua b/selector.lua index 0b3fe8a..cba01e6 100644 --- a/selector.lua +++ b/selector.lua @@ -144,13 +144,14 @@ end -- Get list of selections, checks if not locked are allowed. function Selector:getFullSelection(allowed) - local allowed = allowed or false + local allowed = allowed + if allowed == nil then allowed = false end local t = {} - for n,v in ipairs(self.selections) do + for n,v in pairs(self.selections) do local name = self:getListValue(self:getSelection(n)) local locked = self:isLocked(n) - if not (not locked and not allow) then - table.insert(t, {name, self.sets[n], self:isLocked(n)}) + if locked or allowed then + table.insert(t, {name, self.sets[n]}) end end return t diff --git a/world.lua b/world.lua index 8f948ce..57b8cd7 100644 --- a/world.lua +++ b/world.lua @@ -36,7 +36,7 @@ World = { } -- Constructor of `World` ZA WARUDO! -function World:new(map, ...) +function World:new(map, nauts) -- Meta local o = {} setmetatable(o, self) @@ -64,7 +64,7 @@ function World:new(map, ...) local map = map or "default" o:loadMap(map) -- Nauts - o:spawnNauts(...) + o:spawnNauts(nauts) -- Create camera o.camera = Camera:new(o) -- Play music @@ -110,14 +110,7 @@ function World:loadMap(name) end -- Spawn all the nauts for the round -function World:spawnNauts(...) - local params = {...} - local nauts = nil - if type(params[1][1]) == "table" then - nauts = params[1] - else - nauts = params - end +function World:spawnNauts(nauts) for _,naut in pairs(nauts) do local x,y = self:getSpawnPosition() local spawn = self:createNaut(x, y, naut[1]) -- cgit v1.1 From aafcac7057e0ef7904d96446f88b2d26b12e0ab5 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 14:53:05 +0200 Subject: I don't regret this --- config/menumain.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/config/menumain.lua b/config/menumain.lua index cb53714..c0607d6 100644 --- a/config/menumain.lua +++ b/config/menumain.lua @@ -18,14 +18,23 @@ return { button:new(menu) :setText("Join") :setPosition(bx, 96) + :set("active", function (self) + self:blink() + end) , button:new(menu) :setText("Settings") :setPosition(bx, 112) + :set("active", function (self) + self:blink() + end) , button:new(menu) :setText("Credits") :setPosition(bx, 128) + :set("active", function (self) + self:blink() + end) , button:new(menu) :setText("Exit") -- cgit v1.1 From 2abd5e31214a14f7e090fe81985ddf2aeac32112 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 18:33:12 +0200 Subject: Only unique nauts --- selector.lua | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/selector.lua b/selector.lua index cba01e6..a0e19f8 100644 --- a/selector.lua +++ b/selector.lua @@ -142,6 +142,17 @@ function Selector:getListValue(i) return self.list[i] end +-- Checks if selection of given number is unique within Selector scope. +function Selector:isUnique(n) + local selection = self:getSelection(n) + for fn,v in pairs(self.selections) do + if fn ~= n and self:isLocked(fn) and v == selection then + return false + end + end + return true +end + -- Get list of selections, checks if not locked are allowed. function Selector:getFullSelection(allowed) local allowed = allowed @@ -159,10 +170,8 @@ end -- Draw single block of Selector function Selector:drawBlock(n, x, y, scale) - local x, y = x or 0, y or 0 if self.quads == nil or self.sprite == nil then return end - love.graphics.setFont(Font) - love.graphics.setColor(255, 255, 255, 255) + local x, y = x or 0, y or 0 local name = self:getListValue(self:getSelection(n)) local locked = self:isLocked(n) local sprite = self.sprite @@ -170,6 +179,12 @@ function Selector:drawBlock(n, x, y, scale) local arrowl = self.quads.arrow_left local arrowr = self.quads.arrow_right local w,h = self:getSize() + local unique = self:isUnique(n) + if unique then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(140, 140, 140, 255) + end if not locked then love.graphics.draw(sprite, quad.normal, x*scale, y*scale, 0, scale, scale) if self.focused then @@ -181,6 +196,8 @@ function Selector:drawBlock(n, x, y, scale) love.graphics.draw(sprite, quad.active, x*scale, y*scale, 0, scale, scale) end if self:getSelection(n) ~= 1 then + love.graphics.setFont(Font) + love.graphics.setColor(255, 255, 255, 255) love.graphics.printf(string.upper(name), (x-w)*scale, (y+h+1)*scale, w*3, "center", 0, scale, scale) end end @@ -214,7 +231,7 @@ function Selector:controlpressed(set, action, key) if action == "left" and not locked then self:previous(n) end if action == "right" and not locked then self:next(n) end if action == "attack" then - if self:getSelection(n) ~= 1 then + if self:getSelection(n) ~= 1 and self:isUnique(n) then self.locks[n] = true end end -- cgit v1.1 From b19ec990880a3f2529ac8a7833337a0984094a23 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 19:03:40 +0200 Subject: Autostart+new menu --- config/menuhost.lua | 24 ++++++++++++++++++++++++ config/menumain.lua | 2 +- config/menuselect.lua | 36 ++++++++++++++++++++++++++++++++---- 3 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 config/menuhost.lua diff --git a/config/menuhost.lua b/config/menuhost.lua new file mode 100644 index 0000000..3ad10db --- /dev/null +++ b/config/menuhost.lua @@ -0,0 +1,24 @@ +local menu = ... + +local button = require "button" +local selector = require "selector" + +local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() +local bx = width/2-29 + +return { + button:new(menu) + :setText("Select") + :setPosition(bx,101) + :set("active", function (self) + self.parent:load("menuselect") + end) + , + button:new(menu) + :setText("Go back") + :setPosition(bx,117) + :set("active", function (self) + self.parent:load("menumain") + end) + , +} \ No newline at end of file diff --git a/config/menumain.lua b/config/menumain.lua index c0607d6..2ca2c59 100644 --- a/config/menumain.lua +++ b/config/menumain.lua @@ -12,7 +12,7 @@ return { :setText("Start") :setPosition(bx, 80) :set("active", function (self) - self.parent:load("menuselect") + self.parent:load("menuhost") end) , button:new(menu) diff --git a/config/menuselect.lua b/config/menuselect.lua index c3a05c1..af71b5f 100644 --- a/config/menuselect.lua +++ b/config/menuselect.lua @@ -2,11 +2,13 @@ local menu = ... local button = require "button" local selector = require "selector" +local element = require "element" local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() local bx = width/2-29 local naut_selector = selector:new(menu) +local start_button = button:new(menu) return { naut_selector @@ -19,9 +21,9 @@ return { :set("quads", require "portraits") :init() , - button:new(menu) + start_button :setText("Force start") - :setPosition(bx,101) + :setPosition(bx,134) :set("active", function (self) local nauts = naut_selector:getFullSelection(false) if #nauts > 1 then @@ -33,9 +35,35 @@ return { , button:new(menu) :setText("Go back") - :setPosition(bx,117) + :setPosition(bx,150) :set("active", function (self) - self.parent:load("menumain") + self.parent:load("menuhost") + end) + , + element:new(menu) + :setPosition(bx, 101) + :set("the_final_countdown", 9) + :set("draw", function (self, scale) + if self.the_final_countdown ~= 9 then + local x,y = self:getPosition() + local countdown = math.max(1, math.ceil(self.the_final_countdown)) + love.graphics.setColor(255, 255, 255, 255) + love.graphics.setFont(Font) + love.graphics.print("Autostart in:", (x-16)*scale, (y+10)*scale, 0, scale, scale) + love.graphics.setFont(Bold) + love.graphics.printf(countdown, (x+40)*scale, (y)*scale, 36, "center", 0, scale, scale) + end + end) + :set("update", function (self, dt) + local total = #naut_selector:getFullSelection(false) + if total > 1 then + self.the_final_countdown = self.the_final_countdown - dt + else + self.the_final_countdown = 9 + end + if self.the_final_countdown < 0 then + start_button:active() + end end) , } \ No newline at end of file -- cgit v1.1 From 65e2f701a6c0cfbf53506678771839f7f6d12cbf Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 22:14:10 +0200 Subject: map selection --- assets/placeholder-map-icon.png | Bin 0 -> 1220 bytes config/menuhost.lua | 13 +++++++++++++ config/menuselect.lua | 2 +- selector.lua | 5 ++++- 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 assets/placeholder-map-icon.png diff --git a/assets/placeholder-map-icon.png b/assets/placeholder-map-icon.png new file mode 100644 index 0000000..cab79f1 Binary files /dev/null and b/assets/placeholder-map-icon.png differ diff --git a/config/menuhost.lua b/config/menuhost.lua index 3ad10db..53972b3 100644 --- a/config/menuhost.lua +++ b/config/menuhost.lua @@ -6,11 +6,24 @@ local selector = require "selector" local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() local bx = width/2-29 +local map_selector = selector:new(menu) + return { + map_selector + :setPosition(width/2, 10) + :setSize(80, 42) + :setMargin(0) + :set("global", true) + :set("list", require "maplist") + :set("sprite", love.graphics.newImage("assets/placeholder-map-icon.png")) + :set("quads", require "mapicons") + :init() + , button:new(menu) :setText("Select") :setPosition(bx,101) :set("active", function (self) + MAP = map_selector:getFullSelection(true)[1][1] self.parent:load("menuselect") end) , diff --git a/config/menuselect.lua b/config/menuselect.lua index af71b5f..20ea607 100644 --- a/config/menuselect.lua +++ b/config/menuselect.lua @@ -27,7 +27,7 @@ return { :set("active", function (self) local nauts = naut_selector:getFullSelection(false) if #nauts > 1 then - changeScene(World:new(nil, nauts)) + changeScene(World:new(MAP, nauts)) else self:blink() end diff --git a/selector.lua b/selector.lua index a0e19f8..f2d7b16 100644 --- a/selector.lua +++ b/selector.lua @@ -82,6 +82,7 @@ function Selector:init() end -- Initialize global Selector if self.global then + self.sets = {} self.locks = {false} self.selections = {1} -- Initialize Selector for Controllers @@ -162,7 +163,9 @@ function Selector:getFullSelection(allowed) local name = self:getListValue(self:getSelection(n)) local locked = self:isLocked(n) if locked or allowed then - table.insert(t, {name, self.sets[n]}) + local a = {name} + if self.sets[n] then table.insert(a, self.sets[n]) end + table.insert(t, a) end end return t -- cgit v1.1 From ac6d4307fc9f7713b996eb8d36a8d0d3756efc00 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 25 Aug 2016 16:44:13 +0200 Subject: THIS NEED REAL CLEANUP --- assets/menu.png | Bin 279 -> 599 bytes assets/placeholder-map-icon.png | Bin 1220 -> 5322 bytes button.lua | 14 ++++++------ config/menuhost.lua | 5 +++-- config/menuselect.lua | 4 ++-- mapicons.lua | 8 +++++++ menu.lua | 25 +++++++++++++++++++++- nautsicons.lua | 46 ++++++++++++++++++++++++++++++++++++++++ selector.lua | 39 ++++++++++++++++++++++------------ 9 files changed, 115 insertions(+), 26 deletions(-) create mode 100644 mapicons.lua create mode 100644 nautsicons.lua diff --git a/assets/menu.png b/assets/menu.png index ec5a398..8088c23 100644 Binary files a/assets/menu.png and b/assets/menu.png differ diff --git a/assets/placeholder-map-icon.png b/assets/placeholder-map-icon.png index cab79f1..eccb551 100644 Binary files a/assets/placeholder-map-icon.png and b/assets/placeholder-map-icon.png differ diff --git a/button.lua b/button.lua index 6b8ef25..4b397cf 100644 --- a/button.lua +++ b/button.lua @@ -7,9 +7,7 @@ Button = { x = 0, y = 0, sprite, - quad = love.graphics.newQuad(0, 0, 58,15, 68,15), - arrow_l = love.graphics.newQuad(58, 0, 5, 5, 68,15), - arrow_r = love.graphics.newQuad(63, 0, 5, 5, 68,15), + quads, delay = 2, blinker = 1, parent @@ -20,7 +18,7 @@ function Button:new(parent) setmetatable(o, self) self.__index = self o.parent = parent - self.sprite = love.graphics.newImage("assets/menu.png") + o.sprite, o.quads = parent:getSheet() return o end function Button:setText(text) @@ -53,15 +51,17 @@ end function Button:draw(scale) local x,y = self:getPosition() local blinker = math.floor(self.blinker*4) + local quad = self.quads + local sprite = self.sprite if blinker%2 == 0 then love.graphics.setColor(255, 255, 255, 255) else love.graphics.setColor(255, 100, 100, 255) end - love.graphics.draw(self.sprite, self.quad, x*scale, y*scale, 0, scale, scale) + love.graphics.draw(sprite, quad.button.normal, x*scale, y*scale, 0, scale, scale) if self.focused then - love.graphics.draw(self.sprite, self.arrow_l, (x+54+math.floor(self.delay))*scale, (y+5)*scale, 0, scale, scale) - love.graphics.draw(self.sprite, self.arrow_r, (x-1-math.floor(self.delay))*scale, (y+5)*scale, 0, scale, scale) + love.graphics.draw(sprite, quad.arrow_l, (x+54+math.floor(self.delay))*scale, (y+5)*scale, 0, scale, scale) + love.graphics.draw(sprite, quad.arrow_r, (x-2-math.floor(self.delay))*scale, (y+5)*scale, 0, scale, scale) end love.graphics.setFont(Font) love.graphics.printf(self.text, (x+2)*scale, (y+4)*scale, 54, "center", 0, scale, scale) diff --git a/config/menuhost.lua b/config/menuhost.lua index 53972b3..878ec71 100644 --- a/config/menuhost.lua +++ b/config/menuhost.lua @@ -15,8 +15,9 @@ return { :setMargin(0) :set("global", true) :set("list", require "maplist") - :set("sprite", love.graphics.newImage("assets/placeholder-map-icon.png")) - :set("quads", require "mapicons") + :set("icons_i", love.graphics.newImage("assets/placeholder-map-icon.png")) + :set("icons_q", require "mapicons") + :set("shape", "panorama") :init() , button:new(menu) diff --git a/config/menuselect.lua b/config/menuselect.lua index 20ea607..31cf02e 100644 --- a/config/menuselect.lua +++ b/config/menuselect.lua @@ -17,8 +17,8 @@ return { :setSize(32, 32) :set("list", require "nautslist") :set("global", false) - :set("sprite", love.graphics.newImage("assets/portraits.png")) - :set("quads", require "portraits") + :set("icons_i", love.graphics.newImage("assets/portraits.png")) + :set("icons_q", require "nautsicons") :init() , start_button diff --git a/mapicons.lua b/mapicons.lua new file mode 100644 index 0000000..40ba589 --- /dev/null +++ b/mapicons.lua @@ -0,0 +1,8 @@ +local w, h = 80, 210 +return { + default = love.graphics.newQuad(2, 3,76,37,w,h), + rill = love.graphics.newQuad(2, 45,76,37,w,h), + ribbit = love.graphics.newQuad(2, 87,76,37,w,h), + starstorm = love.graphics.newQuad(2,129,76,37,w,h), + aiguillon = love.graphics.newQuad(2,171,76,37,w,h), +} \ No newline at end of file diff --git a/menu.lua b/menu.lua index 206c45e..29f5b2a 100644 --- a/menu.lua +++ b/menu.lua @@ -9,12 +9,30 @@ Menu = { scale = getScale(), elements, --table active = 1, - music + music, + sprite, + quads = { + 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), + } } function Menu:new(name) local o = {} setmetatable(o, self) self.__index = self + self.sprite = love.graphics.newImage("assets/menu.png") o.elements = {} o:load(name) o.music = Music:new("menu.ogg") @@ -31,6 +49,11 @@ function Menu:load(name) self.elements[self.active]:focus() end +-- Return reference to quads table and menu sprite +function Menu:getSheet() + return self.sprite, self.quads +end + -- Cycle elements function Menu:next() self.elements[self.active]:blur() diff --git a/nautsicons.lua b/nautsicons.lua new file mode 100644 index 0000000..a44e01d --- /dev/null +++ b/nautsicons.lua @@ -0,0 +1,46 @@ +-- Spritesheet for character portraits +-- Original size: 331x265 (say what?) +-- Single size: 32x32 1px border merged between +local w, h = 331, 265 +return { + -- EMPTY + empty = love.graphics.newQuad(300,136,28,28,w,h), + -- 1. ROW + froggo = love.graphics.newQuad( 3, 4,28,28,w,h), + cowboy = love.graphics.newQuad( 36, 4,28,28,w,h), + honic = love.graphics.newQuad( 69, 4,28,28,w,h), + gelato = love.graphics.newQuad(102, 4,28,28,w,h), + veno = love.graphics.newQuad(135, 4,28,28,w,h), + lady = love.graphics.newQuad(168, 4,28,28,w,h), + girl = love.graphics.newQuad(201, 4,28,28,w,h), + megoman = love.graphics.newQuad(234, 4,28,28,w,h), + brainos = love.graphics.newQuad(267, 4,28,28,w,h), + -- 2. ROW + woman = love.graphics.newQuad( 3, 70,28,28,w,h), + bison = love.graphics.newQuad( 36, 70,28,28,w,h), + bobito = love.graphics.newQuad( 69, 70,28,28,w,h), + slugzor = love.graphics.newQuad(102, 70,28,28,w,h), + capone = love.graphics.newQuad(135, 70,28,28,w,h), + bug = love.graphics.newQuad(168, 70,28,28,w,h), + calamari = love.graphics.newQuad(201, 70,28,28,w,h), + quack = love.graphics.newQuad(234, 70,28,28,w,h), + scissors = love.graphics.newQuad(267, 70,28,28,w,h), + -- 3. ROW + marine = love.graphics.newQuad( 3, 136,28,28,w,h), + scooter = love.graphics.newQuad( 36, 136,28,28,w,h), + phonebooth = love.graphics.newQuad( 69, 136,28,28,w,h), + weed = love.graphics.newQuad(102, 136,28,28,w,h), + gummybear = love.graphics.newQuad(135, 136,28,28,w,h), + gramps = love.graphics.newQuad(168, 136,28,28,w,h), + biker = love.graphics.newQuad(201, 136,28,28,w,h), + vrooom = love.graphics.newQuad(234, 136,28,28,w,h), + link = love.graphics.newQuad(267, 136,28,28,w,h), + -- 4. ROW + gorilla = love.graphics.newQuad( 3,202,28,28,w,h), + nemo = love.graphics.newQuad( 36,202,28,28,w,h), + rock = love.graphics.newQuad( 69,202,28,28,w,h), + boss = love.graphics.newQuad(102,202,28,28,w,h), + -- ARROWS + arrow_left = love.graphics.newQuad(298,1,4,6,w,h), + arrow_right = love.graphics.newQuad(303,1,4,6,w,h) +} diff --git a/selector.lua b/selector.lua index f2d7b16..a4f9c03 100644 --- a/selector.lua +++ b/selector.lua @@ -7,8 +7,8 @@ selector:new(menu) :setMargin(8) -- each block has marigin on both sides; they do stack :setSize(32, 32) -- size of single graphics frame :set("list", require "nautslist") - :set("sprite", love.graphics.newImage("assets/portraits.png")) - :set("quads", require "portraits") + :set("icons_i", love.graphics.newImage("assets/portraits.png")) + :set("icons_q", require "portraits") :set("global", false) -- true: single selector; false: selector for each controller set present :init() ]] @@ -22,12 +22,16 @@ Selector = { margin = 0, focused = false, global = false, + delay = 2, list, sets, locks, selections, + shape = "portrait", sprite, - quads + quads, + icons_i, + icons_q } -- Constructor @@ -36,6 +40,7 @@ function Selector:new(parent) setmetatable(o, self) self.__index = self o.parent = parent + o.sprite, o.quads = parent:getSheet() return o end @@ -178,9 +183,9 @@ function Selector:drawBlock(n, x, y, scale) local name = self:getListValue(self:getSelection(n)) local locked = self:isLocked(n) local sprite = self.sprite - local quad = self.quads[name] - local arrowl = self.quads.arrow_left - local arrowr = self.quads.arrow_right + local quad = self.quads + local icon = self.icons_i + local iconq = self.icons_q[name] local w,h = self:getSize() local unique = self:isUnique(n) if unique then @@ -189,14 +194,15 @@ function Selector:drawBlock(n, x, y, scale) love.graphics.setColor(140, 140, 140, 255) end if not locked then - love.graphics.draw(sprite, quad.normal, x*scale, y*scale, 0, scale, scale) - if self.focused then - local dy = (h-6)/2 - love.graphics.draw(sprite, arrowl, (x+0-2)* scale, (y+dy)*scale, 0, scale, scale) - love.graphics.draw(sprite, arrowr, (x+w-2)*scale, (y+dy)*scale, 0, scale, scale) - end + love.graphics.draw(sprite, quad[self.shape].normal, x*scale, y*scale, 0, scale, scale) else - love.graphics.draw(sprite, quad.active, x*scale, y*scale, 0, scale, scale) + love.graphics.draw(sprite, quad[self.shape].active, x*scale, y*scale, 0, scale, scale) + end + love.graphics.draw(icon, iconq, (x+2)*scale, (y+3)*scale, 0, scale, scale) + if self.focused and not locked then + local dy = (h-6)/2 + love.graphics.draw(sprite, quad.arrow_l, (x+0-2-math.floor(self.delay))* scale, (y+dy)*scale, 0, scale, scale) + love.graphics.draw(sprite, quad.arrow_r, (x+w-4+math.floor(self.delay))*scale, (y+dy)*scale, 0, scale, scale) end if self:getSelection(n) ~= 1 then love.graphics.setFont(Font) @@ -224,7 +230,12 @@ function Selector:draw(scale) self:drawBlock(n, x+(margin+width)*(n-1)+margin*n, y, scale) end end -function Selector:update(dt) end +function Selector:update(dt) + self.delay = self.delay + dt + if self.delay > Selector.delay then -- Selector.delay is initial + self.delay = self.delay - Selector.delay + end +end -- Controller callbacks function Selector:controlpressed(set, action, key) -- cgit v1.1 From 7c41ef664be97b2de097c16df8b7d84379be920b Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 25 Aug 2016 16:45:56 +0200 Subject: I can't substract... --- nautsicons.lua | 62 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/nautsicons.lua b/nautsicons.lua index a44e01d..f0cd9c2 100644 --- a/nautsicons.lua +++ b/nautsicons.lua @@ -6,40 +6,40 @@ return { -- EMPTY empty = love.graphics.newQuad(300,136,28,28,w,h), -- 1. ROW - froggo = love.graphics.newQuad( 3, 4,28,28,w,h), - cowboy = love.graphics.newQuad( 36, 4,28,28,w,h), - honic = love.graphics.newQuad( 69, 4,28,28,w,h), - gelato = love.graphics.newQuad(102, 4,28,28,w,h), - veno = love.graphics.newQuad(135, 4,28,28,w,h), - lady = love.graphics.newQuad(168, 4,28,28,w,h), - girl = love.graphics.newQuad(201, 4,28,28,w,h), - megoman = love.graphics.newQuad(234, 4,28,28,w,h), - brainos = love.graphics.newQuad(267, 4,28,28,w,h), + froggo = love.graphics.newQuad( 3, 4,28,27,w,h), + cowboy = love.graphics.newQuad( 36, 4,28,27,w,h), + honic = love.graphics.newQuad( 69, 4,28,27,w,h), + gelato = love.graphics.newQuad(102, 4,28,27,w,h), + veno = love.graphics.newQuad(135, 4,28,27,w,h), + lady = love.graphics.newQuad(168, 4,28,27,w,h), + girl = love.graphics.newQuad(201, 4,28,27,w,h), + megoman = love.graphics.newQuad(234, 4,28,27,w,h), + brainos = love.graphics.newQuad(267, 4,28,27,w,h), -- 2. ROW - woman = love.graphics.newQuad( 3, 70,28,28,w,h), - bison = love.graphics.newQuad( 36, 70,28,28,w,h), - bobito = love.graphics.newQuad( 69, 70,28,28,w,h), - slugzor = love.graphics.newQuad(102, 70,28,28,w,h), - capone = love.graphics.newQuad(135, 70,28,28,w,h), - bug = love.graphics.newQuad(168, 70,28,28,w,h), - calamari = love.graphics.newQuad(201, 70,28,28,w,h), - quack = love.graphics.newQuad(234, 70,28,28,w,h), - scissors = love.graphics.newQuad(267, 70,28,28,w,h), + woman = love.graphics.newQuad( 3, 70,28,27,w,h), + bison = love.graphics.newQuad( 36, 70,28,27,w,h), + bobito = love.graphics.newQuad( 69, 70,28,27,w,h), + slugzor = love.graphics.newQuad(102, 70,28,27,w,h), + capone = love.graphics.newQuad(135, 70,28,27,w,h), + bug = love.graphics.newQuad(168, 70,28,27,w,h), + calamari = love.graphics.newQuad(201, 70,28,27,w,h), + quack = love.graphics.newQuad(234, 70,28,27,w,h), + scissors = love.graphics.newQuad(267, 70,28,27,w,h), -- 3. ROW - marine = love.graphics.newQuad( 3, 136,28,28,w,h), - scooter = love.graphics.newQuad( 36, 136,28,28,w,h), - phonebooth = love.graphics.newQuad( 69, 136,28,28,w,h), - weed = love.graphics.newQuad(102, 136,28,28,w,h), - gummybear = love.graphics.newQuad(135, 136,28,28,w,h), - gramps = love.graphics.newQuad(168, 136,28,28,w,h), - biker = love.graphics.newQuad(201, 136,28,28,w,h), - vrooom = love.graphics.newQuad(234, 136,28,28,w,h), - link = love.graphics.newQuad(267, 136,28,28,w,h), + marine = love.graphics.newQuad( 3, 136,28,27,w,h), + scooter = love.graphics.newQuad( 36, 136,28,27,w,h), + phonebooth = love.graphics.newQuad( 69, 136,28,27,w,h), + weed = love.graphics.newQuad(102, 136,28,27,w,h), + gummybear = love.graphics.newQuad(135, 136,28,27,w,h), + gramps = love.graphics.newQuad(168, 136,28,27,w,h), + biker = love.graphics.newQuad(201, 136,28,27,w,h), + vrooom = love.graphics.newQuad(234, 136,28,27,w,h), + link = love.graphics.newQuad(267, 136,28,27,w,h), -- 4. ROW - gorilla = love.graphics.newQuad( 3,202,28,28,w,h), - nemo = love.graphics.newQuad( 36,202,28,28,w,h), - rock = love.graphics.newQuad( 69,202,28,28,w,h), - boss = love.graphics.newQuad(102,202,28,28,w,h), + gorilla = love.graphics.newQuad( 3,202,28,27,w,h), + nemo = love.graphics.newQuad( 36,202,28,27,w,h), + rock = love.graphics.newQuad( 69,202,28,27,w,h), + boss = love.graphics.newQuad(102,202,28,27,w,h), -- ARROWS arrow_left = love.graphics.newQuad(298,1,4,6,w,h), arrow_right = love.graphics.newQuad(303,1,4,6,w,h) -- cgit v1.1 From ab82b9f8ee76ef8327765ed59639c3f3c65fce8f Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 26 Aug 2016 15:52:25 +0200 Subject: allow first --- assets/placeholder-map-icon.png | Bin 5322 -> 6850 bytes config/menuhost.lua | 3 ++- selector.lua | 5 +++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/assets/placeholder-map-icon.png b/assets/placeholder-map-icon.png index eccb551..3d54e18 100644 Binary files a/assets/placeholder-map-icon.png and b/assets/placeholder-map-icon.png differ diff --git a/config/menuhost.lua b/config/menuhost.lua index 878ec71..6e52482 100644 --- a/config/menuhost.lua +++ b/config/menuhost.lua @@ -10,10 +10,11 @@ local map_selector = selector:new(menu) return { map_selector - :setPosition(width/2, 10) + :setPosition(width/2, 40) :setSize(80, 42) :setMargin(0) :set("global", true) + :set("first", true) :set("list", require "maplist") :set("icons_i", love.graphics.newImage("assets/placeholder-map-icon.png")) :set("icons_q", require "mapicons") diff --git a/selector.lua b/selector.lua index a4f9c03..f382bbb 100644 --- a/selector.lua +++ b/selector.lua @@ -23,6 +23,7 @@ Selector = { focused = false, global = false, delay = 2, + first = false, list, sets, locks, @@ -204,7 +205,7 @@ function Selector:drawBlock(n, x, y, scale) love.graphics.draw(sprite, quad.arrow_l, (x+0-2-math.floor(self.delay))* scale, (y+dy)*scale, 0, scale, scale) love.graphics.draw(sprite, quad.arrow_r, (x+w-4+math.floor(self.delay))*scale, (y+dy)*scale, 0, scale, scale) end - if self:getSelection(n) ~= 1 then + if (self:getSelection(n) ~= 1 or self.first) then love.graphics.setFont(Font) love.graphics.setColor(255, 255, 255, 255) love.graphics.printf(string.upper(name), (x-w)*scale, (y+h+1)*scale, w*3, "center", 0, scale, scale) @@ -245,7 +246,7 @@ function Selector:controlpressed(set, action, key) if action == "left" and not locked then self:previous(n) end if action == "right" and not locked then self:next(n) end if action == "attack" then - if self:getSelection(n) ~= 1 and self:isUnique(n) then + if (self:getSelection(n) ~= 1 or self.first) and self:isUnique(n) then self.locks[n] = true end end -- cgit v1.1 From ba478157bd634e60469d8ca1091a69a8a614e1bd Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 28 Aug 2016 03:42:31 +0200 Subject: temp background --- menu.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/menu.lua b/menu.lua index 29f5b2a..bd04215 100644 --- a/menu.lua +++ b/menu.lua @@ -11,6 +11,7 @@ Menu = { active = 1, music, sprite, + background, quads = { button = { normal = love.graphics.newQuad(0, 0, 58,15, 80,130), @@ -33,6 +34,7 @@ function Menu:new(name) setmetatable(o, self) self.__index = self self.sprite = love.graphics.newImage("assets/menu.png") + self.background = love.graphics.newImage("assets/backgrounds/menu.png") o.elements = {} o:load(name) o.music = Music:new("menu.ogg") @@ -82,6 +84,7 @@ function Menu:update(dt) end function Menu:draw() local scale = self.scale + love.graphics.draw(self.background, 0, 0, 0, scale, scale) love.graphics.setFont(Font) for _,element in pairs(self.elements) do element:draw(scale) -- cgit v1.1 From f3318c4549a63ed151577b0ee0742440f780e4ca Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 28 Aug 2016 03:43:09 +0200 Subject: yeah, this one too --- assets/backgrounds/menu.png | Bin 0 -> 13640 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 assets/backgrounds/menu.png diff --git a/assets/backgrounds/menu.png b/assets/backgrounds/menu.png new file mode 100644 index 0000000..9be3233 Binary files /dev/null and b/assets/backgrounds/menu.png differ -- cgit v1.1 From 96b4407ae6410affd0db1e6d6d657d4f65d32235 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 28 Aug 2016 20:41:48 +0200 Subject: No blinking; buttons enabled/disabled --- button.lua | 17 +++++------------ config/menuhost.lua | 3 +++ config/menumain.lua | 12 ++++++------ config/menuselect.lua | 8 ++++++-- selector.lua | 2 ++ 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/button.lua b/button.lua index 4b397cf..c5681b2 100644 --- a/button.lua +++ b/button.lua @@ -9,8 +9,7 @@ Button = { sprite, quads, delay = 2, - blinker = 1, - parent + parent, } function Button:new(parent) @@ -39,9 +38,7 @@ function Button:blur() self.focused = false end function Button:active() end -function Button:blink() - self.blinker = 0 -end +function Button:isEnabled() return true end function Button:set(name, func) if type(name) == "string" and type(func) == "function" then self[name] = func @@ -50,13 +47,12 @@ function Button:set(name, func) end function Button:draw(scale) local x,y = self:getPosition() - local blinker = math.floor(self.blinker*4) local quad = self.quads local sprite = self.sprite - if blinker%2 == 0 then + if self:isEnabled() then love.graphics.setColor(255, 255, 255, 255) else - love.graphics.setColor(255, 100, 100, 255) + love.graphics.setColor(140, 140, 140, 255) end love.graphics.draw(sprite, quad.button.normal, x*scale, y*scale, 0, scale, scale) if self.focused then @@ -71,12 +67,9 @@ function Button:update(dt) if self.delay > Button.delay then -- Button.delay is initial self.delay = self.delay - Button.delay end - if self.blinker < Button.blinker then -- Button.blink is initial - self.blinker = self.blinker + dt - end end function Button:controlpressed(set, action, key) - if action == "attack" and self.focused then + if action == "attack" and self.focused and self:isEnabled() then self:active() end end diff --git a/config/menuhost.lua b/config/menuhost.lua index 6e52482..487b75f 100644 --- a/config/menuhost.lua +++ b/config/menuhost.lua @@ -24,6 +24,9 @@ return { button:new(menu) :setText("Select") :setPosition(bx,101) + :set("isEnabled", function () + return map_selector:isLocked() + end) :set("active", function (self) MAP = map_selector:getFullSelection(true)[1][1] self.parent:load("menuselect") diff --git a/config/menumain.lua b/config/menumain.lua index 2ca2c59..e1bd89f 100644 --- a/config/menumain.lua +++ b/config/menumain.lua @@ -18,22 +18,22 @@ return { button:new(menu) :setText("Join") :setPosition(bx, 96) - :set("active", function (self) - self:blink() + :set("isEnabled", function (self) + return false end) , button:new(menu) :setText("Settings") :setPosition(bx, 112) - :set("active", function (self) - self:blink() + :set("isEnabled", function (self) + return false end) , button:new(menu) :setText("Credits") :setPosition(bx, 128) - :set("active", function (self) - self:blink() + :set("isEnabled", function (self) + return false end) , button:new(menu) diff --git a/config/menuselect.lua b/config/menuselect.lua index 31cf02e..c79396c 100644 --- a/config/menuselect.lua +++ b/config/menuselect.lua @@ -24,12 +24,16 @@ return { start_button :setText("Force start") :setPosition(bx,134) + :set("isEnabled", function () + if #naut_selector:getFullSelection(false) > 1 then + return true + end + return false + end) :set("active", function (self) local nauts = naut_selector:getFullSelection(false) if #nauts > 1 then changeScene(World:new(MAP, nauts)) - else - self:blink() end end) , diff --git a/selector.lua b/selector.lua index f382bbb..75c0190 100644 --- a/selector.lua +++ b/selector.lua @@ -136,11 +136,13 @@ end -- Check if given number is locked function Selector:isLocked(n) + local n = n or 1 return self.locks[n] end -- Get value of selection of given number function Selector:getSelection(n) + local n = n or 1 return self.selections[n] end -- cgit v1.1 From 7a1facacf70c37d6ed2b17c2979744ef2fe8375e Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 28 Aug 2016 21:15:57 +0200 Subject: readability improved --- selector.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/selector.lua b/selector.lua index 75c0190..de20699 100644 --- a/selector.lua +++ b/selector.lua @@ -202,10 +202,15 @@ function Selector:drawBlock(n, x, y, scale) love.graphics.draw(sprite, quad[self.shape].active, x*scale, y*scale, 0, scale, scale) end love.graphics.draw(icon, iconq, (x+2)*scale, (y+3)*scale, 0, scale, scale) - if self.focused and not locked then + if self.focused then local dy = (h-6)/2 - love.graphics.draw(sprite, quad.arrow_l, (x+0-2-math.floor(self.delay))* scale, (y+dy)*scale, 0, scale, scale) - love.graphics.draw(sprite, quad.arrow_r, (x+w-4+math.floor(self.delay))*scale, (y+dy)*scale, 0, scale, scale) + if not locked then + love.graphics.draw(sprite, quad.arrow_l, (x+0-2-math.floor(self.delay))* scale, (y+dy)*scale, 0, scale, scale) + love.graphics.draw(sprite, quad.arrow_r, (x+w-4+math.floor(self.delay))*scale, (y+dy)*scale, 0, scale, scale) + else + love.graphics.draw(sprite, quad.arrow_r, (x+0-2-math.floor(self.delay))* scale, (y+dy)*scale, 0, scale, scale) + love.graphics.draw(sprite, quad.arrow_l, (x+w-4+math.floor(self.delay))*scale, (y+dy)*scale, 0, scale, scale) + end end if (self:getSelection(n) ~= 1 or self.first) then love.graphics.setFont(Font) -- cgit v1.1 From adb0938f960312fef6f73640526e94d9bd3ce4ba Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 28 Aug 2016 23:48:31 +0200 Subject: Credits menu --- config/menucredits.lua | 24 ++++++++++++++++++++++++ config/menumain.lua | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 config/menucredits.lua diff --git a/config/menucredits.lua b/config/menucredits.lua new file mode 100644 index 0000000..975c962 --- /dev/null +++ b/config/menucredits.lua @@ -0,0 +1,24 @@ +local menu = ... + +local button = require "button" +local element = require "element" + +local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() +local bx = width/2-29 + +return { + button:new(menu) + :setText("Go back") + :setPosition(bx,144) + :set("active", function (self) + self.parent:load("menumain") + end) + , + element:new(menu) + :setPosition(width/2, 30) + :set("draw", function (self, scale) + local x,y = self:getPosition() + love.graphics.printf("The year is 3587. Conflict spans the stars as huge robot armies are locked in an enduring stalemate. In their bid for galactic supremacy, they call upon the most powerful group of mercenaries in the universe: the Awesomenauts!", (x-100)*scale, (y+10)*scale, 200, "center", 0, scale, scale) + end) + , +} \ No newline at end of file diff --git a/config/menumain.lua b/config/menumain.lua index e1bd89f..70666b3 100644 --- a/config/menumain.lua +++ b/config/menumain.lua @@ -32,8 +32,8 @@ return { button:new(menu) :setText("Credits") :setPosition(bx, 128) - :set("isEnabled", function (self) - return false + :set("active", function (self) + self.parent:load("menucredits") end) , button:new(menu) -- cgit v1.1 From e255f06e02b680442630fe2f6282c791e5acfd58 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 12 Sep 2016 10:59:25 +0200 Subject: draw only alive players --- player.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/player.lua b/player.lua index b2a73d8..53f138c 100644 --- a/player.lua +++ b/player.lua @@ -286,6 +286,8 @@ end -- Draw of `Player` function Player:draw(offset_x, offset_y, scale, debug) + -- draw only alive + if not self.alive then return end -- locals local offset_x = offset_x or 0 local offset_y = offset_y or 0 -- cgit v1.1 From 01304063655a31e102f312f6293e7aa4c7582d3f Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 13 Sep 2016 15:38:37 +0200 Subject: Text changes --- config/menucredits.lua | 2 +- config/menuhost.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/menucredits.lua b/config/menucredits.lua index 975c962..9d38da4 100644 --- a/config/menucredits.lua +++ b/config/menucredits.lua @@ -18,7 +18,7 @@ return { :setPosition(width/2, 30) :set("draw", function (self, scale) local x,y = self:getPosition() - love.graphics.printf("The year is 3587. Conflict spans the stars as huge robot armies are locked in an enduring stalemate. In their bid for galactic supremacy, they call upon the most powerful group of mercenaries in the universe: the Awesomenauts!", (x-100)*scale, (y+10)*scale, 200, "center", 0, scale, scale) + love.graphics.printf("A game by the Awesomenauts community including:\nSeltzy, PlasmaWisp, ParaDoX, MilkingChicken, Burningdillo, Bronkey and Aki.\n\n04font was used.\n\nBased on a game by Jan Willem Nijman, Paul Veer and Bits_Beats XOXO.\n\nAwesomenauts is property of Ronimo Games.", (x-110)*scale, (y+10)*scale, 220, "left", 0, scale, scale) end) , } \ No newline at end of file diff --git a/config/menuhost.lua b/config/menuhost.lua index 487b75f..bd7a3b9 100644 --- a/config/menuhost.lua +++ b/config/menuhost.lua @@ -22,7 +22,7 @@ return { :init() , button:new(menu) - :setText("Select") + :setText("Next") :setPosition(bx,101) :set("isEnabled", function () return map_selector:isLocked() -- cgit v1.1 From 92c040a9c0104623b19f8f5d6590a260190b4492 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 30 Sep 2016 16:35:05 +0200 Subject: Added Settings module scrap --- controller.lua | 2 -- main.lua | 6 ++++-- settings.lua | 8 ++++++++ 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 settings.lua diff --git a/controller.lua b/controller.lua index fde63c1..b56bd32 100644 --- a/controller.lua +++ b/controller.lua @@ -160,8 +160,6 @@ end -- Load gamepad mappings from db file and init module function Controller.load() love.joystick.loadGamepadMappings("gamecontrollerdb.txt") - Controller.registerSet("left", "right", "up", "down", "return", "rshift") - Controller.registerSet("a", "d", "w", "s", "g", "h") end -- Create new sets when new joystick is added diff --git a/main.lua b/main.lua index 8c6eb8e..ab1c755 100644 --- a/main.lua +++ b/main.lua @@ -39,6 +39,7 @@ require "camera" require "menu" require "controller" require "music" +require "settings" -- Temporary debug debug = false @@ -53,8 +54,9 @@ function love.load() Bold = love.graphics.newImageFont("assets/font-big.png", " 0123456789AEFILNORSTUW", -2) Font:setLineHeight(9/16) love.graphics.setFont(Font) - -- Controller + -- Modules Controller.load() + Settings.load() -- Scene Scene = Menu:new() end @@ -84,7 +86,7 @@ function Controller.controlpressed(set, action, key) -- pass to current Scene Scene:controlpressed(set, action, key) -- globals - if key == "escape" or key == "f1" then + if key == "escape" then love.event.quit() end if key == "f5" then diff --git a/settings.lua b/settings.lua new file mode 100644 index 0000000..0a31b41 --- /dev/null +++ b/settings.lua @@ -0,0 +1,8 @@ +Settings = {} + +function Settings.load() + if Controller then + Controller.registerSet("left", "right", "up", "down", "return", "rshift") + Controller.registerSet("a", "d", "w", "s", "g", "h") + end +end \ No newline at end of file -- cgit v1.1 From 39a4c99468b5f02730f02fb910af12d66e156c67 Mon Sep 17 00:00:00 2001 From: nthirtyone Date: Thu, 6 Oct 2016 13:58:42 +0200 Subject: Fixed music deletion on menu deletion --- menu.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/menu.lua b/menu.lua index bd04215..7771f39 100644 --- a/menu.lua +++ b/menu.lua @@ -40,7 +40,9 @@ function Menu:new(name) o.music = Music:new("menu.ogg") return o end -function Menu:delete() end +function Menu:delete() + self.music:delete() +end -- Load menu from file function Menu:load(name) -- cgit v1.1 From bdc2e0ee9420eaf99ad9502ad061f124e17e00b8 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Oct 2016 14:05:56 +0200 Subject: New empty menu for settings --- config/menusettings.lua | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 config/menusettings.lua diff --git a/config/menusettings.lua b/config/menusettings.lua new file mode 100644 index 0000000..fc7d62e --- /dev/null +++ b/config/menusettings.lua @@ -0,0 +1,7 @@ +local menu = ... + +local button = require "button" +local selector = require "selector" + +local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() +local bx = width/2-29 -- cgit v1.1 From 9f1854ed3365eacec0b49017d619eb02ab0f52fb Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Oct 2016 14:21:28 +0200 Subject: Fixed debug information displaying with wrong font --- main.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.lua b/main.lua index ab1c755..93d0408 100644 --- a/main.lua +++ b/main.lua @@ -67,6 +67,7 @@ function love.draw() Scene:draw() if debug then local scale = getScale() + love.graphics.setFont(Font) love.graphics.setColor(255, 0, 0, 255) love.graphics.print("Debug ON", 10, 10, 0, scale, scale) love.graphics.setColor(255, 255, 255, 255) @@ -96,6 +97,4 @@ end function Controller.controlreleased(set, action, key) -- pass to current Scene Scene:controlreleased(set, action, key) -end - - +end \ No newline at end of file -- cgit v1.1 From 35262a7245bcd9ebf937d07ab3326655d96e5d2e Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Oct 2016 14:43:11 +0200 Subject: Fixed scaling of fullscreen menu in different ratios --- config/menuhost.lua | 2 +- config/menumain.lua | 6 +++--- config/menuselect.lua | 2 +- config/menusettings.lua | 10 ++++++++++ menu.lua | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/config/menuhost.lua b/config/menuhost.lua index bd7a3b9..af7dad1 100644 --- a/config/menuhost.lua +++ b/config/menuhost.lua @@ -28,7 +28,7 @@ return { return map_selector:isLocked() end) :set("active", function (self) - MAP = map_selector:getFullSelection(true)[1][1] + MAP = map_selector:getFullSelection(true)[1][1] -- please, don't kill me for this, kek self.parent:load("menuselect") end) , diff --git a/config/menumain.lua b/config/menumain.lua index 70666b3..e312b51 100644 --- a/config/menumain.lua +++ b/config/menumain.lua @@ -4,7 +4,7 @@ local button = require "button" local header = require "header" local element = require "element" -local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() +local width, height = love.graphics.getWidth()/getScale(), love.graphics.getHeight()/getScale() local bx = width/2-29 return { @@ -25,8 +25,8 @@ return { button:new(menu) :setText("Settings") :setPosition(bx, 112) - :set("isEnabled", function (self) - return false + :set("active", function (self) + self.parent:load("menusettings") end) , button:new(menu) diff --git a/config/menuselect.lua b/config/menuselect.lua index c79396c..19f46ab 100644 --- a/config/menuselect.lua +++ b/config/menuselect.lua @@ -4,7 +4,7 @@ local button = require "button" local selector = require "selector" local element = require "element" -local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() +local width, height = love.graphics.getWidth()/getScale(), love.graphics.getHeight()/getScale() local bx = width/2-29 local naut_selector = selector:new(menu) diff --git a/config/menusettings.lua b/config/menusettings.lua index fc7d62e..380828d 100644 --- a/config/menusettings.lua +++ b/config/menusettings.lua @@ -5,3 +5,13 @@ local selector = require "selector" local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() local bx = width/2-29 + +return { + button:new(menu) + :setText("Go back") + :setPosition(bx,117) + :set("active", function (self) + self.parent:load("menumain") + end) + , +} \ No newline at end of file diff --git a/menu.lua b/menu.lua index 7771f39..e24bc64 100644 --- a/menu.lua +++ b/menu.lua @@ -86,7 +86,7 @@ function Menu:update(dt) end function Menu:draw() local scale = self.scale - love.graphics.draw(self.background, 0, 0, 0, scale, scale) + love.graphics.draw(self.background, 0, 0, 0, getRealScale(), getRealScale()) love.graphics.setFont(Font) for _,element in pairs(self.elements) do element:draw(scale) -- cgit v1.1 From 82f0f11c9098da300439f62fdd175b6699fd150c Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Oct 2016 14:45:05 +0200 Subject: Oops! --- config/menuhost.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/menuhost.lua b/config/menuhost.lua index af7dad1..710839d 100644 --- a/config/menuhost.lua +++ b/config/menuhost.lua @@ -3,7 +3,7 @@ local menu = ... local button = require "button" local selector = require "selector" -local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() +local width, height = love.graphics.getWidth()/getScale(), love.graphics.getHeight()/getScale() local bx = width/2-29 local map_selector = selector:new(menu) -- cgit v1.1 From 1a7dc6c7b9e36872a5ad45122aa5f34f532ed7ab Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 10 Oct 2016 12:02:18 +0200 Subject: Identity added --- conf.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/conf.lua b/conf.lua index 02212ae..94b5203 100644 --- a/conf.lua +++ b/conf.lua @@ -5,7 +5,8 @@ function love.conf(t) -- t.window.width = 320*3 -- t.window.height = 180*3 -- t.window.borderless = true + t.identity = "not-nautz" t.window.fullscreentype = "desktop" t.window.fullscreen = true t.console = false -end \ No newline at end of file +end -- cgit v1.1 From 1f6f24ba4fb434ed76fb118a21f7492a1b678bc4 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 10 Oct 2016 17:37:36 +0200 Subject: Default settings file --- settings.default | 6 ++++++ settings.lua | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 settings.default diff --git a/settings.default b/settings.default new file mode 100644 index 0000000..6816116 --- /dev/null +++ b/settings.default @@ -0,0 +1,6 @@ +return { + {"left", "right", "up", "down", "return", "rshift", false}, + {"a", "d", "w", "s", "g", "h", false}, + {"axis:leftx-", "axis:leftx+", "axis:lefty-", "axis:lefty+", "a", "b", true}, + {"axis:leftx-", "axis:leftx+", "axis:lefty-", "axis:lefty+", "a", "b", true}, +} diff --git a/settings.lua b/settings.lua index 0a31b41..5b0e38a 100644 --- a/settings.lua +++ b/settings.lua @@ -5,4 +5,5 @@ function Settings.load() Controller.registerSet("left", "right", "up", "down", "return", "rshift") Controller.registerSet("a", "d", "w", "s", "g", "h") end -end \ No newline at end of file + print(love.filesystem.getIdentity(), love.filesystem.exists("settings.lua")) +end -- cgit v1.1 From 26199823381c0a9ee81a8eddde1d8c093c101685 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 10 Oct 2016 22:08:17 +0200 Subject: Yeah, makefile --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5eee011 --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +all: + zip not-nautz maps/*.lua config/*.lua assets/*.png assets/sounds/*.ogg assets/platforms/*.png assets/nauts/*.png assets/music/*.ogg assets/decorations/*.png assets/backgrounds/*.png *.lua gamecontrollerdb.txt settings.default + mv not-nautz.zip ../not-nautz.love + +clean: + $(RM) ../not-nautz.love \ No newline at end of file -- cgit v1.1 From 7e567d1fc37d8e65e4e8fe5c7ece2cea8a6567b1 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 10 Oct 2016 22:33:34 +0200 Subject: Load controller sets from file --- controller.lua | 5 ----- main.lua | 1 - settings.lua | 18 +++++++++++++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/controller.lua b/controller.lua index b56bd32..e435d63 100644 --- a/controller.lua +++ b/controller.lua @@ -162,11 +162,6 @@ function Controller.load() love.joystick.loadGamepadMappings("gamecontrollerdb.txt") end --- Create new sets when new joystick is added -function Controller.joystickadded(joystick) - Controller.registerSet("axis:leftx-", "axis:leftx+", "axis:lefty-", "axis:lefty+", "a", "b", joystick) -end - -- Gamepad input callbacks function Controller.gamepadaxis(joystick, axis, value) if value ~= 0 then diff --git a/main.lua b/main.lua index 93d0408..3e28d90 100644 --- a/main.lua +++ b/main.lua @@ -75,7 +75,6 @@ function love.draw() end end -- Pass input to Controller -function love.joystickadded(joystick) Controller.joystickadded(joystick) end function love.gamepadaxis(joystick, axis, value) Controller.gamepadaxis(joystick, axis, value) end function love.gamepadpressed(joystick, key) Controller.gamepadpressed(joystick, key) end function love.gamepadreleased(joystick, key) Controller.gamepadreleased(joystick, key) end diff --git a/settings.lua b/settings.lua index 5b0e38a..920abdf 100644 --- a/settings.lua +++ b/settings.lua @@ -2,8 +2,20 @@ Settings = {} function Settings.load() if Controller then - Controller.registerSet("left", "right", "up", "down", "return", "rshift") - Controller.registerSet("a", "d", "w", "s", "g", "h") + if not love.filesystem.exists("settings") then + local def = love.filesystem.newFile("settings.default") + local new = love.filesystem.newFile("settings") + new:open("w") def:open("r") + new:write(def:read()) + new:close() def:close() + end + local getSettings = love.filesystem.load("settings") + for _,set in pairs(getSettings()) do + local isJoystick = set[7] + if isJoystick then + -- Add first free joystick from joysticks list + end + Controller.registerSet(set[1], set[2], set[3], set[4], set[5], set[6], joystick) + end end - print(love.filesystem.getIdentity(), love.filesystem.exists("settings.lua")) end -- cgit v1.1 From 941d0214a4a1b499190f4f3c6133b5e512d897fe Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 10 Oct 2016 22:42:58 +0200 Subject: Add joystick controllers only if js present --- settings.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/settings.lua b/settings.lua index 920abdf..93432a0 100644 --- a/settings.lua +++ b/settings.lua @@ -12,10 +12,14 @@ function Settings.load() local getSettings = love.filesystem.load("settings") for _,set in pairs(getSettings()) do local isJoystick = set[7] + local joystick if isJoystick then + joystick = love.joystick.getJoysticks()[1] -- Add first free joystick from joysticks list end - Controller.registerSet(set[1], set[2], set[3], set[4], set[5], set[6], joystick) + if not isJoystick or joystick then + Controller.registerSet(set[1], set[2], set[3], set[4], set[5], set[6], joystick) + end end end end -- cgit v1.1 From 73bcd524906c51d43b22b3ea68c64b38f130bea6 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 20 Dec 2016 06:02:05 +0100 Subject: I have no idea why I have put everything in one commit --- config/menusettings.lua | 96 +++++++++++++++++++++++++++++++++++++++++++++++-- main.lua | 3 ++ menu.lua | 19 ++++++---- settings.lua | 46 +++++++++++++++++++++--- 4 files changed, 151 insertions(+), 13 deletions(-) diff --git a/config/menusettings.lua b/config/menusettings.lua index 380828d..1b19e84 100644 --- a/config/menusettings.lua +++ b/config/menusettings.lua @@ -2,16 +2,106 @@ local menu = ... local button = require "button" local selector = require "selector" +local element = require "element" local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() local bx = width/2-29 -return { +local keys = {"Left", "Right", "Up", "Down", "Attack", "Jump"} + +local dimmer = element:new(menu) + :setPosition(width/2, 15) + :set("visible", false) + :set("currentControl", "Left") + :set("draw", function (self, scale) + if self.visible then + love.graphics.setColor(0, 0, 0, 210) + love.graphics.rectangle("fill",0,0,width*getRealScale(),height*getRealScale()) + love.graphics.setColor(120, 255, 120, 255) + love.graphics.printf("Press new key for: \n> " .. self.currentControl .. " <", (width/2-110)*scale, (height/2-4)*scale, 220, "center", 0, scale, scale) + love.graphics.setColor(255, 255, 255, 255) + end + end) + +-- CHANGER functions +local isEnabled = function (self) + if Controller.getSets()[self.setNumber()] and not self.inProgress then + return true + else + return false + end +end +local startChange = function (self) + dimmer:set("visible", true):set("currentControl", "Left") + self.parent.allowMove = false + self.inProgress = true + self.currentKey = 0 + self.newSet = {} +end +local controlreleased = function(self, set, action, key) + if self.inProgress then + if self.currentKey > 0 and self.currentKey < 7 then + table.insert(self.newSet, key) + dimmer:set("currentControl", keys[self.currentKey+1]) + end + if self.currentKey > 5 then + dimmer:set("visible", false) + self.parent.allowMove = true + self.inProgress = false + table.insert(self.newSet, Controller.sets[self.setNumber()][7]) + print(self.newSet[7]) + Settings.change(self.setNumber(), self.newSet[1], self.newSet[2], self.newSet[3], self.newSet[4], self.newSet[5], self.newSet[6], self.newSet[7]) + else + self.currentKey = self.currentKey + 1 + end + end +end + +local a = { + button:new(menu) + :setText("Keyboard 1") + :setPosition(bx,80) + :set("setNumber", function () return 1 end) + :set("isEnabled", isEnabled) + :set("controlreleased", controlreleased) + :set("stopChange", stopChange) + :set("active", startChange) + , + button:new(menu) + :setText("Keyboard 2") + :setPosition(bx,96) + :set("setNumber", function () return 2 end) + :set("isEnabled", isEnabled) + :set("controlreleased", controlreleased) + :set("stopChange", stopChange) + :set("active", startChange) + , + button:new(menu) + :setText("Gamepad 1") + :setPosition(bx,112) + :set("setNumber", function () return 3 end) + :set("isEnabled", isEnabled) + :set("controlreleased", controlreleased) + :set("stopChange", stopChange) + :set("active", startChange) + , + button:new(menu) + :setText("Gamepad 2") + :setPosition(bx,128) + :set("setNumber", function () return 4 end) + :set("isEnabled", isEnabled) + :set("controlreleased", controlreleased) + :set("stopChange", stopChange) + :set("active", startChange) + , button:new(menu) :setText("Go back") - :setPosition(bx,117) + :setPosition(bx,144) :set("active", function (self) self.parent:load("menumain") end) , -} \ No newline at end of file + dimmer +} + +return a \ No newline at end of file diff --git a/main.lua b/main.lua index 3e28d90..deff1a1 100644 --- a/main.lua +++ b/main.lua @@ -74,6 +74,9 @@ function love.draw() love.graphics.print("Current FPS: "..tostring(love.timer.getFPS()), 10, 10+9*scale, 0, scale, scale) end end +function love.quit() + Settings.save() +end -- Pass input to Controller function love.gamepadaxis(joystick, axis, value) Controller.gamepadaxis(joystick, axis, value) end function love.gamepadpressed(joystick, key) Controller.gamepadpressed(joystick, key) end diff --git a/menu.lua b/menu.lua index e24bc64..b72ea09 100644 --- a/menu.lua +++ b/menu.lua @@ -12,6 +12,7 @@ Menu = { music, sprite, background, + allowMove = true, quads = { button = { normal = love.graphics.newQuad(0, 0, 58,15, 80,130), @@ -95,14 +96,20 @@ end -- Controller callbacks function Menu:controlpressed(set, action, key) - if action == "down" then - self:next() - end - if action == "up" then - self:previous() + if self.allowMove then + if action == "down" then + self:next() + end + if action == "up" then + self:previous() + end end for _,element in pairs(self.elements) do element:controlpressed(set, action, key) end end -function Menu:controlreleased(set, action, key) end \ No newline at end of file +function Menu:controlreleased(set, action, key) + for _,element in pairs(self.elements) do + element:controlreleased(set, action, key) + end +end \ No newline at end of file diff --git a/settings.lua b/settings.lua index 93432a0..ad8b8e5 100644 --- a/settings.lua +++ b/settings.lua @@ -1,5 +1,5 @@ Settings = {} - +Settings.current = {} function Settings.load() if Controller then if not love.filesystem.exists("settings") then @@ -10,12 +10,15 @@ function Settings.load() new:close() def:close() end local getSettings = love.filesystem.load("settings") - for _,set in pairs(getSettings()) do + Settings.current = getSettings() + local joysticksList = love.joystick.getJoysticks() -- local list for editing + for _,set in pairs(Settings.current) do local isJoystick = set[7] local joystick if isJoystick then - joystick = love.joystick.getJoysticks()[1] - -- Add first free joystick from joysticks list + -- take and remove first joystick from list + joystick = joysticksList[1] + table.remove(joysticksList, 1) end if not isJoystick or joystick then Controller.registerSet(set[1], set[2], set[3], set[4], set[5], set[6], joystick) @@ -23,3 +26,38 @@ function Settings.load() end end end +function Settings.save() + local new = love.filesystem.newFile("settings") + local sets = Settings.current + local string = "return {\n" + for i,set in pairs(sets) do + string = string .. "\t{" + for j,word in pairs(set) do + if j ~= 7 then + string = string .. "\"" .. word .. "\", " + else + if word then + string = string .. "true" + else + string = string .. "false" + end + end + end + string = string .. "},\n" + end + string = string .. "}" + new:open("w") + new:write(string) + new:close() +end +function Settings.change(n, left, right, up, down, attack, jump, joystick) + local bool + if joystick then + bool = true + else + bool = false + end + Settings.current[n] = {left, right, up, down, attack, jump, bool} + table.remove(Controller.sets, n) + Controller.registerSet(left, right, up, down, attack, jump, joystick) +end \ No newline at end of file -- cgit v1.1