def __init__(self): super().__init__() i2c = board.I2C() if i2c is not None: self._accelerometer = adafruit_lsm6ds.LSM6DS33(i2c) self._buttons = GamePad(digitalio.DigitalInOut(board.BUTTON_A), digitalio.DigitalInOut(board.BUTTON_B))
def __init__(self): super().__init__() self._buttons = GamePad( digitalio.DigitalInOut(board.BUTTON_O), digitalio.DigitalInOut(board.BUTTON_X), digitalio.DigitalInOut(board.BUTTON_Z), digitalio.DigitalInOut(board.BUTTON_RIGHT), digitalio.DigitalInOut(board.BUTTON_DOWN), digitalio.DigitalInOut(board.BUTTON_UP), digitalio.DigitalInOut(board.BUTTON_LEFT), )
class PewPewM4(PyBadgerBase): """Class that represents a single Pew Pew M4.""" _audio_out = audioio.AudioOut _neopixel_count = 0 def __init__(self): super().__init__() self._buttons = GamePad( digitalio.DigitalInOut(board.BUTTON_O), digitalio.DigitalInOut(board.BUTTON_X), digitalio.DigitalInOut(board.BUTTON_Z), digitalio.DigitalInOut(board.BUTTON_RIGHT), digitalio.DigitalInOut(board.BUTTON_DOWN), digitalio.DigitalInOut(board.BUTTON_UP), digitalio.DigitalInOut(board.BUTTON_LEFT), ) @property def button(self): """The buttons on the board. Example use: .. code-block:: python from adafruit_pybadger import pybadger while True: if pybadger.button.x: print("Button X") elif pybadger.button.o: print("Button O") """ button_values = self._buttons.get_pressed() return Buttons(*[ button_values & button for button in ( PyBadgerBase.BUTTON_B, PyBadgerBase.BUTTON_A, PyBadgerBase.BUTTON_START, PyBadgerBase.BUTTON_SELECT, PyBadgerBase.BUTTON_RIGHT, PyBadgerBase.BUTTON_DOWN, PyBadgerBase.BUTTON_UP, ) ]) @property def _unsupported(self): """This feature is not supported on PewPew M4.""" raise NotImplementedError( "This feature is not supported on PewPew M4.") # The following is a list of the features available in other PyBadger modules but # not available for CLUE. If called while using a CLUE, they will result in the # NotImplementedError raised in the property above. light = _unsupported acceleration = _unsupported pixels = _unsupported
class ManualController(object): def __init__(self, deadzone=0.08): self.deadzone = deadzone try: self.controller = GamePad() except: self.controller = None def connected(self): return self.controller is not None def manual_control(self): if not self.connected(): return False return self.controller.left_trigger > self.deadzone def get_yaw_power(self): if not self.connected(): return 0 x = self.controller.left_stick_x return x if self.manual_control() and abs(x) > self.deadzone else 0 def get_pitch_power(self): if not self.connected(): return 0 y = self.controller.right_stick_y return y if self.manual_control() and abs(y) > self.deadzone else 0 def get_fire(self): if not self.connected(): return False return self.manual_control( ) and self.controller.right_trigger > self.deadzone def get_frame(self): frame = Frame() frame.timestamp = millis() frame.manualOverride = self.manual_control() frame.pitchPower = self.get_pitch_power() frame.yawPower = self.get_yaw_power() frame.manualFire = self.get_fire() return frame def release(self): if self.connected(): self.controller.close()
def __init__(self): super().__init__() i2c = board.I2C() if i2c is not None: self._accelerometer = adafruit_lsm6ds.LSM6DS33(i2c) # NeoPixels self._neopixels = neopixel.NeoPixel(board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB) self._buttons = GamePad( digitalio.DigitalInOut(board.BUTTON_A), digitalio.DigitalInOut(board.BUTTON_B), )
def _get_gamepad(self): """ Returns a GamePad instance if possible, otherwise will return None """ try: # Asign it a real object if possible return GamePad() except IOError as e: print(f'Error: {e}') print('Gamepad currently the only supported input mechanism') raise e
class CPB_Gizmo(PyBadgerBase): """Class that represents a single Circuit Playground Bluefruit with TFT Gizmo.""" display = None _audio_out = audiopwmio.PWMAudioOut _neopixel_count = 10 def __init__(self): super().__init__() _i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA) _int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT) self.accelerometer = adafruit_lis3dh.LIS3DH_I2C(_i2c, address=0x19, int1=_int1) self.accelerometer.range = adafruit_lis3dh.RANGE_8_G self.display = tft_gizmo.TFT_Gizmo() self._display_brightness = 1.0 # NeoPixels self._neopixels = neopixel.NeoPixel(board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB) _a_btn = digitalio.DigitalInOut(board.BUTTON_A) _a_btn.switch_to_input(pull=digitalio.Pull.DOWN) _b_btn = digitalio.DigitalInOut(board.BUTTON_B) _b_btn.switch_to_input(pull=digitalio.Pull.DOWN) self._buttons = GamePad(_a_btn, _b_btn) self._light_sensor = analogio.AnalogIn(board.LIGHT) @property def button(self): """The buttons on the board. Example use: .. code-block:: python from adafruit_pybadger import pybadger while True: if pybadger.button.a: print("Button A") elif pybadger.button.b: print("Button B") """ button_values = self._buttons.get_pressed() return Buttons(button_values & PyBadgerBase.BUTTON_B, button_values & PyBadgerBase.BUTTON_A) @property def _unsupported(self): """This feature is not supported on CPB Gizmo.""" raise NotImplementedError( "This feature is not supported on CPB Gizmo.")
class Clue(PyBadgerBase): """Class that represents a single CLUE.""" _audio_out = audiopwmio.PWMAudioOut _neopixel_count = 1 def __init__(self): super().__init__() i2c = board.I2C() if i2c is not None: self._accelerometer = adafruit_lsm6ds.LSM6DS33(i2c) # NeoPixels self._neopixels = neopixel.NeoPixel(board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB) self._buttons = GamePad( digitalio.DigitalInOut(board.BUTTON_A), digitalio.DigitalInOut(board.BUTTON_B), ) @property def button(self): """The buttons on the board. Example use: .. code-block:: python from adafruit_pybadger import pybadger while True: if pybadger.button.a: print("Button A") elif pybadger.button.b: print("Button B") """ button_values = self._buttons.get_pressed() return Buttons(button_values & PyBadgerBase.BUTTON_B, button_values & PyBadgerBase.BUTTON_A) @property def _unsupported(self): """This feature is not supported on CLUE.""" raise NotImplementedError("This feature is not supported on CLUE.") # The following is a list of the features available in other PyBadger modules but # not available for CLUE. If called while using a CLUE, they will result in the # NotImplementedError raised in the property above. play_file = _unsupported light = _unsupported
def __init__(self, win_width, win_height, caption): pygame.init() self.gamepad = GamePad() self.screen = pygame.display.set_mode((win_width, win_height)) pygame.display.set_caption(caption) self.clock = pygame.time.Clock() self.angleX = 0 self.angleY = 0 self.angleZ = 0 self.vertices = [] self.faces = [] self.colors = []
def __init__(self): super().__init__() _i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA) _int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT) self.accelerometer = adafruit_lis3dh.LIS3DH_I2C(_i2c, address=0x19, int1=_int1) self.accelerometer.range = adafruit_lis3dh.RANGE_8_G self.display = tft_gizmo.TFT_Gizmo() self._display_brightness = 1.0 # NeoPixels self._neopixels = neopixel.NeoPixel( board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB ) _a_btn = digitalio.DigitalInOut(board.BUTTON_A) _a_btn.switch_to_input(pull=digitalio.Pull.DOWN) _b_btn = digitalio.DigitalInOut(board.BUTTON_B) _b_btn.switch_to_input(pull=digitalio.Pull.DOWN) self._buttons = GamePad(_a_btn, _b_btn) self._light_sensor = analogio.AnalogIn(board.LIGHT)
def __init__(self, deadzone=0.08): self.deadzone = deadzone try: self.controller = GamePad() except: self.controller = None
def main(): global SCREEN_FULLSCREEN pygame.init() util.load_config() if len(sys.argv) > 1: for arg in sys.argv: if arg == "-np": Variables.particles = False elif arg == "-na": Variables.alpha = False elif arg == "-nm": Variables.music = False elif arg == "-ns": Variables.sound = False elif arg == "-f": SCREEN_FULLSCREEN = True scr_options = 0 if SCREEN_FULLSCREEN: scr_options += FULLSCREEN screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT),scr_options ,32) pygame.display.set_icon(util.load_image("kuvake")) pygame.display.set_caption("Trip on the Funny Boat") init() joy = None if pygame.joystick.get_count() > 0: joy = pygame.joystick.Joystick(0) joy.init() gamepad = GamePad(joy) else: gamepad = None try: util.load_music("JDruid-Trip_on_the_Funny_Boat") if Variables.music: pygame.mixer.music.play(-1) except: # It's not a critical problem if there's no music pass pygame.time.set_timer(NEXTFRAME, 1000 / FPS) # 30 fps Water.global_water = Water() main_selection = 0 while True: main_selection = Menu(screen, ("New Game", "High Scores", "Options", "Quit"), gamepad, main_selection).run() if main_selection == 0: # New Game selection = Menu(screen, ("Story Mode", "Endless Mode"), gamepad).run() if selection == 0: # Story score = Game(screen, gamepad).run() Highscores(screen, score).run() elif selection == 1: # Endless score = Game(screen, gamepad, True).run() Highscores(screen, score, True).run() elif main_selection == 1: # High Scores selection = 0 while True: selection = Menu(screen, ("Story Mode", "Endless Mode", "Endless Online"), gamepad, selection).run() if selection == 0: # Story Highscores(screen).run() elif selection == 1: # Endless Highscores(screen, endless = True).run() elif selection == 2: # Online Highscores(screen, endless = True, online = True).run() else: break elif main_selection == 2: # Options selection = Options(screen, gamepad).run() else: #if main_selection == 3: # Quit return