diff options
-rw-r--r-- | controller.lua | 38 | ||||
-rw-r--r-- | main.lua | 2 | ||||
-rw-r--r-- | menu.lua | 92 | ||||
-rw-r--r-- | world.lua | 15 |
4 files changed, 74 insertions, 73 deletions
diff --git a/controller.lua b/controller.lua index 88751a2..971b83b 100644 --- a/controller.lua +++ b/controller.lua @@ -70,37 +70,23 @@ end -- Gamepad input callbacks function Controller.gamepadpressed(joystick, button) print(button, "pressed") - for _,controller in pairs(Controllers) do - controller:gamepadpressed(joystick, button) - end + local set, action, key = Controller.testSets(button, joystick) + Controller.controlpressed(set, action, key) end function Controller.gamepadreleased(joystick, button) print(button, "released") - for _,controller in pairs(Controllers) do - controller:gamepadreleased(joystick, button) - end + local set, action, key = Controller.testSets(button, joystick) + Controller.controlreleased(set, action, key) end -- Keyboard input callbacks -function Controller.keypressed(key) - print(key, "pressed") - for _,controller in pairs(Controllers) do - controller:keypressed(key) - end - - if key == "f6" and debug then - local map = Scene:getMapName() - local nauts = {} - for _,naut in pairs(Scene:getNautsAll()) do - table.insert(nauts, {naut.name, naut.controller}) - end - local new = World:new(map, nauts) - changeScene(new) - end +function Controller.keypressed(button) + print(button, "pressed") + local set, action, key = Controller.testSets(button) + Controller.controlpressed(set, action, key) end -function Controller.keyreleased(key) - print(key, "released") - for _,controller in pairs(Controllers) do - controller:keyreleased(key) - end +function Controller.keyreleased(button) + print(button, "released") + local set, action, key = Controller.testSets(button) + Controller.controlreleased(set, action, key) end
\ No newline at end of file @@ -87,7 +87,7 @@ function love.keyreleased(key) Controller.keyreleased(key) end function Controller.controlpressed(set, action, key) -- pass to current Scene Scene:controlpressed(set, action, key) - -- global quit + -- globals if key == "escape" or key == "f1" then love.event.quit() end @@ -107,6 +107,31 @@ function Menu:getBounce(f) return math.sin(self.header_move*f*math.pi) end +-- Update +function Menu:update(dt) + local state = true + if self:getSelectorsNumberActive() > 1 then + for _,selector in pairs(self:getSelectorsActive()) do + state = state and selector.state + end + else + state = false + end + if state then + self.countdown = self.countdown - dt + else + self.countdown = Menu.countdown -- Menu.countdown is initial + end + if state and 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:draw() -- locals @@ -135,31 +160,6 @@ function Menu:draw() end end --- Upadte -function Menu:update(dt) - local state = true - if self:getSelectorsNumberActive() > 1 then - for _,selector in pairs(self:getSelectorsActive()) do - state = state and selector.state - end - else - state = false - end - if state then - self.countdown = self.countdown - dt - else - self.countdown = Menu.countdown -- Menu.countdown is initial - end - if state and 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 - -- Speed up countdown function Menu:countdownJump() if self.countdown ~= Menu.countdown then -- Menu.countdown is initial @@ -167,7 +167,7 @@ function Menu:countdownJump() end end --- +-- Called when selector is deactivated function Menu:unselectSelector(selector) local i = 0 for _,v in pairs(self:getSelectorsActive()) do @@ -182,12 +182,28 @@ function Menu:unselectSelector(selector) end end --- Controllers +-- Get table of nauts currently selected by active selectors +function Menu:getNauts() + local nauts = {} + for _,selector in pairs(self:getSelectorsActive()) do + table.insert(nauts, {selector:getSelectionName(), selector:getController()}) + end + return nauts +end + +-- WARUDO +function Menu:startGame() + local world = World:new(self.maplist[self.map], self:getNauts()) + changeScene(world) +end + +-- Controllers stuff function Menu:assignController(controller) controller:setParent(self) end -function Menu:controllerPressed(control, controller) +-- Controller callbacks +function Menu:controlpressed(set, action, key) -- assign to character selection if control == "attack" then local selector = self:getSelectorsInactive()[1] @@ -211,21 +227,5 @@ function Menu:controllerPressed(control, controller) end end end - --- It just must be here -function Menu:controllerReleased(control, controller) -end - -function Menu:getNauts() - local nauts = {} - for _,selector in pairs(self:getSelectorsActive()) do - table.insert(nauts, {selector:getSelectionName(), selector:getController()}) - end - return nauts -end - --- WARUDO -function Menu:startGame() - local world = World:new(self.maplist[self.map], self:getNauts()) - changeScene(world) -end +function Menu:controlreleased(set, action, key) +end
\ No newline at end of file @@ -399,3 +399,18 @@ function World.endContact(a, b, coll) b:getUserData().inAir = true end end + +-- Controller callbacks +function World:controlpressed(set, action, key) + if key == "f6" and debug then + local map = self:getMapName() + local nauts = {} + for _,naut in pairs(self:getNautsAll()) do + table.insert(nauts, {naut.name, naut.controller}) + end + local new = World:new(map, nauts) + changeScene(new) + end +end +function World:controlreleased(set, action, key) +end
\ No newline at end of file |