Commit 81cff213 authored by Aurel Wildfellner's avatar Aurel Wildfellner

brute force reset on main gameloop

parent 406b8a17
Pipeline #85 canceled with stages
......@@ -48,6 +48,7 @@ class GameState:
HOLDGAME = "wait"
SETUPRALLY = "setuprally"
RALLY = "rally"
GAMEEND = "gameend"
class PongGame:
......@@ -92,6 +93,7 @@ class PongGame:
self.controllers = []
for i, device in enumerate(devicepaths):
name = "reader" + str(i)
print("register controller:", name)
reader = KeyboardReader(device, name, self.rEvQueue)
self.controllers.append(reader)
reader.start()
......@@ -128,6 +130,9 @@ class PongGame:
self._rally()
return
if self.gameState == GameState.GAMEEND:
return
def _initGame(self):
self.menuText = ""
......@@ -159,6 +164,7 @@ class PongGame:
# handle events
for ev in self.rEvQueue.popAllEvents():
print(ev, ev.reader.name)
# handle a codescan
if (ev.etype == EventType.CODESCAN):
if (ev.code == PongConfig.barcodes["playerleft"]):
......@@ -251,10 +257,10 @@ class PongGame:
# end of rally?
if self.gamefield.ballLeftOut(self.ball):
self.leftPlayer.lifes -= 1
self.gameState = GameState.SETUPRALLY
self.gameState = GameState.GAMEEND
if self.gamefield.ballRightOut(self.ball):
self.rightPlayer.lifes -= 1
self.gameState = GameState.SETUPRALLY
self.gameState = GameState.GAMEEND
......@@ -264,14 +270,17 @@ def main():
utils.disableBarcodeKeyboards()
pg = PongGame()
if not pg.setupControllers():
print("Controller Error")
#exit(1)
while True:
pg.gameLoop()
pg = PongGame()
while True:
if pg.gameState == GameState.GAMEEND:
del pg
break
pg.gameLoop()
#TODO catch exceptions and stop barcode reader threads
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment