summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-08-14 22:41:13 +0200
committerAki <nthirtyone@gmail.com>2016-08-14 22:41:13 +0200
commit49c6cd2edf399313f2204530ce4285299a9b6858 (patch)
treeafe62f1543e98f4273d2bb6045bc27d46acf1636
parent3038bd171700d91e56a4050943925a02f5b1eda6 (diff)
downloadroflnauts-49c6cd2edf399313f2204530ce4285299a9b6858.zip
roflnauts-49c6cd2edf399313f2204530ce4285299a9b6858.tar.gz
roflnauts-49c6cd2edf399313f2204530ce4285299a9b6858.tar.bz2
Controller callbacks
-rw-r--r--controller.lua38
-rw-r--r--main.lua2
-rw-r--r--menu.lua92
-rw-r--r--world.lua15
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
diff --git a/main.lua b/main.lua
index a35110a..a708ecb 100644
--- a/main.lua
+++ b/main.lua
@@ -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
diff --git a/menu.lua b/menu.lua
index cea9c81..157fa8e 100644
--- a/menu.lua
+++ b/menu.lua
@@ -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
diff --git a/world.lua b/world.lua
index 8ee27fe..735f854 100644
--- a/world.lua
+++ b/world.lua
@@ -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