def __init__(self, x, y, width, height, angle, color): """ Initialize our rectangle variables """ # Position self.x = x self.y = y # Vector self.delta_x = 0 self.delta_y = 0 # Size and rotation self.width = width self.height = height self.angle = angle # Color self.color = color joysticks = arcade.get_joysticks() if joysticks: self.joystick = joysticks[0] self.joystick.open() else: print("There are no Joysticks") self.joystick = None
def __init__(self, width, height, title): #init application window super().__init__(width, height, title) # init process object self.process = Process() # set application window background color arcade.set_background_color(arcade.color.BOTTLE_GREEN) # Store gamepad list self.gamepads = arcade.get_joysticks() # check every connected gamepad if self.gamepads: for g in self.gamepads: #link all gamepad callbacks to the current class methods g.open() g.on_joybutton_press = self.__onButtonPressed g.on_joybutton_release = self.__onButtonReleased g.on_joyhat_motion = self.__onCrossMove g.on_joyaxis_motion = self.__onAxisMove # transform list into a dictionary to get its index faster self.gamepads = { self.gamepads[idx]: idx for idx in range(len(self.gamepads)) } else: print("There are no Gamepad connected !") self.gamepads = None
def __init__(self, width, height, title): # Call the parent class's init function super().__init__(width, height, title) # Make the mouse disappear when it is over the window. # So we just see our object, not the pointer. self.set_mouse_visible(False) arcade.set_background_color(arcade.color.ASH_GREY) # Create our ball self.ball = Ball(50, 50, 0, 0, 15, arcade.color.AUBURN) # Get a list of all the game controllers that are plugged in joysticks = arcade.get_joysticks() # If we have a game controller plugged in, grab it and # make an instance variable out of it. if joysticks: self.joystick = joysticks[0] self.joystick.open() else: print("There are no joysticks.") self.joystick = None
def __init__(self, width, height, title): super().__init__(width, height, title) # Set the working directory (where we expect to find files) to the same # directory this .py file is in. You can leave this out of your own # code, but it is needed to easily run the examples using "python -m" # as mentioned at the top of this program. file_path = os.path.dirname(os.path.abspath(__file__)) os.chdir(file_path) arcade.set_background_color(arcade.color.DARK_MIDNIGHT_BLUE) self.game_over = False self.score = 0 self.bullet_cooldown = 0 self.player = Player("images/playerShip2_orange.png") self.bullet_list = arcade.SpriteList() self.enemy_list = arcade.SpriteList() self.joy = None joys = arcade.get_joysticks() if joys: self.joy = joys[0] self.joy.open() print("Using joystick controls: {}".format(self.joy.device)) if not self.joy: print("No joystick present, using keyboard controls") arcade.window_commands.schedule(self.spawn_enemy, ENEMY_SPAWN_INTERVAL)
def __init__(self, width, height, title): super().__init__(width, height, title) joysticks = arcade.get_joysticks() if joysticks: self.joystick = joysticks[0] self.joystick.open() self.joystick.on_joybutton_press = self.on_joybutton_press_for_cover
def __init__(self, filename, scale): super().__init__(filename, scale) joysticks = arcade.get_joysticks() if joysticks: self.joystick = joysticks[0] self.joystick.open() else: print("There are no Joysticks") self.joystick = None
def check_joysticks(world): all_joysticks = [] for _, input_source in world.get_component(InputSource): all_joysticks.append(input_source.name) # arcade.get_joysticks is a time consuming operation and will skip frames joysticks = arcade.get_joysticks() if joysticks: for joystick in joysticks: name = joystick.device.name if name not in all_joysticks: print(f"new joystick! {name}") world.create_entity(InputSource(name, JoystickState(joystick))) all_joysticks.append(name)
def __init__(self) -> None: super().__init__() # These lists will hold different sets of sprites self.coins = None self.background = None self.walls = None self.ladders = None self.goals = None self.enemies = None # One sprite for the player, no more is needed self.player = None # We need a physics engine as well self.physics_engine = None # Someplace to keep score self.score = 0 # Which level are we on? self.level = 1 # Load up our sounds here self.coin_sound = arcade.load_sound( str(ASSETS_PATH / "sounds" / "coin.wav")) self.jump_sound = arcade.load_sound( str(ASSETS_PATH / "sounds" / "jump.wav")) self.victory_sound = arcade.load_sound( str(ASSETS_PATH / "sounds" / "victory.wav")) # Track the bottom left corner of the current viewport self.view_left = 0 self.view_bottom = 0 # Check if a joystick is connected joysticks = arcade.get_joysticks() if joysticks: # If so, get the first one self.joystick = joysticks[0] self.joystick.open() else: # If not, flag it so we won't use it print("There are no Joysticks") self.joystick = None # Flag for entering view mode - allows super-user to skim around self.view_mode = False
def __init__(self, width, height): super().__init__(width, height, title="Keyboard control") self.player = None self.left_down = False joysticks = arcade.get_joysticks() if joysticks: self.joystick = joysticks[0] self.joystick.open() self.joystick.on_joybutton_press = self.on_joybutton_press self.joystick.on_joybutton_release = self.on_joybutton_release self.joystick.on_joyhat_motion = self.on_joyhat_motion else: print("There are no Joysticks") self.joystick = None
def __init__(self, width, height): super().__init__(width, height, title="joystick control") self.player = None self.left_down = False joysticks = arcade.get_joysticks() if joysticks: self.joystick = joysticks[0] self.joystick.open() self.joystick.on_joybutton_press = self.on_joybutton_press self.joystick.on_joybutton_release = self.on_joybutton_release self.joystick.on_joyhat_motion = self.on_joyhat_motion else: print("There are no Joysticks") self.joystick = None
def setup(self): """ Initialize Scoring System & Game Components """ self.board = new_board() self.score = 0 self.level = 0 self.GAME_SPEED = INITIAL_GAME_SPEED self.background = arcade.load_texture(BACKGROUNDS[0]) # Set Game Levels 1-9 self.GAME_LEVEL_FRAMES = [ 0, 300, 600,950,1300,1650,2050,2450,2900,3400,3950] # RX & Statistics self.processing_time = 0 self.draw_time = 0 self.fps_start_timer = None self.fps = None self.board_sprite_list = arcade.SpriteList() for row in range(len(self.board)): for column in range(len(self.board[0])): sprite = arcade.Sprite() for texture in texture_list: sprite.append_texture(texture) sprite.set_texture(0) sprite.center_x = (MARGIN + WIDTH) * column + SCREEN_MARGIN + WIDTH // 2 + WINDOW_MARGIN # MAY NEED FIXED WITH NEW SCREEN SIZE sprite.center_y = TETRIS_HEIGHT - HIDE_BOTTOM - (MARGIN + HEIGHT) * row + SCREEN_MARGIN + HEIGHT // 2 # MAY NEED FIXED WITH NEW SCREEN SIZE self.board_sprite_list.append(sprite) #- JOYSTICK # Check for System Installed Joysticks. Make instance of it. joysticks = arcade.get_joysticks() if joysticks: self.joystick = joysticks[0] self.joystick.open() else: print("----NO JOYSTICK CONTROLLER WAS FOUND.") self.joystick = None #- Initial Stone self.new_stone() self.update_board() print("---- Game Board, Mechanics, Stats == SETUP Confirm")
def __init__(self) -> None: super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) # These lists will hold different sets of sprites self.coins = None self.background = None self.walls = None self.ladders = None self.goals = None self.enemies = None # One sprite for the player, no more is needed self.player = None # We need a physics engine as well self.physics_engine = None # Someplace to keep score self.score = 0 # Which level are we on? self.level = 1 # Load up our sounds here self.coin_sound = arcade.load_sound( str(ASSETS_PATH / "sounds" / "coin.wav") ) self.jump_sound = arcade.load_sound( str(ASSETS_PATH / "sounds" / "jump.wav") ) self.victory_sound = arcade.load_sound( str(ASSETS_PATH / "sounds" / "victory.wav") ) # Check if a joystick is connected joysticks = arcade.get_joysticks() if joysticks: # If so, get the first one self.joystick = joysticks[0] self.joystick.open() else: # If not, flag it so we won't use it print("There are no Joysticks") self.joystick = None
def __init__(self): super().__init__(fullscreen=True, resizable=True) # Add Joystick joysticks = arcade.get_joysticks() if joysticks: self.joystick = joysticks[0] self.joystick.open() self.joystick.on_joybutton_press = self.on_joybutton_press self.joystick.on_joybutton_release = self.on_joybutton_release self.joystick.on_joyhat_motion = self.on_joyhat_motion else: print("There are no Joysticks") self.joystick = None # Set Background Color arcade.set_background_color(arcade.color.BLACK) # If you have sprite lists, you should create them here, # and set them to None self.defender_list = None self.invader_list = None self.lazer_list = None # Set up the player info self.defender_sprite = None # Don't show the mouse cursor self.set_mouse_visible(False) # Debugging Variable self.iteration = 0 # Create Game State Variables self.invaderDirection = "left" # Get Full Screen Width & Height self.FULL_SCREEN_WIDTH, self.FULL_SCREEN_HEIGHT = self.get_size() self.CENTER_X = self.FULL_SCREEN_WIDTH / 2 self.CENTER_Y = self.FULL_SCREEN_HEIGHT / 2 self.LEFT_BOUNDARY_X = self.CENTER_X - (self.CENTER_X * 0.5) self.RIGHT_BOUNDARY_X = self.CENTER_X + (self.CENTER_X * 0.5) self.leftButtonDown = False self.rightButtonDown = False
def __init__(self): """ Initializer """ # Call the parent class initializer super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, "Lab 7 - User Control") self.set_mouse_visible(False) self.ship = BattleShip(88, 32, 0, 0, 88, arcade.color.AUBURN) self.invader = RealInvader(88, 200, 0, 0, 88, arcade.color.AUBURN) self.laser_sound = arcade.load_sound("laser.ogg") joysticks = arcade.get_joysticks() if joysticks: self.joystick = joysticks[0] self.joystick.open() else: print("There are no joysticks.") self.joystick = None
def __init__(self, width: float = 800, height: float = 600, title: str = 'Arcade Window', fullscreen: bool = False, resizable: bool = False, debug_mode=False, scale_speed=0.001, init_delta_time=10): super().__init__(width, height, title, fullscreen, resizable) arcade.set_background_color(arcade.color.BLACK) self.scale_speed = scale_speed self.init_delta_time = init_delta_time self.atv = None self.docking_system = None self.instruments = None self.debug = debug_mode self.time = timeit.default_timer() self.fps = None joysticks = arcade.get_joysticks() if joysticks: self.joystick = joysticks[0] self.joystick.open() else: print("There are no Joysticks") self.joystick = None
def __init__(self, filename, scale): super().__init__(filename, scale) # Get list of game controllers that are available joysticks = arcade.get_joysticks() # If we have any... if joysticks: # Grab the first one in the list self.joystick = joysticks[0] # Open it for input self.joystick.open() # Push this object as a handler for joystick events. # Required for the on_joy* events to be called. self.joystick.push_handlers(self) else: # Handle if there are no joysticks. print("There are no joysticks, plug in a joystick and run again.") self.joystick = None
def __init__(self, width, height, title): # Call the parent class's init function super().__init__(width, height, title) # Make the mouse disappear when it is over the window. # So we just see our object, not the pointer. self.set_mouse_visible(False) arcade.set_background_color(arcade.color.ASH_GREY) # Create our ball self.ball = Ball(50, 50, 0, 0, 15, arcade.color.AUBURN) joysticks = arcade.get_joysticks() if joysticks: self.joystick = joysticks[0] self.joystick.open() else: print("There are no joysticks.") self.joystick = None
def __init__(self, width, height, title): """ Initializer """ super().__init__(width, height, title) # Set the working directory (where we expect to find files) to the same # directory this .py file is in. You can leave this out of your own # code, but it is needed to easily run the examples using "python -m" # as mentioned at the top of this program. file_path = os.path.dirname(os.path.abspath(__file__)) os.chdir(file_path) # https://freesound.org/people/TNTdude7/sounds/261462/ self.chest_sound = arcade.load_sound("chest_slam.wav") # Sprite lists self.player_list = None self.chest_list = None self.bullet_list = None # Set up the player self.player_sprite = None self.wall_list = None self.physics_engine = None self.view_bottom = 0 self.view_left = 0 self.score = 0 joysticks = arcade.get_joysticks() if joysticks: self.joystick_1 = joysticks[0] self.joystick_1.open() self.joystick_1.on_joybutton_press = self.on_joybutton_press self.joystick_1.on_joybutton_release = self.on_joybutton_release self.joystick_1.on_joyhat_motion = self.on_joyhat_motion else: print("There are no joysticks.") self.joystick_1 = None
def __init__(self, width, height, title): super().__init__(width, height, title) # 角色列表定义 self.all_sprites_list = None self.enemy_list = None # 定义玩家的相关变量 self.score = 0 self.player_sprite = None joysticks = arcade.get_joysticks() if joysticks: self.joystick = joysticks[0] self.joystick.open() self.joystick.on_joybutton_press = self.on_joybutton_press #self.joystick.on_joybutton_release = self.on_joybutton_release #self.joystick.on_joyhat_motion = self.on_joyhat_motion else: print("There are no Joysticks") self.joystick = None
def __init__(self, width, height, title): super().__init__(width, height, title) arcade.set_background_color(arcade.color.DARK_MIDNIGHT_BLUE) self.game_over = False self.score = 0 self.bullet_cooldown = 0 self.ship = Ship("../img/ship.png") self.ship.center_x = 200 self.ship.center_y = 200 self.sprites = arcade.SpriteList() self.sprites.append(self.ship) self.bullet_list = arcade.SpriteList() self.enemy_list = arcade.SpriteList() self.enemy_list.append(Enemy(300, 300)) self.joy = None joys = arcade.get_joysticks() if joys: self.joy = joys[0] self.joy.open() print("Using joystick controls: {}".format(self.joy.device)) if not self.joy: print("No joystick present, using keyboard controls") arcade.window_commands.schedule(self.spawn_enemy, 2.0)
def __init__(self, WindowSize): self.texts = [ Text( 10, flip_y(WindowSize, 20), "Stage 1", { "font_name": "Georgia", "font_size": 40, "bold": True, "anchor_x": "left", "align": "left" }), ] self.WindowSize = WindowSize self.avatar = Avatar("avatar.png") self.avatar.center_x = 860 self.avatar.center_y = 120 joysticks = arcade.get_joysticks() if joysticks: self.joystick = joysticks[0] self.joystick.open() self.joystick.on_joyhat_motion = self.on_joyhat_motion self.sprites = arcade.SpriteList() self.sprites.append(self.avatar) self.walls = arcade.SpriteList() top_row = list(zip(range(20, 1024, 90), [500] * 15)) for i in range(len(top_row)): left = top_row[i][0] top = top_row[i][1] + random.randint(-10, 10) top_row[i] = (left, top) for pos in top_row: wall = arcade.Sprite("LPC_cliffs_grass.png", image_x=15, image_y=288 - 175 - 100, image_width=65, image_height=120, scale=1.6) wall.left = pos[0] wall.top = pos[1] self.walls.append(wall) right_row = [ [903, 410], #[920, 410 - 240 + 20] ] for pos in right_row: wall = arcade.Sprite("LPC_cliffs_grass.png", image_x=95, image_y=288 - 130 - 150, image_width=75, image_height=120, scale=2.2) wall.left = pos[0] wall.top = pos[1] self.walls.append(wall) bottom_row = list(zip(range(20, 1024, 90), [50] * 15)) left_row = list(zip([10] * 15, range(50, 500, 200))) left_row.reverse() for pos in left_row + bottom_row: wall = arcade.Sprite("LPC_cliffs_grass.png", image_x=174, image_y=288 - 175 - 100, image_width=80, image_height=140, scale=2) wall.left = pos[0] wall.top = pos[1] self.walls.append(wall) self.physics = arcade.PhysicsEngineSimple(self.avatar, self.walls) self.floor = arcade.SpriteList() cave = arcade.Sprite("LPC_cliffs_grass.png", image_x=1, image_y=288 - 140, image_width=30, image_height=45, scale=2.4) target_cliff = top_row[3] cave.left = target_cliff[0] + 14 cave.top = target_cliff[1] - 85 self.floor.append(cave) self.cave = cave
def __init__(self, title, track_file): temp_track_data = [] start_pos = '' track_sprite_dir = "sprites/track-structure/" track_sprite_ext = ".bmp" with open(track_file) as track_data: GRAPHICS_SCALE = float(track_data.readline()) TILE_SIZE = int(ORG_TILE_SIZE * GRAPHICS_SCALE) start_pos = track_data.readline().split(',') temp_track_data = track_data.readlines() self.track_sprites = arcade.SpriteList() for i, track_line in enumerate(reversed(temp_track_data)): track_line = track_line.split(',') for j, tile in enumerate(track_line): if isValidTrackTile(tile): track_sprite = arcade.Sprite( track_sprite_dir + tile + track_sprite_ext, GRAPHICS_SCALE) track_sprite.top = (i + 1) * TILE_SIZE track_sprite.left = j * TILE_SIZE self.track_sprites.append(track_sprite) self.window_width = len(track_line) * TILE_SIZE self.window_height = len(temp_track_data) * TILE_SIZE super().__init__(self.window_width, self.window_height, title) self.track_sprites.draw() self.track_shape = arcade.get_image() if not DEBUG: track_sprite_dir = "sprites/track-texture/" track_sprite_ext = ".png" self.track_sprites = arcade.SpriteList() for i, track_line in enumerate(reversed(temp_track_data)): track_line = track_line.split(',') for j, tile in enumerate(track_line): if isValidTrackTile(tile): track_sprite = arcade.Sprite( track_sprite_dir + tile + track_sprite_ext, GRAPHICS_SCALE) track_sprite.top = (i + 1) * TILE_SIZE track_sprite.left = j * TILE_SIZE self.track_sprites.append(track_sprite) arcade.set_background_color(arcade.color.AMAZON) else: self.distance_lines = [] arcade.set_background_color(arcade.color.WHITE) self.car = Car( int(start_pos[1]) * TILE_SIZE - (TILE_SIZE / 2), (len(temp_track_data) - int(start_pos[0])) * TILE_SIZE - (TILE_SIZE / 2), int(start_pos[2]), "sprites/car.png", GRAPHICS_SCALE) self.distance_angles = [-90, -60, -30, 0, 30, 60, 90] self.end = False self.steer_dir = 0 self.steer_speed = 0 self.data_file = open( "NN_data/" + datetime.datetime.now().strftime("%Y_%m_%d_%H_%M") + ".txt", "w") joysticks = arcade.get_joysticks() if joysticks: self.joystick = joysticks[0] self.joystick.open() """ else:
start = time.time() end = start + delay while time.time() < end: yield if __name__ == "__main__": window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) # Set the working directory (where we expect to find files) to the same # directory this .py file is in. You can leave this out of your own # code, but it is needed to easily run the examples using "python -m" # as mentioned at the top of this program. file_path = os.path.dirname(os.path.abspath(__file__)) os.chdir(file_path) window.joys = arcade.get_joysticks() for j in window.joys: j.open() joy_config_method_names = ( ("Move the movement stick left or right", "move_stick_x"), ("Move the movement stick up or down", "move_stick_y"), ("Move the shooting stick left or right", "shoot_stick_x"), ("Move the shooting stick up or down", "shoot_stick_y"), ) game = MyGame() window.show_view( JoyConfigView(joy_config_method_names, window.joys, game, SCREEN_WIDTH, SCREEN_HEIGHT)) arcade.run()
def __init__(self, width, height, title): """ Create the variables """ # Init the parent class super().__init__(width, height, title) #............................................................ #camera demo example vsync: self.set_vsync(True) #mouse tracker: self.mouse_pos = 0, 0 #............................................. self.time = 0 #********* # //////////////////////////////////////////////////////////////// self.joysticks = None #.................... # Get list of game controllers that are available joysticks = arcade.get_joysticks() # If we have any... if joysticks: # Grab the first one in the list self.joystick = joysticks[0] # Open it for input self.joystick.open() print("joystick open") # Push this object as a handler for joystick events. # Required for the on_joy* events to be called. self.joystick.push_handlers(self) else: # Handle if there are no joysticks. print("There are no joysticks, plug in a joystick and run again.") self.joystick = None # //////////////////////////////////////////////////////////////// self.score = 0 self.lives = 0 self.inventory = set() self.master_status_png: Optional[arcade.Sprite] = None #self.master_status_name: str() self.master_status_name: cycle([]) self.master_status_cyclist = cycle( []) #TypeError: cycle expected 1 argument, got 0 self.master_status_index = 0 self.master_status = None self.mechandlers_textures = dict() # Player sprite self.player_sprite: Optional[PlayerSprite] = None # Sprite lists we need self.player_list: Optional[arcade.SpriteList] = None self.wall_list: Optional[arcade.SpriteList] = None self.bullet_list: Optional[arcade.SpriteList] = None self.coins_list: Optional[arcade.SpriteList] = None #self.autonom_moving_sprites_list: Optional[arcade.SpriteList] = None self.key_lock_door_list: Optional[arcade.SpriteList] = None self.ladder_list: Optional[arcade.SpriteList] = None self.trap_list: Optional[arcade.SpriteList] = None self.mechanics_list: Optional[arcade.SpriteList] = None self.mechandler_list: Optional[arcade.SpriteList] = None self.stairs_list: Optional[arcade.SpriteList] = None self.enemy_list: Optional[arcade.SpriteList] = None self.lowfric_list: Optional[arcade.SpriteList] = None self.startposition_list: Optional[arcade.SpriteList] = None # Track the current state of what key is pressed self.left_pressed: bool = False self.right_pressed: bool = False self.up_pressed: bool = False self.down_pressed: bool = False # Physics engine self.physics_engine = Optional[arcade.PymunkPhysicsEngine] # Set background color arcade.set_background_color(arcade.color.AMAZON)