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 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 setup(self): """ Set up the game here. Call this function to restart the game. """ # Used to keep track of our scrolling self.view_bottom = 0 self.view_left = 0 # Keep track of the score self.score = 0 # Create the Sprite lists self.player_list = arcadeplus.SpriteList() self.wall_list = arcadeplus.SpriteList() self.coin_list = arcadeplus.SpriteList() # Set up the player, specifically placing it at these coordinates. image_source = ":resources:images/animated_characters/female_adventurer/femaleAdventurer_idle.png" self.player_sprite = arcadeplus.Sprite(image_source, CHARACTER_SCALING) self.player_sprite.center_x = 64 self.player_sprite.center_y = 96 self.player_list.append(self.player_sprite) # Create the ground # This shows using a loop to place multiple sprites horizontally for x in range(0, 1250, 64): wall = arcadeplus.Sprite(":resources:images/tiles/grassMid.png", TILE_SCALING) wall.center_x = x wall.center_y = 32 self.wall_list.append(wall) # Put some crates on the ground # This shows using a coordinate list to place sprites coordinate_list = [[512, 96], [256, 96], [768, 96]] for coordinate in coordinate_list: # Add a crate on the ground wall = arcadeplus.Sprite(":resources:images/tiles/boxCrate_double.png", TILE_SCALING) wall.position = coordinate self.wall_list.append(wall) # Use a loop to place some coins for our character to pick up for x in range(128, 1250, 256): coin = arcadeplus.Sprite(":resources:images/items/coinGold.png", COIN_SCALING) coin.center_x = x coin.center_y = 96 self.coin_list.append(coin) # Create the 'physics engine' self.physics_engine = arcadeplus.PhysicsEnginePlatformer(self.player_sprite, self.wall_list, GRAVITY)
def setup(self): """ Set up the game here. Call this function to restart the game. """ # Used to keep track of our scrolling self.view_bottom = 0 self.view_left = 0 # Keep track of the score self.score = 0 # Create the Sprite lists self.player_list = arcadeplus.SpriteList() self.wall_list = arcadeplus.SpriteList() self.coin_list = arcadeplus.SpriteList() # Set up the player, specifically placing it at these coordinates. image_source = ":resources:images/animated_characters/female_adventurer/femaleAdventurer_idle.png" self.player_sprite = arcadeplus.Sprite(image_source, CHARACTER_SCALING) self.player_sprite.center_x = 64 self.player_sprite.center_y = 128 self.player_list.append(self.player_sprite) # --- Load in a map from the tiled editor --- # Name of map file to load map_name = ":resources:tmx_maps/test_map_7.tmx" # Name of the layer in the file that has our platforms/walls platforms_layer_name = 'Platforms' # Name of the layer that has items for pick-up coins_layer_name = 'Coins' # Read in the tiled map my_map = arcadeplus.tilemap.read_tmx(map_name) # -- Platforms self.wall_list = arcadeplus.tilemap.process_layer( my_map, platforms_layer_name, TILE_SCALING) # -- Coins self.coin_list = arcadeplus.tilemap.process_layer( my_map, coins_layer_name, TILE_SCALING) # --- Other stuff # Set the background color if my_map.background_color: arcadeplus.set_background_color(my_map.background_color) # Create the 'physics engine' self.physics_engine = arcadeplus.PhysicsEnginePlatformer( self.player_sprite, self.wall_list, GRAVITY)
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.player_sprite = arcadeplus.Sprite( ":resources:images/animated_characters/female_person/femalePerson_idle.png", PLAYER_SCALING) # Starting position of the player self.player_sprite.center_x = 196 self.player_sprite.center_y = 270 self.player_list.append(self.player_sprite) map_name = ":resources:/tmx_maps/map.tmx" # Read in the tiled map my_map = arcadeplus.tilemap.read_tmx(map_name) self.end_of_map = my_map.map_size.width * GRID_PIXEL_SIZE # --- Platforms --- self.wall_list = arcadeplus.tilemap.process_layer( my_map, 'Platforms', TILE_SCALING) # --- Coins --- self.coin_list = arcadeplus.tilemap.process_layer( my_map, 'Coins', TILE_SCALING) # --- Other stuff # Set the background color if my_map.background_color: arcadeplus.set_background_color(my_map.background_color) # Keep player from running through the wall_list layer self.physics_engine = arcadeplus.PhysicsEnginePlatformer( self.player_sprite, self.wall_list, gravity_constant=GRAVITY) # Set the view port boundaries # These numbers set where we have 'scrolled' to. self.view_left = 0 self.view_bottom = 0 self.game_over = False
def setup(self): """ Set up the game here. Call this function to restart the game. """ # Used to keep track of our scrolling self.view_bottom = 0 self.view_left = 0 # Keep track of the score self.score = 0 # Create the Sprite lists self.player_list = arcadeplus.SpriteList() self.background_list = arcadeplus.SpriteList() self.wall_list = arcadeplus.SpriteList() self.coin_list = arcadeplus.SpriteList() # Set up the player, specifically placing it at these coordinates. self.player_sprite = PlayerCharacter() self.player_sprite.center_x = PLAYER_START_X self.player_sprite.center_y = PLAYER_START_Y self.player_list.append(self.player_sprite) # --- Load in a map from the tiled editor --- # Name of the layer in the file that has our platforms/walls platforms_layer_name = 'Platforms' moving_platforms_layer_name = 'Moving Platforms' # Name of the layer that has items for pick-up coins_layer_name = 'Coins' # Map name map_name = f":resources:tmx_maps/map_with_ladders.tmx" # Read in the tiled map my_map = arcadeplus.tilemap.read_tmx(map_name) # Calculate the right edge of the my_map in pixels self.end_of_map = my_map.map_size.width * GRID_PIXEL_SIZE # -- Platforms self.wall_list = arcadeplus.tilemap.process_layer(my_map, platforms_layer_name, TILE_SCALING) # -- Moving Platforms moving_platforms_list = arcadeplus.tilemap.process_layer(my_map, moving_platforms_layer_name, TILE_SCALING) for sprite in moving_platforms_list: self.wall_list.append(sprite) # -- Background objects self.background_list = arcadeplus.tilemap.process_layer(my_map, "Background", TILE_SCALING) # -- Background objects self.ladder_list = arcadeplus.tilemap.process_layer(my_map, "Ladders", TILE_SCALING) # -- Coins self.coin_list = arcadeplus.tilemap.process_layer(my_map, coins_layer_name, TILE_SCALING) # --- Other stuff # Set the background color if my_map.background_color: arcadeplus.set_background_color(my_map.background_color) # Create the 'physics engine' self.physics_engine = arcadeplus.PhysicsEnginePlatformer(self.player_sprite, self.wall_list, gravity_constant=GRAVITY, ladders=self.ladder_list)
def start_new_game(self): """ Set up the game and initialize the variables. """ # Sprite lists self.all_sprites_list = arcadeplus.SpriteList() self.wall_list = arcadeplus.SpriteList() self.player_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 = 64 self.player_sprite.center_y = 270 self.player_list.append(self.player_sprite) self.all_sprites_list.append(self.player_sprite) map_array = get_map() # Right edge of the map in pixels self.end_of_map = len(map_array[0]) * GRID_PIXEL_SIZE map_items = [ ":resources:images/tiles/boxCrate_double.png", ":resources:images/tiles/grassCenter.png", ":resources:images/tiles/grassCorner_left.png", ":resources:images/tiles/grassCorner_right.png", ":resources:images/tiles/grassHill_left.png", ":resources:images/tiles/grassHill_right.png", ":resources:images/tiles/grassLeft.png", ":resources:images/tiles/grassMid.png", ":resources:images/tiles/grassRight.png", ":resources:images/tiles/stoneHalf.png" ] for row_index, row in enumerate(map_array): for column_index, item in enumerate(row): if item == -1: continue else: wall = arcadeplus.Sprite(map_items[item], SPRITE_SCALING) # Change the collision polygon to be a ramp instead of # a rectangle if item == 4: wall.points = ((-wall.width // 2, wall.height // 2), (wall.width // 2, -wall.height // 2), (-wall.width // 2, -wall.height // 2)) elif item == 5: wall.points = ((-wall.width // 2, -wall.height // 2), (wall.width // 2, -wall.height // 2), (wall.width // 2, wall.height // 2)) wall.right = column_index * 64 wall.top = (7 - row_index) * 64 self.all_sprites_list.append(wall) self.wall_list.append(wall) self.physics_engine = \ arcadeplus.PhysicsEnginePlatformer(self.player_sprite, self.wall_list, gravity_constant=GRAVITY) # Set the background color arcadeplus.set_background_color(arcadeplus.color.AMAZON) # Set the viewport boundaries # These numbers set where we have 'scrolled' to. self.view_left = 0 self.view_bottom = 0 self.game_over = False
def setup(self, level): """ Set up the game here. Call this function to restart the game. """ # Used to keep track of our scrolling self.view_bottom = 0 self.view_left = 0 # Keep track of the score self.score = 0 # Create the Sprite lists self.player_list = arcadeplus.SpriteList() self.foreground_list = arcadeplus.SpriteList() self.background_list = arcadeplus.SpriteList() self.wall_list = arcadeplus.SpriteList() self.coin_list = arcadeplus.SpriteList() # Set up the player, specifically placing it at these coordinates. image_source = ":resources:images/animated_characters/female_adventurer/femaleAdventurer_idle.png" self.player_sprite = arcadeplus.Sprite(image_source, CHARACTER_SCALING) self.player_sprite.center_x = PLAYER_START_X self.player_sprite.center_y = PLAYER_START_Y self.player_list.append(self.player_sprite) # --- Load in a map from the tiled editor --- # Name of the layer in the file that has our platforms/walls platforms_layer_name = 'Platforms' # Name of the layer that has items for pick-up coins_layer_name = 'Coins' # Name of the layer that has items for foreground foreground_layer_name = 'Foreground' # Name of the layer that has items for background background_layer_name = 'Background' # Name of the layer that has items we shouldn't touch dont_touch_layer_name = "Don't Touch" # Map name map_name = f":resources:tmx_maps/map2_level_{level}.tmx" # Read in the tiled map my_map = arcadeplus.tilemap.read_tmx(map_name) # Calculate the right edge of the my_map in pixels self.end_of_map = my_map.map_size.width * GRID_PIXEL_SIZE # -- Background self.background_list = arcadeplus.tilemap.process_layer( my_map, background_layer_name, TILE_SCALING) # -- Foreground self.foreground_list = arcadeplus.tilemap.process_layer( my_map, foreground_layer_name, TILE_SCALING) # -- Platforms self.wall_list = arcadeplus.tilemap.process_layer( my_map, platforms_layer_name, TILE_SCALING) # -- Coins self.coin_list = arcadeplus.tilemap.process_layer( my_map, coins_layer_name, TILE_SCALING) # -- Don't Touch Layer self.dont_touch_list = arcadeplus.tilemap.process_layer( my_map, dont_touch_layer_name, TILE_SCALING) # --- Other stuff # Set the background color if my_map.background_color: arcadeplus.set_background_color(my_map.background_color) # Create the 'physics engine' self.physics_engine = arcadeplus.PhysicsEnginePlatformer( self.player_sprite, self.wall_list, GRAVITY)
def setup(self): """ Set up the game and initialize the variables. """ # Sprite lists self.all_wall_list = arcadeplus.SpriteList() self.static_wall_list = arcadeplus.SpriteList() self.moving_wall_list = arcadeplus.SpriteList() self.player_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 = 2 * GRID_PIXEL_SIZE self.player_sprite.center_y = 3 * GRID_PIXEL_SIZE self.player_list.append(self.player_sprite) # Create floor for i in range(30): wall = arcadeplus.Sprite(":resources:images/tiles/grassMid.png", SPRITE_SCALING) wall.bottom = 0 wall.center_x = i * GRID_PIXEL_SIZE self.static_wall_list.append(wall) self.all_wall_list.append(wall) # Create platform side to side wall = arcadeplus.Sprite(":resources:images/tiles/grassMid.png", SPRITE_SCALING) wall.center_y = 3 * GRID_PIXEL_SIZE wall.center_x = 3 * GRID_PIXEL_SIZE wall.boundary_left = 2 * GRID_PIXEL_SIZE wall.boundary_right = 5 * GRID_PIXEL_SIZE wall.change_x = 2 * SPRITE_SCALING self.all_wall_list.append(wall) self.moving_wall_list.append(wall) # Create platform side to side wall = arcadeplus.Sprite(":resources:images/tiles/grassMid.png", SPRITE_SCALING) wall.center_y = 3 * GRID_PIXEL_SIZE wall.center_x = 7 * GRID_PIXEL_SIZE wall.boundary_left = 5 * GRID_PIXEL_SIZE wall.boundary_right = 9 * GRID_PIXEL_SIZE wall.change_x = -2 * SPRITE_SCALING self.all_wall_list.append(wall) self.moving_wall_list.append(wall) # Create platform moving up and down wall = arcadeplus.Sprite(":resources:images/tiles/grassMid.png", SPRITE_SCALING) wall.center_y = 5 * GRID_PIXEL_SIZE wall.center_x = 5 * GRID_PIXEL_SIZE wall.boundary_top = 8 * GRID_PIXEL_SIZE wall.boundary_bottom = 4 * GRID_PIXEL_SIZE wall.change_y = 2 * SPRITE_SCALING self.all_wall_list.append(wall) self.moving_wall_list.append(wall) # Create platform moving diagonally wall = arcadeplus.Sprite(":resources:images/tiles/grassMid.png", SPRITE_SCALING) wall.center_y = 5 * GRID_PIXEL_SIZE wall.center_x = 8 * GRID_PIXEL_SIZE wall.boundary_left = 7 * GRID_PIXEL_SIZE wall.boundary_right = 9 * GRID_PIXEL_SIZE wall.boundary_top = 8 * GRID_PIXEL_SIZE wall.boundary_bottom = 4 * GRID_PIXEL_SIZE wall.change_x = 2 * SPRITE_SCALING wall.change_y = 2 * SPRITE_SCALING self.all_wall_list.append(wall) self.moving_wall_list.append(wall) self.physics_engine = \ arcadeplus.PhysicsEnginePlatformer(self.player_sprite, self.all_wall_list, gravity_constant=GRAVITY) # Set the background color arcadeplus.set_background_color(arcadeplus.color.AMAZON) # Set the viewport boundaries # These numbers set where we have 'scrolled' to. self.view_left = 0 self.view_bottom = 0 self.game_over = False