From cbde6f71bd7d4876d12f07bcc5ade6ef40314a6b Mon Sep 17 00:00:00 2001 From: Rene Hopf Date: Wed, 28 Dec 2011 13:08:28 +0100 Subject: [PATCH] Added r0cketlaunch0r game (cherry picked from commit 89a0b322e0b27d69e1ba9b7a46c43478196acd97) Signed-off-by: Stefan `Sec` Zehl --- tools/game/launch0r.py | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tools/game/launch0r.py diff --git a/tools/game/launch0r.py b/tools/game/launch0r.py new file mode 100644 index 0000000..b78d19f --- /dev/null +++ b/tools/game/launch0r.py @@ -0,0 +1,45 @@ +import r0ketrem0te.game +import time +import hid + +class Launch0r: + def __init__(self): + self.rem0te = r0ketrem0te.game.Game('/dev/cu.usbmodem411', "Launch0r", 83, 87, [ord(x) for x in 'REM0T'], 1, False) + self.rem0te.registerPlayerCallback(self.playercallback) + self.player = Rem0tePlayer(self.rem0te) + + def playercallback(self, action, player): + if action == 'added': + if self.player == None: + self.player.player = player + elif action == 'removed': + self.player = None + + def run(self): + self.player.launcher = hid.device(0x0a81, 0x0701) + self.player.launcher.set_nonblocking(1) + +class Rem0tePlayer(object): + def __init__(self, rem0te): + self.rem0te = rem0te + self.rem0te.bridge.registerCallback(self.receivedPacket) + self.player = None + self.launcher = None + + def receivedPacket(self, packet): + if packet.button == 0:#off + self.launcher.write([0x20, 0, 0]) + if packet.button == 4:#left + self.launcher.write([0x04, 0, 0]) + if packet.button == 8:#right + self.launcher.write([0x08, 0, 0]) + if packet.button == 1:#up + self.launcher.write([0x02, 0, 0]) + if packet.button == 2:#down + self.launcher.write([0x01, 0, 0]) + if packet.button == 16:#fire + self.launcher.write([0x10, 0, 0]) + +if __name__ == '__main__': + launch0r = Launch0r() + launch0r.run()