summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-08-14 23:00:13 +0200
committerAki <nthirtyone@gmail.com>2016-08-14 23:00:13 +0200
commit1f4b5642739f18185b026a5ad95d66680c8b76c9 (patch)
tree362d27262e6afe86f62fa8abf2765af98b654ee1
parent49c6cd2edf399313f2204530ce4285299a9b6858 (diff)
downloadroflnauts-1f4b5642739f18185b026a5ad95d66680c8b76c9.zip
roflnauts-1f4b5642739f18185b026a5ad95d66680c8b76c9.tar.gz
roflnauts-1f4b5642739f18185b026a5ad95d66680c8b76c9.tar.bz2
Testing callbacks successfully
-rw-r--r--controller.lua36
-rw-r--r--menu.lua9
2 files changed, 18 insertions, 27 deletions
diff --git a/controller.lua b/controller.lua
index 971b83b..f49b839 100644
--- a/controller.lua
+++ b/controller.lua
@@ -4,10 +4,9 @@
-- Rather than that use functions provided by this module: `Controller.controlpressed` and `Controller.controlreleased`.
-- For information on additional functions, look below.
--- Metatable
-Controller = {
- sets = {}
-}
+-- Namespace
+Controller = {}
+Controller.sets = {}
-- Declared to avoid calling nil. Be sure to define yours after this line is performed.
function Controller.controlpressed(set, action, key) end
@@ -23,6 +22,7 @@ function Controller.registerSet(left, right, up, down, attack, jump, joystick)
set.attack = attack or "return"
set.jump = jump or "rshift"
table.insert(Controller.sets, set)
+ print(set, left, right, up, down, attack, jump, joystick)
return set
end
@@ -41,23 +41,19 @@ end
function Controller.testControl(set, key, joystick)
-- First test if it is joystick and if it is correct one
if joystick == set.joystick then
- if control == set.left then
+ if key == set.left then
return "left"
- elseif control == set.right then
+ elseif key == set.right then
return "right"
- elseif control == set.up then
+ elseif key == set.up then
return "up"
- elseif control == set.down then
+ elseif key == set.down then
return "down"
- elseif control == set.attack then
+ elseif key == set.attack then
return "attack"
- elseif control == set.jump then
+ elseif key == set.jump then
return "jump"
- else
- return nil
end
- else
- return nil
end
end
@@ -69,24 +65,24 @@ end
-- Gamepad input callbacks
function Controller.gamepadpressed(joystick, button)
- print(button, "pressed")
local set, action, key = Controller.testSets(button, joystick)
+ print("Pressed:", set, action, key)
Controller.controlpressed(set, action, key)
end
function Controller.gamepadreleased(joystick, button)
- print(button, "released")
local set, action, key = Controller.testSets(button, joystick)
+ print("Released:", set, action, key)
Controller.controlreleased(set, action, key)
end
-- Keyboard input callbacks
function Controller.keypressed(button)
- print(button, "pressed")
- local set, action, key = Controller.testSets(button)
+ local set, action, key = Controller.testSets(button, nil)
+ print("Pressed:", set, action, key)
Controller.controlpressed(set, action, key)
end
function Controller.keyreleased(button)
- print(button, "released")
- local set, action, key = Controller.testSets(button)
+ local set, action, key = Controller.testSets(button, nil)
+ print("Released:", set, action, key)
Controller.controlreleased(set, action, key)
end \ No newline at end of file
diff --git a/menu.lua b/menu.lua
index 157fa8e..5b84f83 100644
--- a/menu.lua
+++ b/menu.lua
@@ -197,11 +197,6 @@ function Menu:startGame()
changeScene(world)
end
--- Controllers stuff
-function Menu:assignController(controller)
- controller:setParent(self)
-end
-
-- Controller callbacks
function Menu:controlpressed(set, action, key)
-- assign to character selection
@@ -212,14 +207,14 @@ function Menu:controlpressed(set, action, key)
end
end
-- map selection chaos!
- if control == "left" then
+ if action == "left" then
if self.map ~= 1 then
self.map = self.map - 1
else
self.map = #self.maplist
end
end
- if control == "right" then
+ if action == "right" then
if self.map ~= #self.maplist then
self.map = self.map + 1
else