def __init__(self): super().__init__(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) arcadeplus.set_background_color(arcadeplus.color.BLACK) # collect particle factory functions self.factories = [ v for k, v in globals().items() if k.startswith("emitter_") ] self.emitter_factory_id = -1 self.label = None self.emitter = None self.emitter_timeout = 0 self.obj = arcadeplus.Sprite(":resources:images/pinball/bumper.png", 0.2, center_x=0, center_y=15) self.obj.change_x = 3 self.frametime_plotter = FrametimePlotter() pyglet.clock.schedule_once(self.next_emitter, QUIET_BETWEEN_SPAWNS)
def setup(self): """ Set up the game and initialize the variables. """ # Sprite lists self.player_list = arcadeplus.SpriteList() self.coin_list = arcadeplus.SpriteList() self.bullet_list = arcadeplus.SpriteList() # Set up the player self.score = 0 # Image from kenney.nl self.player_sprite = arcadeplus.Sprite(":resources:images/animated_characters/female_person/femalePerson_idle.png", SPRITE_SCALING_PLAYER) self.player_sprite.center_x = 50 self.player_sprite.center_y = 70 self.player_list.append(self.player_sprite) # Create the coins for i in range(COIN_COUNT): # Create the coin instance # Coin image from kenney.nl coin = arcadeplus.Sprite(":resources:images/items/coinGold.png", SPRITE_SCALING_COIN) # Position the coin coin.center_x = random.randrange(SCREEN_WIDTH) coin.center_y = random.randrange(120, SCREEN_HEIGHT) # Add the coin to the lists self.coin_list.append(coin) # Set the background color arcadeplus.set_background_color(arcadeplus.color.AMAZON)
def __init__(self): # Call the parent class and set up the window super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) # These are 'lists' that keep track of our sprites. Each sprite should # go into a list. self.coin_list = None self.wall_list = None self.player_list = None # Separate variable that holds the player sprite self.player_sprite = None # Our physics engine self.physics_engine = None # Used to keep track of our scrolling self.view_bottom = 0 self.view_left = 0 # Keep track of the score self.score = 0 # Load sounds self.collect_coin_sound = arcadeplus.load_sound(":resources:sounds/coin1.wav") self.jump_sound = arcadeplus.load_sound(":resources:sounds/jump1.wav") arcadeplus.set_background_color(arcadeplus.csscolor.CORNFLOWER_BLUE)
def __init__(self, width, height, title): """ Set up the application. """ super().__init__(width, height, title) self.shape_list = arcadeplus.ShapeElementList() point_list = ((0, 50), (10, 10), (50, 0), (10, -10), (0, -50), (-10, -10), (-50, 0), (-10, 10), (0, 50)) colors = [ getattr(arcadeplus.color, color) for color in dir(arcadeplus.color) if not color.startswith("__") ] for i in range(200): x = SCREEN_WIDTH // 2 - random.randrange(SCREEN_WIDTH) y = SCREEN_HEIGHT // 2 - random.randrange(SCREEN_HEIGHT) color = random.choice(colors) points = [(px + x, py + y) for px, py in point_list] my_line_strip = arcadeplus.create_line_strip(points, color, 5) self.shape_list.append(my_line_strip) self.shape_list.center_x = SCREEN_WIDTH // 2 self.shape_list.center_y = SCREEN_HEIGHT // 2 self.shape_list.angle = 0 arcadeplus.set_background_color(arcadeplus.color.BLACK)
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) arcadeplus.set_background_color(arcadeplus.color.ASH_GREY) # Create our ball self.ball = Ball(50, 50, 0, 0, 15, arcadeplus.color.AUBURN) # Get a list of all the game controllers that are plugged in joysticks = arcadeplus.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 start_snowfall(self): """ Set up snowfall and initialize variables. """ self.snowflake_list = [] for i in range(50): # Create snowflake instance snowflake = Snowflake() # Randomly position snowflake snowflake.x = random.randrange(SCREEN_WIDTH) snowflake.y = random.randrange(SCREEN_HEIGHT + 200) # Set other variables for the snowflake snowflake.size = random.randrange(4) snowflake.speed = random.randrange(20, 40) snowflake.angle = random.uniform(math.pi, math.pi * 2) # Add snowflake to snowflake list self.snowflake_list.append(snowflake) # Don't show the mouse pointer self.set_mouse_visible(False) # Set the background color arcadeplus.set_background_color(arcadeplus.color.BLACK)
def setup(): global toolbar, frames arcadeplus.open_window(WIDTH, HEIGHT, "AnimationCreator") arcadeplus.set_background_color(arcadeplus.color.WHITE) scheduling_update_time = 0.01666666666 # float value is same as 1/60 arcadeplus.schedule(on_update, scheduling_update_time) # Create Vertex Buffer Object (VBO) shape lists frames.append(arcadeplus.ShapeElementList()) toolbar = arcadeplus.ShapeElementList() # Override arcade window methods window = arcadeplus.get_window() window.on_draw = on_draw window.on_key_press = on_key_press window.on_key_release = on_key_release window.on_mouse_press = on_mouse_press window.on_mouse_release = on_mouse_release window.on_mouse_drag = on_mouse_drag # Render toolbar render_toolbar_dividers() render_toolbar_shapes() render_toolbar_colors() render_toolbar_icons() render_toolbar_text() arcadeplus.run()
def __init__(self): """ Initializer """ # Call the parent class initializer super().__init__(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) # Variables that will hold sprite lists self.shape_list = [] self.processing_time = 0 self.draw_time = 0 self.program_start_time = timeit.default_timer() self.sprite_count_list = [] self.fps_list = [] self.processing_time_list = [] self.drawing_time_list = [] self.last_fps_reading = 0 self.fps = FPSCounter() arcadeplus.set_background_color(arcadeplus.color.AMAZON) # Open file to save timings self.results_file = open(RESULTS_FILE, "w")
def load_level(self, level): # Read in the tiled map my_map = arcadeplus.tilemap.read_tmx( f":resources:tmx_maps/level_{level}.tmx") # --- Walls --- # Calculate the right edge of the my_map in pixels self.end_of_map = my_map.map_size.width * GRID_PIXEL_SIZE # Grab the layer of items we can't move through self.wall_list = arcadeplus.tilemap.process_layer( my_map, 'Platforms', TILE_SPRITE_SCALING) self.physics_engine = arcadeplus.PhysicsEnginePlatformer( self.player_sprite, self.wall_list, gravity_constant=GRAVITY) # --- Other stuff # Set the background color if my_map.background_color: arcadeplus.set_background_color(my_map.background_color) # Set the view port boundaries # These numbers set where we have 'scrolled' to. self.view_left = 0 self.view_bottom = 0
def __init__(self, width, height, title): super().__init__(width, height, title) arcadeplus.set_background_color(arcadeplus.color.DARK_SLATE_GRAY) self.draw_time = 0 self.shape_list = None
def setup(self): """ Set up the game and initialize the variables. """ # Sprite lists self.player_list = arcadeplus.SpriteList() self.coin_list = arcadeplus.SpriteList() # Set up the player self.score = 0 self.player_sprite = arcadeplus.Sprite( ":resources:images/animated_characters/female_person/femalePerson_idle.png", 0.5) self.player_sprite.center_x = 50 self.player_sprite.center_y = 50 self.player_list.append(self.player_sprite) for i in range(50): # Create the coin instance coin = Collectable(":resources:images/items/coinGold.png", SPRITE_SCALING) coin.width = 30 coin.height = 30 # Position the coin coin.center_x = random.randrange(SCREEN_WIDTH) coin.center_y = random.randrange(SCREEN_HEIGHT) # Add the coin to the lists self.coin_list.append(coin) # Don't show the mouse cursor self.set_mouse_visible(False) # Set the background color arcadeplus.set_background_color(arcadeplus.color.AMAZON)
def __init__(self, width, height, title): super().__init__(width, height, title) arcadeplus.set_background_color(arcadeplus.color.AMAZON) self.texture = arcadeplus.load_texture( ":resources:images/items/coinGold.png")
def __init__(self): """ Initializer """ # Open a window in full screen mode. Remove fullscreen=True if # you don't want to start this way. super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE, fullscreen=True) # 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) # This will get the size of the window, and set the viewport to match. # So if the window is 1000x1000, then so will our viewport. If # you want something different, then use those coordinates instead. width, height = self.get_size() self.set_viewport(0, width, 0, height) arcadeplus.set_background_color(arcadeplus.color.AMAZON) self.example_image = arcadeplus.load_texture( ":resources:images/tiles/boxCrate_double.png")
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) arcadeplus.set_background_color(arcadeplus.color.DARK_SLATE_GRAY) # -- Pymunk self.space = pymunk.Space() self.space.iterations = 35 self.space.gravity = (0.0, -900.0) # Lists of sprites or lines self.sprite_list = arcadeplus.SpriteList() self.static_lines = [] # Used for dragging shapes around with the mouse self.shape_being_dragged = None self.last_mouse_position = 0, 0 self.draw_time = 0 self.processing_time = 0 # Create the floor floor_height = 80 body = pymunk.Body(body_type=pymunk.Body.STATIC) shape = pymunk.Segment(body, [0, floor_height], [SCREEN_WIDTH, floor_height], 0.0) shape.friction = 10 self.space.add(shape) self.static_lines.append(shape)
def setup(self): """ Set up the game and initialize the variables. Call this method if you implement a 'play again' feature. """ self.game_state = PLAY_GAME # Sprite lists self.player_list = arcadeplus.SpriteList() self.enemy_list = arcadeplus.SpriteList() self.player_bullet_list = arcadeplus.SpriteList() self.enemy_bullet_list = arcadeplus.SpriteList() self.shield_list = arcadeplus.SpriteList(is_static=True) # Set up the player self.score = 0 # Image from kenney.nl self.player_sprite = arcadeplus.Sprite( ":resources:images/animated_characters/female_person/femalePerson_idle.png", SPRITE_SCALING_PLAYER) self.player_sprite.center_x = 50 self.player_sprite.center_y = 40 self.player_list.append(self.player_sprite) # Make each of the shields for x in range(75, 800, 190): self.make_shield(x) # Set the background color arcadeplus.set_background_color(arcadeplus.color.AMAZON) self.setup_level_one()
def __init__(self): """ Initializer """ # Call the parent class initializer super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) # Variables that will hold sprite lists self.player_list = None self.enemy_list = None self.player_bullet_list = None self.enemy_bullet_list = None self.shield_list = None # Textures for the enemy self.enemy_textures = None # State of the game self.game_state = PLAY_GAME # Set up the player info self.player_sprite = None self.score = 0 # Enemy movement self.enemy_change_x = -ENEMY_SPEED # Don't show the mouse cursor self.set_mouse_visible(False) # Load sounds. Sounds from kenney.nl self.gun_sound = arcadeplus.load_sound(":resources:sounds/hurt5.wav") self.hit_sound = arcadeplus.load_sound(":resources:sounds/hit5.wav") arcadeplus.set_background_color(arcadeplus.color.AMAZON)
def __init__(self, width, height, title): super().__init__(width, height, title) file_path = os.path.dirname(os.path.abspath(__file__)) os.chdir(file_path) arcadeplus.set_background_color(arcadeplus.color.AMAZON) self.character_list = arcadeplus.SpriteList() self.character_sprite = arcadeplus.Sprite( ":resources:images/animated_characters/female_person/femalePerson_idle.png", CHARACTER_SCALING) self.character_sprite.center_x = 150 self.character_sprite.center_y = 110 self.character_list.append(self.character_sprite) self.wall_list = arcadeplus.SpriteList() for x in range(0, 1200, 64): sprite = arcadeplus.Sprite( ":resources:images/tiles/boxCrate_double.png", CHARACTER_SCALING) sprite.center_x = x sprite.center_y = 32 self.wall_list.append(sprite) self.physics_engine = arcadeplus.PhysicsEnginePlatformer( self.character_sprite, self.wall_list, gravity_constant=GRAVITY)
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) arcadeplus.set_background_color(arcadeplus.color.DARK_SLATE_GRAY) # -- Pymunk self.space = pymunk.Space() self.space.iterations = 35 self.space.gravity = (0.0, -900.0) # Lists of sprites or lines self.sprite_list: arcadeplus.SpriteList[ PhysicsSprite] = arcadeplus.SpriteList() self.static_lines = [] # Used for dragging shapes around with the mouse self.shape_being_dragged = None self.last_mouse_position = 0, 0 self.draw_time = 0 self.processing_time = 0 # Create the floor floor_height = 80 body = pymunk.Body(body_type=pymunk.Body.STATIC) shape = pymunk.Segment(body, [0, floor_height], [SCREEN_WIDTH, floor_height], 0.0) shape.friction = 10 self.space.add(shape) self.static_lines.append(shape) # Create the stacks of boxes for row in range(10): for column in range(10): size = 32 mass = 1.0 x = 500 + column * 32 y = (floor_height + size / 2) + row * size moment = pymunk.moment_for_box(mass, (size, size)) body = pymunk.Body(mass, moment) body.position = pymunk.Vec2d(x, y) shape = pymunk.Poly.create_box(body, (size, size)) shape.elasticity = 0.2 shape.friction = 0.9 self.space.add(body, shape) # body.sleep() sprite = BoxSprite( shape, ":resources:images/tiles/boxCrate_double.png", width=size, height=size) self.sprite_list.append(sprite)
def __init__(self): """ Initializer """ # Call the parent class initializer super().__init__(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) # Variables that will hold sprite lists self.player_list = None self.coin_list = None # Set up the player info self.player_sprite = None self.score = 0 # Don't show the mouse cursor self.set_mouse_visible(False) self.processing_time = 0 self.draw_time = 0 self.frame_count = 0 self.fps_start_timer = None self.fps = None arcadeplus.set_background_color(arcadeplus.color.AMAZON)
def setup(self): """ Set up the game and initialize the variables. """ # Sprite lists self.player_list = arcadeplus.SpriteList() self.wall_list = arcadeplus.SpriteList() # Set up the player self.player_sprite = arcadeplus.Sprite(":resources:images/animated_characters/female_person/femalePerson_idle.png", SPRITE_SCALING) self.player_sprite.center_x = 50 self.player_sprite.center_y = 64 self.player_list.append(self.player_sprite) # -- Set up the walls # Create a row of boxes for x in range(173, 650, 64): wall = arcadeplus.Sprite(":resources:images/tiles/boxCrate_double.png", SPRITE_SCALING) wall.center_x = x wall.center_y = 200 self.wall_list.append(wall) # Create a column of boxes for y in range(273, 500, 64): wall = arcadeplus.Sprite(":resources:images/tiles/boxCrate_double.png", SPRITE_SCALING) wall.center_x = 465 wall.center_y = y self.wall_list.append(wall) self.physics_engine = arcadeplus.PhysicsEngineSimple(self.player_sprite, self.wall_list) # Set the background color arcadeplus.set_background_color(arcadeplus.color.AMAZON)
def __init__(self): """ Initializer """ # Call the parent class initializer super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) head_radius = 30 chest_height = 110 chest_width = 70 leg_width = 20 leg_height = 80 arm_width = 15 arm_length = 70 arm_gap = 10 shoulder_height = 15 self.shape_list = make_person(head_radius, chest_height, chest_width, leg_width, leg_height, arm_width, arm_length, arm_gap, shoulder_height) arcadeplus.set_background_color(arcadeplus.color.AMAZON)
def __init__(self, width, height, title): """ Initialize """ # Call the parent class 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) # Variables that will hold sprite lists self.player_list = None self.coin_list = None # Set up the player info self.player_sprite = None self.score = 0 self.level = 1 # Don't show the mouse cursor self.set_mouse_visible(False) # Set the background color arcadeplus.set_background_color(arcadeplus.color.AMAZON)
def __init__(self, width, height, title): super().__init__(width, height, title) file_path = os.path.dirname(os.path.abspath(__file__)) os.chdir(file_path) arcadeplus.set_background_color(arcadeplus.color.AMAZON) self.character_list = arcadeplus.SpriteList() self.character_sprite = arcadeplus.Sprite( ":resources:images/animated_characters/female_person/femalePerson_idle.png", CHARACTER_SCALING) self.character_sprite.center_x = 250 self.character_sprite.center_y = 250 self.character_sprite.change_x = 5 self.character_sprite.change_y = 5 self.character_list.append(self.character_sprite) self.wall_list = arcadeplus.SpriteList() sprite = arcadeplus.Sprite( ":resources:images/tiles/boxCrate_double.png", CHARACTER_SCALING) sprite.position = (330, 330) sprite.angle = 90 self.wall_list.append(sprite) sprite = arcadeplus.Sprite( ":resources:images/tiles/boxCrate_double.png", CHARACTER_SCALING) sprite.position = (170, 170) sprite.angle = 45 self.wall_list.append(sprite) self.physics_engine = arcadeplus.PhysicsEngineSimple( self.character_sprite, self.wall_list)
def __init__(self, width, height, title): super().__init__(width, height, title) arcadeplus.set_background_color(arcadeplus.color.AMAZON) self.texture = arcadeplus.load_texture( ":resources:images/space_shooter/playerShip1_orange.png") assert self.texture.width == 99 assert self.texture.height == 75 self.circle_texture = arcadeplus.make_circle_texture( 10, arcadeplus.color.RED) self.soft_circle_texture = arcadeplus.make_soft_circle_texture( 10, arcadeplus.color.RED, 255, 0) self.soft_square_texture = arcadeplus.make_soft_square_texture( 10, arcadeplus.color.RED, 255, 0) columns = 16 count = 60 sprite_width = 256 sprite_height = 256 file_name = ":resources:images/spritesheets/explosion.png" # Load the explosions from a sprite sheet self.explosion_texture_list = arcadeplus.load_spritesheet( file_name, sprite_width, sprite_height, columns, count)
def __init__(self): """ Initializer """ # Call the parent class initializer super().__init__(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) # Variables that will hold sprite lists self.player_list = None self.coin_list = None self.bullet_list = None # Set up the player info self.player_sprite = None self.score = 0 # Don't show the mouse cursor self.set_mouse_visible(False) # Load sounds. Sounds from kenney.nl self.gun_sound = arcadeplus.load_sound(":resources:sounds/hurt5.wav") self.hit_sound = arcadeplus.load_sound(":resources:sounds/hit5.wav") arcadeplus.set_background_color(arcadeplus.color.AMAZON)
def __init__(self, width, height, title): """ Initializer """ # Call the parent class 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) # Variables that will hold sprite lists self.player_list = None # Set up the player info self.player_sprite = None # Track the current state of what key is pressed self.left_pressed = False self.right_pressed = False self.up_pressed = False self.down_pressed = False # Set the background color arcadeplus.set_background_color(arcadeplus.color.AMAZON)
def setup(self): arcadeplus.set_background_color(arcadeplus.color.AMETHYST) self.text_list.append( arcadeplus.TextLabel("Name: ", self.center_x - 225, self.center_y)) self.textbox_list.append( arcadeplus.TextBox(self.center_x - 125, self.center_y)) self.button_list.append( arcadeplus.SubmitButton(self.textbox_list[0], self.on_submit, self.center_x, self.center_y))
def __init__(self, width, height, title): """ Set up the application. """ super().__init__(width, height, title) self.background_list = None arcadeplus.set_background_color(arcadeplus.color.BLACK) self.grid = None self.recreate_grid()
def main(): # Open up our window arcadeplus.open_window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) arcadeplus.set_background_color(arcadeplus.color.WHITE) # Tell the computer to call the draw command at the specified interval. arcadeplus.schedule(on_draw, 1 / 80) # Run the program arcadeplus.run()
def __init__(self, width, height, title): super().__init__(width, height, title) file_path = os.path.dirname(os.path.abspath(__file__)) os.chdir(file_path) arcadeplus.set_background_color(arcadeplus.color.AMAZON) self.texture = arcadeplus.load_texture( ":resources:images/space_shooter/playerShip1_orange.png")