class PickUp(ServerPickUp): def __init__(self, start_position, width, height, image_list, velocity=euclid.Vector2(0.0, 10.0), max_displacement=euclid.Vector2(0, 5)): ServerPickUp.__init__(self, start_position, width, height, velocity, max_displacement) self.rect = self.server_rect.get_pygame_rect() self.animation = Animation(image_list, self) self.image = self.animation.current_image()
class Platform(ServerPlatform): def __init__(self, start_position, width, height, image_list, velocity=euclid.Vector2(0.0, 0.0)): ServerPlatform.__init__(self, start_position, width, height, velocity) self.rect = self.server_rect.get_pygame_rect() self.animation = Animation(image_list, self) self.image = self.animation.current_image() def update(self): super(Platform, self).update() self.rect = self.server_rect.get_pygame_rect()
class PickUp(ServerPickUp): def __init__(self, start_position, width, height, image_list, velocity=euclid.Vector2(0.0, 10.0), max_displacement=euclid.Vector2(0, 5)): ServerPickUp.__init__(self, start_position, width, height, velocity, max_displacement) self.rect = self.server_rect.get_pygame_rect() self.animation = Animation(image_list, self) self.image = self.animation.current_image()
class Chain(ServerChain): def __init__(self, center, width, height, image_list, grapple_projectile, velocity=euclid.Vector2(0.0, 0.0), gravity=euclid.Vector2(0.0, 0.0)): ServerChain.__init__(self, center, width, height, grapple_projectile, velocity, gravity) self.can_break_rocks = False self.rect = self.server_rect.get_pygame_rect() self.animation = Animation(image_list, self) self.image = self.animation.current_image() def update(self): super(Chain, self).update() self.rect = self.server_rect.get_pygame_rect()
class Projectile(ServerProjectile): def __init__(self, center, shot_from, player, velocity=euclid.Vector2(0.0, 0.0), gravity=euclid.Vector2(0.0, 0.0)): ServerProjectile.__init__(self, center, shot_from, player, velocity, gravity) bullet_position_vector = euclid.Vector2(self.velocity.x / shot_from.bullet_velocity, self.velocity.y / shot_from.bullet_velocity) self.rect = self.server_rect.get_pygame_rect() self.animation = Animation([self.shot_from.bullet_image_list[0]], self) # image for in flight projectile self.image = pygame.transform.rotate(self.animation.current_image(), self.roto_theta_conversion_tool_extreme(bullet_position_vector)) def update(self): super(Projectile, self).update() self.rect = self.server_rect.get_pygame_rect()
class AnimatedObject(WorldObject): def __init__(self, start_position, width, height, image_list, run_time): WorldObject.__init__(self, start_position, width, height) self.rect = self.server_rect.get_pygame_rect() self.default_animation = Animation(image_list, self, run_time) self.image = self.default_animation.current_image() #************************************************************************************************* #************************************************************************************************* #used to update object rect def update(self): self.default_animation.animate_movement() self.rect.center = euclid.Vector2(self.start_position.x + self.get_width() / 2, self.start_position.y + self.get_height() / 2)
class Platform(ServerPlatform): def __init__(self, start_position, width, height, image_list, velocity=euclid.Vector2(0.0, 0.0)): ServerPlatform.__init__(self, start_position, width, height, velocity) self.rect = self.server_rect.get_pygame_rect() self.animation = Animation(image_list, self) self.image = self.animation.current_image() def update(self): super(Platform, self).update() self.rect = self.server_rect.get_pygame_rect()
class Chain(ServerChain): def __init__(self, center, width, height, image_list, grapple_projectile, velocity=euclid.Vector2(0.0, 0.0), gravity=euclid.Vector2(0.0, 0.0)): ServerChain.__init__(self, center, width, height, grapple_projectile, velocity, gravity) self.can_break_rocks = False self.rect = self.server_rect.get_pygame_rect() self.animation = Animation(image_list, self) self.image = self.animation.current_image() def update(self): super(Chain, self).update() self.rect = self.server_rect.get_pygame_rect()
class Projectile(ServerProjectile): def __init__(self, center, shot_from, player, velocity=euclid.Vector2(0.0, 0.0), gravity=euclid.Vector2(0.0, 0.0)): ServerProjectile.__init__(self, center, shot_from, player, velocity, gravity) bullet_position_vector = euclid.Vector2( self.velocity.x / shot_from.bullet_velocity, self.velocity.y / shot_from.bullet_velocity) self.rect = self.server_rect.get_pygame_rect() self.animation = Animation([self.shot_from.bullet_image_list[0]], self) # image for in flight projectile self.image = pygame.transform.rotate( self.animation.current_image(), self.roto_theta_conversion_tool_extreme(bullet_position_vector)) def update(self): super(Projectile, self).update() self.rect = self.server_rect.get_pygame_rect()
class SpritePlayer(LunarPioneer): def __init__(self, start_position, height, length, image_list, weapons, world_object_list_dictionary, spawn_animation, velocity=euclid.Vector2(0.0, 0.0), gravity=euclid.Vector2(0.0, 0.0), health=100.0): LunarPioneer.__init__(self, start_position, height, length, weapons, world_object_list_dictionary, velocity, gravity, health) #images self.spawn_animation = Spawnimation(self.start_position, 90, 651, spawn_animation, self) self.dashing_animation = Animation(image_list[9:14], self, .1, self.end_dash_animation) self.dust_image_list = image_list[15:21] self.running_animation = Animation(image_list[0:9], self, .08) self.image = self.running_animation.current_image() self.rect = self.server_rect.get_pygame_rect() #override self.grapple_projectile = Grapple(start_position, self.weapons[0], self) self.grapple_projectile.is_alive = False # kill default grapple self.add_to_world(self.spawn_animation, "foreground") #************************************************************************************************* #************************************************************************************************* #gets new image of our running man def change_animation(self): if self.is_running(): self.running_animation.animate_movement(self.movement_direction()) self.image = pygame.transform.flip(self.running_animation.current_image(), not self.is_looking_right, 0) elif self.is_dashing: self.dashing_animation.animate_movement() self.image = pygame.transform.flip(self.dashing_animation.current_image(), not self.is_moving_right, 0) #elif self.grapple_projectile.is_alive: #self.image = pygame.transform.flip(self.running_animation.image_list[0], not self.is_looking_right, 0) #elif self.is_falling(): #self.image = pygame.transform.flip(self.running_animation.image_list[0], not self.is_looking_right, 0) else: # player is standing still self.image = pygame.transform.flip(self.running_animation.image_list[0], not self.is_looking_right, 0) #************************************************************************************************* #************************************************************************************************* #hit top of object def collision_above(self, thing_hit): if self.is_grappled(): self.velocity = euclid.Vector2(0.0, 0.0) else: if not self.can_jump and math.fabs(self.velocity.y) >= math.fabs(self.max_speed.y) - 100.0: dust_cloud = DustCloud(euclid.Vector2(self.start_position.x + self.hitbox.width / 2.0 - 150 / 2.0, self.start_position.y + self.hitbox.height - 41), 150, 41, self.dust_image_list) self.add_to_world(dust_cloud, "foreground") self.velocity = euclid.Vector2(self.velocity.x, 0.0) self.can_jump = True #calculates offset to y position self.start_position.y = thing_hit.start_position.y - self.hitbox.height - self.top_padding()
class Gun(ServerGun): def __init__(self, bullet_velocity, delay, damage, ammo, max_ammo, reload_time, accuracy, image_list=None, gun_x_position=-10.0, gun_y_position=-10.0, width=80.0, height=25.0, look_left_offset=20.0): if image_list is None: image_list = [pygame.image.load("resources/images/gunNotShooting.png"), pygame.image.load("resources/images/gunShooting.png")] ServerGun.__init__(self, bullet_velocity, delay, damage, ammo, max_ammo, reload_time, accuracy, gun_x_position, gun_y_position, width, height, look_left_offset) self.rect = self.server_rect.get_pygame_rect() self.animation = Animation(image_list, self) self.image = self.animation.current_image() #************************************************************************************************* #************************************************************************************************* #updates the image #when gun is charging it will run the animation def update_weapon_image(self, player): if player.is_shooting: self.animation.use_image_at = 1 else: self.animation.use_image_at = 0 mouse_position = player.mouse_position gun_position_vector = get_vector_to_position(mouse_position, self.window_position_center) theta = self.roto_theta_conversion_tool_extreme(gun_position_vector) + 90 if math.fabs(theta) > 90: image = pygame.transform.flip(self.animation.current_image(), 1, 0) self.image = pygame.transform.rotate(image, theta + 180) player.gun_is_pointed_right = False else: self.image = pygame.transform.rotate(self.animation.current_image(), theta) player.gun_is_pointed_right = True #set where the player is looking if they aren't dashing if not player.is_dashing: player.is_looking_right = player.gun_is_pointed_right if player.gun_is_pointed_right: self.set_center(euclid.Vector2(player.start_position.x + player.get_width() / 2.0 + self.gun_x_position, player.start_position.y + player.get_height() / 2.0 + self.gun_y_position)) else: self.set_center(euclid.Vector2(player.start_position.x + player.get_width() / 2.0 + self.gun_x_position + self.look_left_offset, player.start_position.y + player.get_height() / 2.0 + self.gun_y_position)) self.server_rect.reform_rect(self.image.get_width(), self.image.get_height(), self.server_rect.center) self.reset_rects() self.rect = self.server_rect.get_pygame_rect() #************************************************************************************************* #************************************************************************************************* #returns a projectile that the Player shot def use_weapon(self, player): # self is da gun current_time = now() bullet_position_vector = get_vector_to_position(player.mouse_position, self.window_position_center) time_since_fire = current_time - player.last_fire_time shot = [] if time_since_fire >= self.delay and self.ammo > 0 and not player.is_reloading: #player shot self.calculate_end_of_barrel(player) player.is_shooting = True player.last_fire_time = current_time self.ammo -= 1 for a in range(1, self.shoots_this_many_at_a_time + 1): shot.append(Projectile( self.end_of_barrel, self, player, euclid.Vector2((bullet_position_vector.x + random.uniform(-self.accuracy, self.accuracy)) * self.bullet_velocity, (bullet_position_vector.y + random.uniform(-self.accuracy, self.accuracy)) * self.bullet_velocity))) return shot return None
class Gun(ServerGun): def __init__(self, bullet_velocity, delay, damage, ammo, max_ammo, reload_time, accuracy, image_list=None, gun_x_position=-10.0, gun_y_position=-10.0, width=80.0, height=25.0, look_left_offset=20.0): if image_list is None: image_list = [ pygame.image.load("resources/images/gunNotShooting.png"), pygame.image.load("resources/images/gunShooting.png") ] ServerGun.__init__(self, bullet_velocity, delay, damage, ammo, max_ammo, reload_time, accuracy, gun_x_position, gun_y_position, width, height, look_left_offset) self.rect = self.server_rect.get_pygame_rect() self.animation = Animation(image_list, self) self.image = self.animation.current_image() #************************************************************************************************* #************************************************************************************************* #updates the image #when gun is charging it will run the animation def update_weapon_image(self, player): if player.is_shooting: self.animation.use_image_at = 1 else: self.animation.use_image_at = 0 mouse_position = player.mouse_position gun_position_vector = get_vector_to_position( mouse_position, self.window_position_center) theta = self.roto_theta_conversion_tool_extreme( gun_position_vector) + 90 if math.fabs(theta) > 90: image = pygame.transform.flip(self.animation.current_image(), 1, 0) self.image = pygame.transform.rotate(image, theta + 180) player.gun_is_pointed_right = False else: self.image = pygame.transform.rotate( self.animation.current_image(), theta) player.gun_is_pointed_right = True #set where the player is looking if they aren't dashing if not player.is_dashing: player.is_looking_right = player.gun_is_pointed_right if player.gun_is_pointed_right: self.set_center( euclid.Vector2( player.start_position.x + player.get_width() / 2.0 + self.gun_x_position, player.start_position.y + player.get_height() / 2.0 + self.gun_y_position)) else: self.set_center( euclid.Vector2( player.start_position.x + player.get_width() / 2.0 + self.gun_x_position + self.look_left_offset, player.start_position.y + player.get_height() / 2.0 + self.gun_y_position)) self.server_rect.reform_rect(self.image.get_width(), self.image.get_height(), self.server_rect.center) self.reset_rects() self.rect = self.server_rect.get_pygame_rect() #************************************************************************************************* #************************************************************************************************* #returns a projectile that the Player shot def use_weapon(self, player): # self is da gun current_time = now() bullet_position_vector = get_vector_to_position( player.mouse_position, self.window_position_center) time_since_fire = current_time - player.last_fire_time shot = [] if time_since_fire >= self.delay and self.ammo > 0 and not player.is_reloading: #player shot self.calculate_end_of_barrel(player) player.is_shooting = True player.last_fire_time = current_time self.ammo -= 1 for a in range(1, self.shoots_this_many_at_a_time + 1): shot.append( Projectile( self.end_of_barrel, self, player, euclid.Vector2( (bullet_position_vector.x + random.uniform(-self.accuracy, self.accuracy)) * self.bullet_velocity, (bullet_position_vector.y + random.uniform(-self.accuracy, self.accuracy)) * self.bullet_velocity))) return shot return None
class SpritePlayer(LunarPioneer): def __init__(self, start_position, height, length, image_list, weapons, world_object_list_dictionary, spawn_animation, velocity=euclid.Vector2(0.0, 0.0), gravity=euclid.Vector2(0.0, 0.0), health=100.0): LunarPioneer.__init__(self, start_position, height, length, weapons, world_object_list_dictionary, velocity, gravity, health) #images self.spawn_animation = Spawnimation(self.start_position, 90, 651, spawn_animation, self) self.dashing_animation = Animation(image_list[9:14], self, .1, self.end_dash_animation) self.dust_image_list = image_list[15:21] self.running_animation = Animation(image_list[0:9], self, .08) self.image = self.running_animation.current_image() self.rect = self.server_rect.get_pygame_rect() #override self.grapple_projectile = Grapple(start_position, self.weapons[0], self) self.grapple_projectile.is_alive = False # kill default grapple self.add_to_world(self.spawn_animation, "foreground") #************************************************************************************************* #************************************************************************************************* #gets new image of our running man def change_animation(self): if self.is_running(): self.running_animation.animate_movement(self.movement_direction()) self.image = pygame.transform.flip( self.running_animation.current_image(), not self.is_looking_right, 0) elif self.is_dashing: self.dashing_animation.animate_movement() self.image = pygame.transform.flip( self.dashing_animation.current_image(), not self.is_moving_right, 0) #elif self.grapple_projectile.is_alive: #self.image = pygame.transform.flip(self.running_animation.image_list[0], not self.is_looking_right, 0) #elif self.is_falling(): #self.image = pygame.transform.flip(self.running_animation.image_list[0], not self.is_looking_right, 0) else: # player is standing still self.image = pygame.transform.flip( self.running_animation.image_list[0], not self.is_looking_right, 0) #************************************************************************************************* #************************************************************************************************* #hit top of object def collision_above(self, thing_hit): if self.is_grappled(): self.velocity = euclid.Vector2(0.0, 0.0) else: if not self.can_jump and math.fabs( self.velocity.y) >= math.fabs(self.max_speed.y) - 100.0: dust_cloud = DustCloud( euclid.Vector2( self.start_position.x + self.hitbox.width / 2.0 - 150 / 2.0, self.start_position.y + self.hitbox.height - 41), 150, 41, self.dust_image_list) self.add_to_world(dust_cloud, "foreground") self.velocity = euclid.Vector2(self.velocity.x, 0.0) self.can_jump = True #calculates offset to y position self.start_position.y = thing_hit.start_position.y - self.hitbox.height - self.top_padding( )