Skip to content

Instantly share code, notes, and snippets.

@MarcScott
Created May 12, 2021 17:10
Show Gist options
  • Save MarcScott/17df0add820563fa779b93970db6a505 to your computer and use it in GitHub Desktop.
Save MarcScott/17df0add820563fa779b93970db6a505 to your computer and use it in GitHub Desktop.
Surrogate.tv buggy starter
import logging
from gpiozero import Robot
from time import sleep
from surrortg import Game
from surrortg.inputs import Joystick
#robot = Robot(left=(19, 26), right=(6, 13))
class MyJoystick(Joystick):
def __init__(self, score_cb):
# Store reference to score callback function
self.score_cb = score_cb
# Set up the robot
self.robot = Robot(left=(19, 26), right=(6, 13))
async def handle_coordinates(self, x, y, seat=0):
#Handle robot directions
async def reset(self, seat=0):
#Stop the robot when the game ends
self.robot.stop()
logging.info(f"reset")
class Run_Buggy(Game):
def update_score(self):
self.score += 1
logging.info(f"score: {self.score}")
if self.score >= 10:
# End game by sending final no of moves to game engine.
self.io.send_score(score=self.score, final_score=True)
# Disable all registered inputs.
self.io.disable_inputs()
else:
# Send updated score to game engine.
self.io.send_score(score=self.score)
async def on_init(self):
self.io.register_inputs({"joystick_main":MyJoystick(self.update_score)})
async def on_prepare(self):
# Set score to 0 before game starts
self.score = 0
if __name__ == "__main__":
# Start running the game
Run_Buggy().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment