def __init__(self): super().__init__() self.level = 1 # Get the background image self.background_image = arcade.load_texture(ASSETS_PATH / "backgrounds" / "BlueStars.png") self.background_color = arcade.color.DARK_MIDNIGHT_BLUE # Gravity (0,0) is basically no external gravity acting on anything # Damping of 1.0 means no friction, 0.0 is max friction gravity = (0, 0) damping = 1.0 self.draw_strength = 1 # Create the physics engine self.physics_engine = arcade.PymunkPhysicsEngine( damping=damping, gravity=gravity ) # Define the launcher sprite self.launcher = arcade.Sprite(SPRITE_PATH / "launcher_lite.png") self.launcher.right = 800 self.launcher.center_y = 450 # Define the player sprite self.player = arcade.Sprite(SPRITE_PATH / "ball.png") self.player.center_x = self.launcher.right + 25 self.player.center_y = self.launcher.center_y self.player.state = PlayerStates.WAITING self.player.on_screen = True # Define a pointing arrow sprite # Add the player. # For the player, we set the damping to a lower value, which increases # the damping rate. This prevents the character from traveling too far # after the player lets off the movement keys. # Setting the moment to PymunkPhysicsEngine.MOMENT_INF prevents it from # rotating. # Friction normally goes between 0 (no friction) and 1.0 (high friction) # Friction is between two objects in contact. It is important to remember # in top-down games that friction moving along the 'floor' is controlled # by damping. self.physics_engine.add_sprite( self.player, friction=0, mass=200, moment=arcade.PymunkPhysicsEngine.MOMENT_INF, collision_type="player", # max_horizontal_velocity=2000, # max_vertical_velocity=2000, radius=20.0, ) self.physics_engine.add_sprite( self.launcher, body_type=arcade.PymunkPhysicsEngine.KINEMATIC, collision_type="none", )
def setup_physics_engine(game_resources: GameResources): # --- Pymunk Physics Engine Setup --- # The default damping for every object controls the percent of velocity # the object will keep each second. A value of 1.0 is no speed loss, # 0.9 is 10% per second, 0.1 is 90% per second. # For top-down games, this is basically the friction for moving objects. # For platformers with gravity, this should probably be set to 1.0. # Default value is 1.0 if not specified. damping = DEFAULT_DAMPING # Set the gravity. (0, 0) is good for outer space and top-down. gravity = (0, -GRAVITY) # Create the physics engine physics_engine = arcade.PymunkPhysicsEngine(damping=damping, gravity=gravity) # Add the player. # For the player, we set the damping to a lower value, which increases # the damping rate. This prevents the character from traveling too far # after the player lets off the movement keys. # Setting the moment to PymunkPhysicsEngine.MOMENT_INF prevents it from # rotating. # Friction normally goes between 0 (no friction) and 1.0 (high friction) # Friction is between two objects in contact. It is important to remember # in top-down games that friction moving along the 'floor' is controlled # by damping. physics_engine.add_sprite( game_resources.player_sprite, friction=PLAYER_FRICTION, mass=PLAYER_MASS, moment=arcade.PymunkPhysicsEngine.MOMENT_INF, collision_type="player", max_horizontal_velocity=PLAYER_MAX_HORIZONTAL_SPEED, max_vertical_velocity=PLAYER_MAX_VERTICAL_SPEED) # Create the walls. # By setting the body type to PymunkPhysicsEngine.STATIC the walls can't # move. # Movable objects that respond to forces are PymunkPhysicsEngine.DYNAMIC # PymunkPhysicsEngine.KINEMATIC objects will move, but are assumed to be # repositioned by code and don't respond to physics forces. # Dynamic is default. physics_engine.add_sprite_list(game_resources.wall_list, friction=WALL_FRICTION, collision_type="wall", body_type=arcade.PymunkPhysicsEngine.STATIC) # Create the items physics_engine.add_sprite_list(game_resources.item_list, friction=DYNAMIC_ITEM_FRICTION, collision_type="item") return physics_engine
def setup(self): self.player_list = ac.SpriteList() self.bullet_list = ac.SpriteList() map_name = "./resources/map.tmx" my_map = ac.tilemap.read_tmx(map_name) self.wall_list = ac.tilemap.process_layer(my_map, "Platforms", sprite_scaling_tiles) self.item_list = ac.tilemap.process_layer(my_map, "Dynamic Items", sprite_scaling_tiles) self.player_sprite = PersonSprite() # set player location grid_x = 1 grid_y = 1 self.player_sprite.center_x = sprite_size * grid_x + sprite_size / 2 self.player_sprite.center_y = sprite_size * grid_y + sprite_size / 2 self.player_list.append(self.player_sprite) # Engine setup damping = default_damping gravity = (0, -default_gravity) self.physics_engine = ac.PymunkPhysicsEngine(damping=damping, gravity=gravity) self.physics_engine.add_sprite( self.player_sprite, friction=player_friction, mass=player_mass, moment=ac.PymunkPhysicsEngine.MOMENT_INF, collision_type="player", max_horizontal_velocity=player_max_horizontal_speed, max_vertical_velocity=player_max_vertical_speed, ) self.physics_engine.add_sprite_list( self.wall_list, friction=wall_friction, collision_type="wall", body_type=ac.PymunkPhysicsEngine.STATIC, ) self.physics_engine.add_sprite_list(self.item_list, friction=dynamic_item_friction, collision_type="item")
def __init__(self, cast): self.player_sprite = cast['player'][0] # self.wall_list = cast["walls"] # Set the gravity. (0, 0) is good for outer space and top-down. self.movement_value = 0 self.jump_value = 0 gravity = (0, -constants.GRAVITY) damping = constants.DEFAULT_DAMPING # Create the physics engine self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping, gravity=gravity) self.physics_engine.add_sprite( self.player_sprite, friction=constants.PLAYER_FRICTION, mass=constants.PLAYER_MASS, moment=arcade.PymunkPhysicsEngine.MOMENT_INF, collision_type="player", max_horizontal_velocity=constants.PLAYER_MAX_HORIZONTAL_SPEED, max_vertical_velocity=constants.PLAYER_MAX_VERTICAL_SPEED) self.physics_engine.add_sprite_list( cast['walls'], friction=constants.WALL_FRICTION, collision_type="wall", body_type=arcade.PymunkPhysicsEngine.STATIC) self.physics_engine.add_sprite_list( cast['invisible'], friction=constants.WALL_FRICTION, collision_type="wall", body_type=arcade.PymunkPhysicsEngine.STATIC) self.physics_engine.add_sprite_list( cast['moving_walls'], friction=constants.WALL_FRICTION, collision_type="wall", body_type=arcade.PymunkPhysicsEngine.STATIC) self.is_on_ground = self.physics_engine.is_on_ground( self.player_sprite)
def setup(self): """ Set up everything with the game """ self.output_service.setup() # --- Pymunk Physics Engine Setup --- # The default damping for every object controls the percent of velocity # the object will keep each second. A value of 1.0 is no speed loss, # 0.9 is 10% per second, 0.1 is 90% per second. # For top-down games, this is basically the friction for moving objects. # For platformers with gravity, this should probably be set to 1.0. # Default value is 1.0 if not specified. damping = DEFAULT_DAMPING # Set the gravity. (0, 0) is good for outer space and top-down. gravity = (0, -GRAVITY) # Create the physics engine self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping, gravity=gravity) # Add the player. self.physics_engine.add_sprite(self.output_service.player_sprite, friction=PLAYER_FRICTION, mass=PLAYER_MASS, moment=arcade.PymunkPhysicsEngine.MOMENT_INF, collision_type="player", max_horizontal_velocity=PLAYER_MAX_HORIZONTAL_SPEED, max_vertical_velocity=PLAYER_MAX_VERTICAL_SPEED) # Create the crash zones. self.physics_engine.add_sprite_list(self.output_service.wall_list, friction=WALL_FRICTION, collision_type="crash", body_type=arcade.PymunkPhysicsEngine.STATIC) # Create the Landing Zones self.physics_engine.add_sprite_list(self.output_service.platform_list, friction=WALL_FRICTION, collision_type="land", body_type=arcade.PymunkPhysicsEngine.STATIC)
def setup(self): """ Set up everything with the game """ # Create the sprite lists self.player_list = arcade.SpriteList() self.bullet_list = arcade.SpriteList() # Read in the tiled map map_name = "pymunk_test_map.tmx" my_map = arcade.tilemap.read_tmx(map_name) # Read in the map layers self.wall_list = arcade.tilemap.process_layer(my_map, 'Platforms', SPRITE_SCALING_TILES) self.item_list = arcade.tilemap.process_layer(my_map, 'Dynamic Items', SPRITE_SCALING_TILES) # Create player sprite self.player_sprite = arcade.Sprite(":resources:images/animated_characters/female_person/femalePerson_idle.png", SPRITE_SCALING_PLAYER) # Set player location grid_x = 1 grid_y = 1 self.player_sprite.center_x = SPRITE_SIZE * grid_x + SPRITE_SIZE / 2 self.player_sprite.center_y = SPRITE_SIZE * grid_y + SPRITE_SIZE / 2 # Add to player sprite list self.player_list.append(self.player_sprite) # --- Pymunk Physics Engine Setup --- # The default damping for every object controls the percent of velocity # the object will keep each second. A value of 1.0 is no speed loss, # 0.9 is 10% per second, 0.1 is 90% per second. # For top-down games, this is basically the friction for moving objects. # For platformers with gravity, this should probably be set to 1.0. # Default value is 1.0 if not specified. damping = DEFAULT_DAMPING # Set the gravity. (0, 0) is good for outer space and top-down. gravity = (0, -GRAVITY) # Create the physics engine self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping, gravity=gravity) # Add the player. # For the player, we set the damping to a lower value, which increases # the damping rate. This prevents the character from traveling too far # after the player lets off the movement keys. # Setting the moment to PymunkPhysicsEngine.MOMENT_INF prevents it from # rotating. # Friction normally goes between 0 (no friction) and 1.0 (high friction) # Friction is between two objects in contact. It is important to remember # in top-down games that friction moving along the 'floor' is controlled # by damping. self.physics_engine.add_sprite(self.player_sprite, friction=PLAYER_FRICTION, mass=PLAYER_MASS, moment=arcade.PymunkPhysicsEngine.MOMENT_INF, collision_type="player", max_horizontal_velocity=PLAYER_MAX_HORIZONTAL_SPEED, max_vertical_velocity=PLAYER_MAX_VERTICAL_SPEED) # Create the walls. # By setting the body type to PymunkPhysicsEngine.STATIC the walls can't # move. # Movable objects that respond to forces are PymunkPhysicsEngine.DYNAMIC # PymunkPhysicsEngine.KINEMATIC objects will move, but are assumed to be # repositioned by code and don't respond to physics forces. # Dynamic is default. self.physics_engine.add_sprite_list(self.wall_list, friction=WALL_FRICTION, collision_type="wall", body_type=arcade.PymunkPhysicsEngine.STATIC) # Create the items self.physics_engine.add_sprite_list(self.item_list, friction=DYNAMIC_ITEM_FRICTION, collision_type="item")
def setup(self): self.background = arcade.load_texture( "assets/background_final.png") self.left_pressed = False self.right_pressed = False self.view_left = 0 self.immune_for = 3 # initiailze player list self.player_list = arcade.SpriteList() # name = "main_char" if self.window.hits_left == 4: self.player = entity.Entity("hazmat") elif self.window.hits_left == 3: self.player = entity.Entity("main_char_gas") elif self.window.hits_left == 2: self.player = entity.Entity("main_char_mask") else: self.player = entity.Entity("main_char") grid_x = 1 grid_y = 1 self.player.center_x = constants.SPRITE_SIZE * \ grid_x + constants.SPRITE_SIZE / 2 self.player.center_y = constants.SPRITE_SIZE * \ grid_y + constants.SPRITE_SIZE / 2 # self.player.center_x = constants.WIDTH * 6 self.player_list.append(self.player) self.cashier = arcade.Sprite("assets/cashier/closed.png") self.cashier.center_y = self.player.center_y self.cashier.center_x = self.window.w * 6 map = arcade.tilemap.read_tmx("assets/map_real.tmx") self.platform_list = arcade.tilemap.process_layer( map, "Platform", constants.SCALING_TILES) # Spatial hashing speeds time to find collision # ENEMY self.enemy_list = arcade.SpriteList() enemy1 = entity.Entity("employee") enemy1.bottom = constants.SPRITE_SIZE enemy1.left = 6 * constants.SPRITE_SIZE enemy1.boundary_left = enemy1.left - 300 enemy1.boundary_right = enemy1.left + 250 enemy1.change_x = 2 self.enemy_list.append(enemy1) enemy2 = entity.Entity("karen") enemy2.bottom = constants.SPRITE_SIZE enemy2.left = 15 * constants.SPRITE_SIZE enemy2.boundary_left = enemy2.left - 50 enemy2.boundary_right = enemy2.left + 256 enemy2.change_x = 2 self.enemy_list.append(enemy2) enemy3 = entity.Entity("fatman") enemy3.bottom = 4 * constants.SPRITE_SIZE enemy3.left = 12 * constants.SPRITE_SIZE enemy3.boundary_left = enemy3.left enemy3.boundary_right = enemy3.left + 512 enemy3.change_x = 2 self.enemy_list.append(enemy3) enemy4 = entity.Entity("karen") enemy4.bottom = 3 * constants.SPRITE_SIZE enemy4.left = 6 * constants.SPRITE_SIZE enemy4.boundary_left = enemy4.left - 256 enemy4.boundary_right = enemy4.left + 128 enemy4.change_x = 1 self.enemy_list.append(enemy4) enemy5 = entity.Entity("employee") enemy5.bottom = 7 * constants.SPRITE_SIZE enemy5.left = 17 * constants.SPRITE_SIZE enemy5.boundary_left = enemy5.left - 50 enemy5.boundary_right = enemy5.left + 256 enemy5.change_x = 2 self.enemy_list.append(enemy5) enemy6 = entity.Entity("fatman") enemy6.bottom = 7 * constants.SPRITE_SIZE enemy6.left = 29 * constants.SPRITE_SIZE enemy6.boundary_left = enemy6.left - 256 enemy6.boundary_right = enemy6.left + 64 enemy6.change_x = 3 self.enemy_list.append(enemy6) enemy7 = entity.Entity("employee") enemy7.bottom = constants.SPRITE_SIZE enemy7.left = 32 * constants.SPRITE_SIZE enemy7.boundary_left = enemy7.left - 64 enemy7.boundary_right = enemy7.left + 18 * constants.SPRITE_SIZE enemy7.change_x = 5 self.enemy_list.append(enemy7) enemy8 = entity.Entity("fatman") enemy8.bottom = 7 * constants.SPRITE_SIZE enemy8.left = 48 * constants.SPRITE_SIZE enemy8.boundary_left = enemy8.left - 128 enemy8.boundary_right = enemy8.left + 200 enemy8.change_x = 7 self.enemy_list.append(enemy8) enemy9 = entity.Entity("karen") enemy9.bottom = constants.SPRITE_SIZE enemy9.left = 48 * constants.SPRITE_SIZE enemy9.boundary_left = enemy9.left - 18 * constants.SPRITE_SIZE enemy9.boundary_right = enemy9.left + 64 enemy9.change_x = 3 self.enemy_list.append(enemy9) enemy10 = entity.Entity("karen") enemy10.bottom = constants.SPRITE_SIZE enemy10.left = 40 * constants.SPRITE_SIZE enemy10.boundary_left = enemy10.left - 9 * constants.SPRITE_SIZE enemy10.boundary_right = enemy10.left + 9 * constants.SPRITE_SIZE enemy10.change_x = 5 self.enemy_list.append(enemy10) enemy11 = entity.Entity("fatman") enemy11.bottom = constants.SPRITE_SIZE enemy11.left = 48 * constants.SPRITE_SIZE enemy11.boundary_left = enemy11.left - 18 * constants.SPRITE_SIZE enemy11.boundary_right = enemy11.left + 64 enemy11.change_x = 5 self.enemy_list.append(enemy11) enemy12 = entity.Entity("employee") enemy12.bottom = constants.SPRITE_SIZE enemy12.left = 56 * constants.SPRITE_SIZE enemy12.boundary_left = enemy12.left - 144 enemy12.boundary_right = enemy12.left + 300 enemy12.change_x = 3 self.enemy_list.append(enemy12) enemy13 = entity.Entity("fatman") enemy13.bottom = 7 * constants.SPRITE_SIZE enemy13.left = 64 * constants.SPRITE_SIZE enemy13.boundary_left = enemy13.left - 128 enemy13.boundary_right = enemy13.left + 200 enemy13.change_x = 3 self.enemy_list.append(enemy13) # Create physics self.physics_engine = arcade.PymunkPhysicsEngine( damping=constants.DEFAULT_DAMPING, gravity=constants.GRAVITY) self.physics_engine.add_sprite(self.player, friction=constants.PLAYER_FRICTOIN, mass=constants.PLAYER_MASS, moment=arcade.PymunkPhysicsEngine.MOMENT_INF, collision_type="player", max_horizontal_velocity=constants.PLAYER_MAX_VX, max_vertical_velocity=constants.PLAYER_MAX_VY) self.physics_engine.add_sprite_list(self.platform_list, friction=constants.FLOOR_FRICTION, collision_type="floor", body_type=arcade.PymunkPhysicsEngine.STATIC) self.physics_engine.add_sprite_list(self.window.item_list, friction=constants.DYNAMIC_ITEM_FRICTION, collision_type="item") self.physics_engine.add_sprite(self.cashier, friction=constants.DYNAMIC_ITEM_FRICTION, collision_type="floor")
def setup(self): """ Set up everything with the game """ self.lives = LIVES_AT_START # Create the sprite lists self.player_list = arcade.SpriteList() self.bullet_list = arcade.SpriteList() # Read in the tiled map map_name = "resources/tmx_maps/pymunk_test_map.tmx" my_map = arcade.tilemap.read_tmx(map_name) # Read in the map layers self.wall_list = arcade.tilemap.process_layer( my_map, 'Platforms', SPRITE_SCALING_TILES, hit_box_algorithm="Detailed") #self.coins_list = arcade.tilemap.process_layer(my_map, # 'Dynamic Items', # SPRITE_SCALING_TILES, # hit_box_algorithm="Detailed") self.coins_list = arcade.tilemap.process_layer( my_map, 'coins_layer', SPRITE_SCALING_TILES, hit_box_algorithm="Detailed") self.key_lock_door_list = arcade.tilemap.process_layer( my_map, 'key_lock_door_layer', SPRITE_SCALING_TILES, hit_box_algorithm="Detailed") self.ladder_list = arcade.tilemap.process_layer( my_map, 'ladders', SPRITE_SCALING_TILES, use_spatial_hash=True, hit_box_algorithm="Detailed") self.trap_list = arcade.tilemap.process_layer( my_map, 'traps', SPRITE_SCALING_TILES, use_spatial_hash=True, hit_box_algorithm="Detailed") self.mechanics_list = arcade.tilemap.process_layer( my_map, 'mechanics', SPRITE_SCALING_TILES, use_spatial_hash=True) #hit_box_algorithm="Detailed") self.mechandler_list = arcade.tilemap.process_layer( my_map, 'mec_handlers_layer', SPRITE_SCALING_TILES, #use_spatial_hash=True, hit_box_algorithm="Detailed") #self.master_status = "leverMid" #self.master_status_cyclist.next() self.master_status = mechandler_texture_names_list[ 0] #self.master_status_cyclist.next() self.mechandlers_textures = MECHANDLERS_TEXTURES #self.master_status_png = arcade.Sprite VA ET VIENT SELON TMX #rint(dir(self.mechandler_list[0])) #print(self.mechandler_list[0].texture) #print(self.mechandler_list[0].textures) self.master_status_png = mechandler_texture_list[0] self.master_status_name = mechandler_texture_names_list[0] #self.master_status_png = self.mechandler_list[0].filename print(f"SETUP self.master_status_png {self.master_status_png}") self.master_status_cyclist = CYCLIST_OF_MECHANDLERS_TEXTURES self.master_status_name_cyclist = cyclist_of_mechandler_texture_names_list self.master_status_index = 0 self.stairs_list = arcade.tilemap.process_layer( my_map, 'Stairs', SPRITE_SCALING_TILES, use_spatial_hash=True, hit_box_algorithm="Detailed") self.enemy_list = arcade.tilemap.process_layer( my_map, 'enemies', SPRITE_SCALING_TILES, use_spatial_hash=True, hit_box_algorithm="Detailed") self.lowfric_list = arcade.tilemap.process_layer( my_map, 'low_friction_platforms', SPRITE_SCALING_TILES, use_spatial_hash=True, hit_box_algorithm="Detailed") startposition_layer_name = 'Startposition' self.startposition_list = arcade.tilemap.process_layer( map_object=my_map, layer_name=startposition_layer_name, scaling=TILE_SCALING, use_spatial_hash=True) start_XY = tuple((self.startposition_list[0].center_x, self.startposition_list[0].center_y)) # Create player sprite self.player_sprite = PlayerSprite(self.ladder_list, hit_box_algorithm="Detailed") # Set player location #grid_x = 1 #grid_y = 1 #grid_x = 7 #grid_y = 15 #self.player_sprite.center_x = SPRITE_SIZE * grid_x + SPRITE_SIZE / 2 #self.player_sprite.center_y = SPRITE_SIZE * grid_y + SPRITE_SIZE / 2 self.player_sprite.center_x = start_XY[0] self.player_sprite.center_y = start_XY[1] # Add to player sprite list self.player_list.append(self.player_sprite) # Moving Sprite self.autonom_moving_sprites_list = arcade.tilemap.process_layer( my_map, 'Moving Platforms', SPRITE_SCALING_TILES) # --- Pymunk Physics Engine Setup --- # The default damping for every object controls the percent of velocity # the object will keep each second. A value of 1.0 is no speed loss, # 0.9 is 10% per second, 0.1 is 90% per second. # For top-down games, this is basically the friction for moving objects. # For platformers with gravity, this should probably be set to 1.0. # Default value is 1.0 if not specified. damping = DEFAULT_DAMPING # Set the gravity. (0, 0) is good for outer space and top-down. gravity = (0, -GRAVITY) # Create the physics engine self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping, gravity=gravity) def wall_hit_handler(bullet_sprite, _wall_sprite, _arbiter, _space, _data): """ Called for bullet/wall collision """ bullet_sprite.remove_from_sprite_lists() self.physics_engine.add_collision_handler( "bullet", "wall", post_handler=wall_hit_handler) def item_hit_handler(bullet_sprite, item_sprite, _arbiter, _space, _data): """ Called for bullet/wall collision """ bullet_sprite.remove_from_sprite_lists() item_sprite.remove_from_sprite_lists() self.physics_engine.add_collision_handler( "bullet", "item", post_handler=item_hit_handler) #def mechanicshandler_hit_handler(self, bullet_sprite, mechandler_sprite, _arbiter, _space, _data): def mechanicshandler_hit_handler(bullet_sprite, mechandler_sprite, _arbiter, _space, _data): """ Called for bullet/wall collision """ bullet_sprite.remove_from_sprite_lists() #print(f"mechandler_sprite.status {mechandler_sprite.status} self.master_status {self.master_status}") print( f"1mechandler_sprite.properties['status'] {mechandler_sprite.properties['status']} self.master_status {self.master_status}" ) #mechandler_sprite.status = leverRight #mechandler_sprite.status = "leverRight" #self.master_status ="leverRight" #self.master_status_index += 1 #self.master_status_cyclist.next() self.master_status_png = next(self.master_status_cyclist) print( f"type(self.master_status_png) {type(self.master_status_png)}" ) #self.master_status_name = next(self.master_status_name) # cyclist_of_mechandler_texture_names_list self.master_status_name = next(self.master_status_name_cyclist) print( f"type(self.master_status_name) {type(self.master_status_name)}" ) #cyclist_of_mechandler_texture_names_list #print(f"self.master_status_png {self.master_status_png}") print( f"2mechandler_sprite.properties['status'] {mechandler_sprite.properties['status']} self.master_status {self.master_status}" ) print("\n") print(f". self.master_status_index {self.master_status_index}") print( f".. self.master_status_cyclist {self.master_status_cyclist}" ) #print(f"... self.master_status_cyclist[self.master_status_index] {self.master_status_cyclist[self.master_status_index]}") CYCLE IS NOT SUSCRIPTABLE self.physics_engine.add_collision_handler( "bullet", "mechandler", post_handler=mechanicshandler_hit_handler) # Add the player. # For the player, we set the damping to a lower value, which increases # the damping rate. This prevents the character from traveling too far # after the player lets off the movement keys. # Setting the moment to PymunkPhysicsEngine.MOMENT_INF prevents it from # rotating. # Friction normally goes between 0 (no friction) and 1.0 (high friction) # Friction is between two objects in contact. It is important to remember # in top-down games that friction moving along the 'floor' is controlled # by damping. self.physics_engine.add_sprite( self.player_sprite, friction=PLAYER_FRICTION, mass=PLAYER_MASS, moment=arcade.PymunkPhysicsEngine.MOMENT_INF, collision_type="player", max_horizontal_velocity=PLAYER_MAX_HORIZONTAL_SPEED, max_vertical_velocity=PLAYER_MAX_VERTICAL_SPEED) # Create the walls. # By setting the body type to PymunkPhysicsEngine.STATIC the walls can't # move. # Movable objects that respond to forces are PymunkPhysicsEngine.DYNAMIC # PymunkPhysicsEngine.KINEMATIC objects will move, but are assumed to be # repositioned by code and don't respond to physics forces. # Dynamic is default. self.physics_engine.add_sprite_list( self.wall_list, friction=WALL_FRICTION, collision_type="wall", body_type=arcade.PymunkPhysicsEngine.STATIC) self.physics_engine.add_sprite_list( self.lowfric_list, friction=ICE_FRICTION, collision_type="ice", body_type=arcade.PymunkPhysicsEngine.STATIC) # Create the items self.physics_engine.add_sprite_list(self.coins_list, friction=DYNAMIC_ITEM_FRICTION, collision_type="item") self.physics_engine.add_sprite_list( self.trap_list, friction=WALL_FRICTION, #collision_type="wall", collision_type="traps", body_type=arcade.PymunkPhysicsEngine.STATIC) self.physics_engine.add_sprite_list( self.key_lock_door_list, friction=WALL_FRICTION, #collision_type="wall", collision_type="kld", body_type=arcade.PymunkPhysicsEngine.STATIC) self.physics_engine.add_sprite_list( self.mechandler_list, friction=WALL_FRICTION, #collision_type="wall", collision_type="mechandler", body_type=arcade.PymunkPhysicsEngine.STATIC) # Add kinematic sprites self.physics_engine.add_sprite_list( self.mechanics_list, body_type=arcade.PymunkPhysicsEngine.KINEMATIC)
def setup(self): """ Set up everything with the game """ # Create the sprite lists self.player_list = arcade.SpriteList() self.enemy_list = arcade.SpriteList() self.bullet_list = arcade.SpriteList() # Read in the tiled map map_name = "tmx_maps/pymunk_test_map.tmx" my_map = arcade.tilemap.read_tmx(map_name) # Read in the map layers self.wall_list = arcade.tilemap.process_layer( my_map, 'Platforms', SPRITE_SCALING_TILES, hit_box_algorithm="Detailed") self.item_list = arcade.tilemap.process_layer( my_map, 'Dynamic Items', SPRITE_SCALING_TILES, hit_box_algorithm="Detailed") self.ladder_list = arcade.tilemap.process_layer( my_map, 'Ladders', SPRITE_SCALING_TILES, use_spatial_hash=True, hit_box_algorithm="Detailed") # Create player sprite self.player_sprite = PlayerSprite(self.ladder_list, hit_box_algorithm="Detailed") # Create player health bar sprite ## self.player_healthbar = PlayerHealthBar(self.player_sprite, ## self.player_sprite.scale, ## self.player_sprite.max_health, ## hit_box_algorithm="None") # Set player location grid_x = 1 grid_y = 1 self.player_sprite.center_x = SPRITE_SIZE * grid_x + SPRITE_SIZE / 2 self.player_sprite.center_y = SPRITE_SIZE * grid_y + SPRITE_SIZE / 2 # Add to player sprite list self.player_list.append(self.player_sprite) # Moving Sprite self.moving_sprites_list = arcade.tilemap.process_layer( my_map, 'Moving Platforms', SPRITE_SCALING_TILES) # Create an Enemy for testing purposes enemy = EnemySprite("images/enemies/slimeBlue.png", 0.5) enemy.bottom = SPRITE_SIZE enemy.left = SPRITE_SIZE * 2 # Set boundaries on the left/right the enemy can't cross enemy.boundary_right = SPRITE_SIZE * 8 enemy.boundary_left = SPRITE_SIZE * 3 enemy.change_x = 2 self.enemy_list.append(enemy) # --- Pymunk Physics Engine Setup --- # The default damping for every object controls the percent of velocity # the object will keep each second. A value of 1.0 is no speed loss, # 0.9 is 10% per second, 0.1 is 90% per second. # For top-down games, this is basically the friction for moving objects. # For platformers with gravity, this should probably be set to 1.0. # Default value is 1.0 if not specified. damping = DEFAULT_DAMPING # Set the gravity. (0, 0) is good for outer space and top-down. gravity = (0, -GRAVITY) # Create the physics engine self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping, gravity=gravity) def wall_hit_handler(bullet_sprite, _wall_sprite, _arbiter, _space, _data): """ Called for bullet/wall collision """ ##bullet_sprite.remove_from_sprite_lists() pass self.physics_engine.add_collision_handler( "bullet", "wall", post_handler=wall_hit_handler) def item_hit_handler(bullet_sprite, item_sprite, _arbiter, _space, _data): """ Called for bullet/wall collision """ ##bullet_sprite.remove_from_sprite_lists() item_sprite.remove_from_sprite_lists() self.physics_engine.add_collision_handler( "bullet", "item", post_handler=item_hit_handler) def bullet_enemy_hit_handler(bullet_sprite, enemy_sprite, _arbiter, _space, _data): enemy_sprite.current_health -= 1 bullet_sprite.remove_from_sprite_lists() if enemy_sprite.current_health <= 0: enemy_sprite.remove_from_sprite_lists() self.physics_engine.add_collision_handler( "bullet", "enemy", post_handler=bullet_enemy_hit_handler) def player_enemy_hit_handler(enemy_sprite, player_sprite, _arbiter, _space, _data): # add in code to handle a damage delay, etc... player_sprite.current_health -= 1 if player_sprite.current_health <= 0: player_sprite.remove_from_sprite_lists() # endgame or spawn or whatever... self.physics_engine.add_collision_handler( "enemy", "player", post_handler=player_enemy_hit_handler) # Add the player. # For the player, we set the damping to a lower value, which increases # the damping rate. This prevents the character from traveling too far # after the player lets off the movement keys. # Setting the moment to PymunkPhysicsEngine.MOMENT_INF prevents it from # rotating. # Friction normally goes between 0 (no friction) and 1.0 (high friction) # Friction is between two objects in contact. It is important to remember # in top-down games that friction moving along the 'floor' is controlled # by damping. self.physics_engine.add_sprite( self.player_sprite, friction=PLAYER_FRICTION, mass=PLAYER_MASS, moment=arcade.PymunkPhysicsEngine.MOMENT_INF, collision_type="player", max_horizontal_velocity=PLAYER_MAX_HORIZONTAL_SPEED, max_vertical_velocity=PLAYER_MAX_VERTICAL_SPEED) # Create the walls. # By setting the body type to PymunkPhysicsEngine.STATIC the walls can't # move. # Movable objects that respond to forces are PymunkPhysicsEngine.DYNAMIC # PymunkPhysicsEngine.KINEMATIC objects will move, but are assumed to be # repositioned by code and don't respond to physics forces. # Dynamic is default. self.physics_engine.add_sprite_list( self.wall_list, friction=WALL_FRICTION, collision_type="wall", body_type=arcade.PymunkPhysicsEngine.STATIC) # Create the items self.physics_engine.add_sprite_list(self.item_list, friction=DYNAMIC_ITEM_FRICTION, collision_type="item") # Add kinematic sprites self.physics_engine.add_sprite_list( self.moving_sprites_list, body_type=arcade.PymunkPhysicsEngine.KINEMATIC) self.physics_engine.add_sprite_list( self.enemy_list, collision_type="enemy", body_type=arcade.PymunkPhysicsEngine.KINEMATIC)
def __init__(self, game_resources): self.game_resources = game_resources #used for test stuff self.last_type = 0 self.projectile_physics = arcade.PymunkPhysicsEngine() self.projectile_physics.add_sprite_list( self.game_resources.wall_list, collision_type="wall", friction=1.0, body_type=arcade.PymunkPhysicsEngine.STATIC, ) self.projectile_physics.add_sprite_list( self.game_resources.object_manager.object_list, collision_type="object", body_type=arcade.PymunkPhysicsEngine.STATIC, ) self.projectile_physics.add_sprite( self.game_resources.player_sprite, damping=0.0001, friction=10.0, mass=2.0, moment=arcade.PymunkPhysicsEngine.MOMENT_INF, collision_type="player", max_horizontal_velocity=1200, max_vertical_velocity=1200, body_type=arcade.PymunkPhysicsEngine.DYNAMIC ) self.projectile_physics.add_sprite_list( self.game_resources.warps_list, collision_type="warp", body_type=arcade.PymunkPhysicsEngine.STATIC, ) self.explosion_sounds = [ SoundPool("Sounds/explosion.wav", 5, 0.2), SoundPool("Sounds/ice-hit.wav", 5, 0.1), SoundPool("Sounds/explosion-ele.wav", 5, 0.2) ] self.shoot_sounds = [ SoundPool("Sounds/fire-cast.wav", 5, 0.2), SoundPool("Sounds/ice-cast.wav", 5, 0.2), SoundPool("Sounds/ele-cast.wav", 5, 0.2) ] def wall_hit_handler(bullet_sprite, _wall_sprite, _arbiter, _space, _data): """ Called for bullet/wall collision """ bullet_sprite.remove_from_sprite_lists() self.on_projectile_death(bullet_sprite) if self.on_bullet_death is not None: self.on_bullet_death(bullet_sprite) self.projectile_physics.add_collision_handler( "bullet", "wall", post_handler=wall_hit_handler ) def object_hit_handler(bullet_sprite, _object_sprite, _arbiter, _space, _data): """ Called for bullet/wall collision """ if self.on_bullet_death is not None: self.on_bullet_death(bullet_sprite) self.on_projectile_death(bullet_sprite) bullet_sprite.remove_from_sprite_lists() _object_sprite.remove_from_sprite_lists() self.projectile_physics.add_collision_handler( "bullet", "object", post_handler=object_hit_handler ) def player_object_hit_handler(bullet_sprite, _object_sprite, _arbiter, _space, _data): """ Called for player/object collision """ _object_sprite.remove_from_sprite_lists() if _object_sprite.kind == 'flask': self.game_resources.player_sprite.player_health.health += 10 if _object_sprite.kind == 'candle_drop': self.game_resources.player_sprite.candles += 1 self.projectile_physics.add_collision_handler( "player", "object", post_handler=player_object_hit_handler ) def player_enemy_hit_handler(bullet_sprite, _object_sprite, _arbiter, _space, _data): """ Called for bullet/wall collision """ self.game_resources.player_sprite.player_health.health -= 1 if self.game_resources.player_sprite.player_health.health == 0: game_resources.dead = True self.projectile_physics.add_collision_handler( "player", "enemy", post_handler=player_enemy_hit_handler ) def warp_hit_handler(_arbiter, _space, _data): warp_sprite, player_sprite = self.projectile_physics.get_sprites_from_arbiter(_arbiter) self.projectile_physics.remove_sprite(game_resources.player_sprite) new_position = convert_from_tiled_coordinates( game_resources.my_map, warp_sprite.properties["warp_to_location"] ) self.game_resources.player_sprite.set_position(new_position[0], new_position[1]) self.game_resources.view_left = new_position[0] self.game_resources.view_bottom = new_position[1] self.projectile_physics.add_sprite(game_resources.player_sprite, damping=0.0001, friction=10.0, mass=2.0, moment=arcade.PymunkPhysicsEngine.MOMENT_INF, collision_type="player", max_horizontal_velocity=1200, max_vertical_velocity=1200, body_type=arcade.PymunkPhysicsEngine.DYNAMIC) game_resources.doors_enabled = True barrier_list = game_resources.enemy_manager.make_barrier_list() barrier_list = game_resources.enemy_manager.make_barrier_list() def spawn_enemy_in_room(): room_raw = warp_sprite.properties["warp_room_size"] x_range = room_raw.x2 - room_raw.x1 y_range = room_raw.y2 - room_raw.y1 rand_x = random.randint(room_raw.x1 + 1, room_raw.x1 + x_range - 1) rand_y = random.randint(room_raw.y1 + 1, room_raw.y1 + y_range - 1) enemy_location = convert_from_tiled_coordinates( game_resources.my_map, ( round(round(rand_x * 3) * SPRITE_IMAGE_SIZE), round(round(rand_y * 3) * SPRITE_IMAGE_SIZE) ) ) enemy = game_resources.enemy_manager.spawn_enemy(barrier_list, enemy_location) self.add_enemy(enemy) num_enemies = random.randint(2, 6) for i in range(0, num_enemies): spawn_enemy_in_room() return False self.projectile_physics.collision_types.append("warp") self.projectile_physics.collision_types.append("player") warp_physics_id = self.projectile_physics.collision_types.index("warp") player_physics_id = self.projectile_physics.collision_types.index("player") handler = self.projectile_physics.space.add_collision_handler(warp_physics_id, player_physics_id) handler.begin = warp_hit_handler def enemy_bullet_handler(_arbiter, _space, _data): bullet_sprite, enemy_sprite = self.projectile_physics.get_sprites_from_arbiter(_arbiter) if enemy_sprite: enemy_sprite.remove_from_sprite_lists() will_drop = random.randint(0, 10) if will_drop > 6: self.game_resources.object_manager.flask(enemy_sprite.center_x, enemy_sprite.center_y) elif will_drop > 3: self.game_resources.object_manager.candle_drop(enemy_sprite.center_x, enemy_sprite.center_y) self.game_resources.object_manager.object_list self.projectile_physics.add_sprite_list( self.game_resources.object_manager.object_list, collision_type="object", body_type=arcade.PymunkPhysicsEngine.STATIC, ) enemy_sprite.on_death() if bullet_sprite: bullet_sprite.remove_from_sprite_lists() if self.on_bullet_death is not None: self.on_bullet_death(bullet_sprite) self.on_projectile_death(bullet_sprite) if len(game_resources.enemy_manager.enemy_list) == 0: game_resources.doors_enabled = False return False self.projectile_physics.collision_types.append("bullet") self.projectile_physics.collision_types.append("enemy") bullet_physics_id = self.projectile_physics.collision_types.index("bullet") enemy_physics_id = self.projectile_physics.collision_types.index("enemy") handler = self.projectile_physics.space.add_collision_handler(bullet_physics_id, enemy_physics_id) handler.begin = enemy_bullet_handler self.projectile_physics.add_sprite_list( self.game_resources.doors_list, collision_type="door", friction=1.0, body_type=arcade.PymunkPhysicsEngine.STATIC, ) def door_player_handler(_arbiter, _space, _data): door_sprite, player_sprite = self.projectile_physics.get_sprites_from_arbiter(_arbiter) return game_resources.doors_enabled self.projectile_physics.collision_types.append("door") door_physics_id = self.projectile_physics.collision_types.index("door") handler = self.projectile_physics.space.add_collision_handler(door_physics_id, player_physics_id) handler.begin = door_player_handler def enemy_object_handler(_arbiter, _space, _data): door_sprite, player_sprite = self.projectile_physics.get_sprites_from_arbiter(_arbiter) return False object_physics_id = self.projectile_physics.collision_types.index("object") handler = self.projectile_physics.space.add_collision_handler(enemy_physics_id, object_physics_id) handler.begin = enemy_object_handler
def setup(self, simulation_parameters): """ Set up everything with the game """ self.simulation_parameters = simulation_parameters # Create the sprite lists self.item_list = arcade.SpriteList() self.wall_list = arcade.SpriteList() # Create data stats self.currently_infected_count = [] self.ever_infected_count = [] self.immune_count = [] self.dead_count = [] self.total_population = [] # --- Pymunk Physics Engine Setup --- damping = 1.0 gravity = (0, 0) # Create the physics engine self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping, gravity=gravity) # Create our population for i in range(simulation_parameters.population_count): item = Person(simulation_parameters) item.center_x = random.randrange( simulation_parameters.person_size * 2, SCREEN_WIDTH - simulation_parameters.person_size * 2) item.center_y = random.randrange( simulation_parameters.person_size * 2, SCREEN_HEIGHT - simulation_parameters.person_size * 2) self.item_list.append(item) self.physics_engine.add_sprite_list(self.item_list, friction=0, collision_type="item", elasticity=1.0) def hit_handler(sprite_a, sprite_b, _arbiter, _space, _data): """ Called for bullet/wall collision """ if sprite_a.currently_infected \ and not sprite_b.currently_infected \ and random.random() <= simulation_parameters.chance_of_infection: sprite_b.infect() if sprite_b.currently_infected \ and not sprite_a.currently_infected \ and random.random() <= simulation_parameters.chance_of_infection: sprite_a.infect() self.physics_engine.add_collision_handler("item", "item", post_handler=hit_handler) # Give items an initial speed for item in self.item_list: direction = random.uniform(0, 2 * math.pi) speed = random.randrange(simulation_parameters.initial_top_speed) x = math.sin(direction) * speed y = math.cos(direction) * speed impulse = (x, y) self.physics_engine.apply_impulse(item, impulse) # Infect our initial population for i in range(simulation_parameters.initial_infected_people): self.item_list[i].infect() # Immunize our initial population for j in range( simulation_parameters.initial_infected_people, simulation_parameters.initial_immune_people + simulation_parameters.initial_infected_people): self.item_list[j].immunize() # Bottom wall = arcade.SpriteSolidColor(SCREEN_WIDTH, 10, WALL_COLOR) wall.position = SCREEN_WIDTH / 2, SCREEN_HEIGHT - 5 self.wall_list.append(wall) # Top wall = arcade.SpriteSolidColor(SCREEN_WIDTH, 10, WALL_COLOR) wall.position = SCREEN_WIDTH / 2, 5 self.wall_list.append(wall) # Left wall = arcade.SpriteSolidColor(10, SCREEN_HEIGHT, WALL_COLOR) wall.position = 5, SCREEN_HEIGHT / 2 self.wall_list.append(wall) # Right wall = arcade.SpriteSolidColor(10, SCREEN_HEIGHT, WALL_COLOR) wall.position = SCREEN_WIDTH - 5, SCREEN_HEIGHT / 2 self.wall_list.append(wall) for i in range(simulation_parameters.vertical_walls): distance = SCREEN_WIDTH // simulation_parameters.vertical_walls + 1 wall_size = SCREEN_HEIGHT // 2 - self.simulation_parameters.door_size // 2 wall_y_pos = wall_size // 2 # Bottom wall = arcade.SpriteSolidColor(10, wall_size, WALL_COLOR) wall.position = distance * i, wall_y_pos self.wall_list.append(wall) # Top wall = arcade.SpriteSolidColor(10, wall_size, WALL_COLOR) wall.position = distance * i, SCREEN_HEIGHT - wall_y_pos self.wall_list.append(wall) # Add the walls to the physics engine self.physics_engine.add_sprite_list( self.wall_list, friction=0, collision_type="wall", elasticity=1.0, body_type=arcade.PymunkPhysicsEngine.STATIC)
def setup_physics_engine(self): self.physics_engine = arcade.PymunkPhysicsEngine( gravity=(0, PhysicsConfig.GRAVITY), damping=PhysicsConfig.DAMPING)
def setup(self, level): # Create the sprite lists self.player_list = arcade.SpriteList() self.gem_list = arcade.SpriteList() # Read in the tiled map map_name = f"Maps/map{level}.tmx" my_map = arcade.tilemap.read_tmx(map_name) # Calculate the right edge of the my_map in pixels self.end_of_map = my_map.map_size.width * SCREEN_GRID_WIDTH + 800 # Read in the map layers self.wall_list = arcade.tilemap.process_layer(my_map, "Platforms", SPRITE_SCALE) self.item_list = arcade.tilemap.process_layer(my_map, "Dynamic Items", SPRITE_SCALE) self.gem_list = arcade.tilemap.process_layer(my_map, "Valuables", SPRITE_SCALE) # Create player sprite self.player_sprite = PlayerSprite() # Variables used for setting player location grid_x = 2 grid_y = 2 # Set player location self.player_sprite.center_x = SPRITE_SIZE * grid_x + SPRITE_SIZE / 2 self.player_sprite.center_y = SPRITE_SIZE * grid_y + SPRITE_SIZE / 2 # Add player sprite to player sprite list self.player_list.append(self.player_sprite) # ----------------------- PHYSICS ENGINE ----------------------- # # The default damping for every object controls the percent of velocity the object will keep each second. damping = DEFAULT_DAMPING # Set the gravity gravity = (0, -GRAVITY) # Create the physics engine self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping, gravity=gravity) # Create physics for player. Damping should be lower so player doesn't travel too far when keys are released self.physics_engine.add_sprite( self.player_sprite, friction=PLAYER_FRICTION, mass=PLAYER_MASS, moment=arcade.PymunkPhysicsEngine.MOMENT_INF, collision_type="player", max_horizontal_velocity=PLAYER_MAX_HORIZONTAL_SPEED, max_vertical_velocity=PLAYER_MAX_VERTICAL_SPEED) # Create physics for walls. They should be set to STATIC self.physics_engine.add_sprite_list( self.wall_list, friction=WALL_FRICTION, collision_type="wall", body_type=arcade.PymunkPhysicsEngine.STATIC) # Create physics for items self.physics_engine.add_sprite_list(self.item_list, friction=DYNAMIC_ITEM_FRICTION, collision_type="item") # Create physics for valuables self.physics_engine.add_sprite_list(self.gem_list, friction=DYNAMIC_ITEM_FRICTION, collision_type="item")
def setup(self, map_name): """ Set up everything with the game """ # Create the sprite lists self.player_list = arcade.SpriteList() self.bullet_list = arcade.SpriteList() self.cannon_list = arcade.SpriteList() self.fruit_list = arcade.SpriteList() self.map_name = map_name # Read in the tiled map my_map = arcade.tilemap.read_tmx(self.map_name) try: self.background = arcade.load_texture( 'resources/images/{}.png'.format(map_name)) except FileNotFoundError: self.background = arcade.load_texture( 'resources/images/backgrounds/level1.tmx.png'.format(map_name)) # Read in the map layers self.wall_list = arcade.tilemap.process_layer(my_map, 'Solid Platforms', SPRITE_SCALING_TILES) self.item_list = arcade.tilemap.process_layer(my_map, 'Movable Items', SPRITE_SCALING_TILES) self.cannon_list = arcade.tilemap.process_layer( my_map, 'Cannons', SPRITE_SCALING_TILES) self.fruit_list = arcade.tilemap.process_layer(my_map, 'Fruit', SPRITE_SCALING_TILES) self.level_end_list = arcade.tilemap.process_layer( my_map, 'Player End', SPRITE_SCALING_TILES) # Create player sprite self.player_sprite = PlayerSprite(game=self) try: player_start_tilemap_objs = arcade.tilemap.get_tilemap_layer( my_map, 'Player Start').tiled_objects if len(player_start_tilemap_objs) != 1: raise AttributeError() player_start_location = player_start_tilemap_objs[0].location except (IndexError, AttributeError, TypeError): raise Exception( "Missing or duplicate Player Start location in map {}, please fix" .format(my_map.tmx_file)) # Set player location self.player_sprite.top = player_start_location.x self.player_sprite.left = player_start_location.y # Add to player sprite list # wierd workarounds below self.player_sprite.top = player_start_location.x + 1200 self.player_sprite.left = player_start_location.y + 180 #arcade.set_viewport(0, SCREEN_WIDTH, 700, SCREEN_HEIGHT) arcade.set_viewport(player_start_location.x - 300, SCREEN_WIDTH + player_start_location.x - 300, player_start_location.y + 800, SCREEN_HEIGHT + player_start_location.y + 800) self.player_list.append(self.player_sprite) # --- Pymunk Physics Engine Setup --- # The default damping for every object controls the percent of velocity # the object will keep each second. A value of 1.0 is no speed loss, # 0.9 is 10% per second, 0.1 is 90% per second. # For top-down games, this is basically the friction for moving objects. # For platformers with gravity, this should probably be set to 1.0. # Default value is 1.0 if not specified. damping = DEFAULT_DAMPING # Set the gravity. (0, 0) is good for outer space and top-down. gravity = (0, -GRAVITY) # Create the physics engine self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping, gravity=gravity) # Add the player. # For the player, we set the damping to a lower value, which increases # the damping rate. This prevents the character from traveling too far # after the player lets off the movement keys. # Setting the moment to PymunkPhysicsEngine.MOMENT_INF prevents it from # rotating. # Friction normally goes between 0 (no friction) and 1.0 (high friction) # Friction is between two objects in contact. It is important to remember # in top-down games that friction moving along the 'floor' is controlled # by damping. self.physics_engine.add_sprite( self.player_sprite, friction=PLAYER_FRICTION, mass=PLAYER_MASS, moment=arcade.PymunkPhysicsEngine.MOMENT_INF, collision_type="player", max_horizontal_velocity=PLAYER_MAX_HORIZONTAL_SPEED, max_vertical_velocity=PLAYER_MAX_VERTICAL_SPEED) # Create the walls. # By setting the body type to PymunkPhysicsEngine.STATIC the walls can't # move. # Movable objects that respond to forces are PymunkPhysicsEngine.DYNAMIC # PymunkPhysicsEngine.KINEMATIC objects will move, but are assumed to be # repositioned by code and don't respond to physics forces. # Dynamic is default. self.physics_engine.add_sprite_list( self.wall_list, friction=WALL_FRICTION, collision_type="wall", body_type=arcade.PymunkPhysicsEngine.STATIC) # Create the items self.physics_engine.add_sprite_list(self.item_list, friction=DYNAMIC_ITEM_FRICTION, collision_type="item") # Create the cannons self.physics_engine.add_sprite_list(self.cannon_list, friction=WALL_FRICTION, collision_type="item") # Create the fruit self.physics_engine.add_sprite_list( self.fruit_list, collision_type="fruit", body_type=arcade.PymunkPhysicsEngine.STATIC) # Create the level end self.physics_engine.add_sprite_list( self.level_end_list, collision_type="level_end", body_type=arcade.PymunkPhysicsEngine.STATIC)