def update(self, bot_group=None, player_group=None): if player_group != None: self.player_group = self.mount_player_group(player_group) if bot_group != None: self.bot_group = bot_group self.nearest_player = self.get_nearest_player() self.choose_animation() self.rotate() self.choose_action() distance_to_player = self.get_distance_to_player() if distance_to_player < 500: if not self.is_grunting: self.is_grunting = True helpers.get_free_channel().play(self.grunt, -1) self.grunt.set_volume(1 - distance_to_player / 500) else: self.grunt.stop() self.is_grunting = False if self.is_dead and self.is_grunting: self.grunt.stop() self.is_grunting = False
def gets_powerup(self, powerup_type): helpers.get_free_channel().play(Sound.Player.pick_up) if powerup_type == 'life': self.life = 100 if powerup_type == 'rifle': self.weapon.weapon_list['rifle'] = True self.weapon.unloaded_ammo_list['rifle'] += 20 if powerup_type == 'shotgun': self.weapon.weapon_list['shotgun'] = True self.weapon.unloaded_ammo_list['shotgun'] += 20 if powerup_type == 'rifle_ammo': self.weapon.unloaded_ammo_list['rifle'] += 10 if powerup_type == 'shotgun_ammo': self.weapon.unloaded_ammo_list['shotgun'] += 10 if powerup_type == 'handgun_ammo': self.weapon.unloaded_ammo_list['handgun'] += 10 if powerup_type == self.weapon.type + '_ammo': self.weapon.player_out_of_ammo_played = False self.weapon.player_reload_played = False
def gets_hit_by_zombie(self): self.life -= 0.2 if not self.player_ugh_playing: self.player_ugh_playing = True helpers.get_free_channel().play(self.player_ugh, -1) if self.life < 0: self.player_ugh_playing = False self.player_ugh.stop() self.is_dead = True self.life = 0
def choose_animation(self): # body animation if self.is_reloading: if self.weapon.type == 'shotgun': self.float_index = helpers.increment(self.float_index, 1, 1) else: self.float_index = helpers.increment(self.float_index, 0.5, 1) self.index_animation_reload = helpers.increment( self.index_animation_reload, int(self.float_index), len(self.animation_reload) - 1) self.animation_body = self.prefix_animation_name + 'reload' self.animation_body_index = self.index_animation_reload self.original_image = self.animation_reload[ self.index_animation_reload] if self.index_animation_reload == len(self.animation_reload) - 1: if self.weapon.type == 'shotgun': if self.counter < self.shotgun_reload_quantity: if self.counter < self.shotgun_reload_quantity - 1: helpers.get_free_channel().play( Sound.Weapon.shotgun_reload) self.weapon.unloaded_ammo_list[self.weapon.type] -= 1 self.weapon.loaded_ammo_list[self.weapon.type] += 1 self.counter += 1 if self.counter >= self.shotgun_reload_quantity: self.is_reloading = False self.counter = 0 else: self.is_reloading = False self.index_animation_reload = 0 elif self.is_shooting and self.weapon.loaded_ammo_list[ self.weapon.type] > 0: self.index_animation_shoot = helpers.increment( self.index_animation_shoot, 1, len(self.animation_shoot) - 1) self.original_image = self.animation_shoot[ self.index_animation_shoot] self.animation_body = self.prefix_animation_name + 'shoot' self.animation_body_index = self.index_animation_shoot elif self.is_meleeattack: self.float_index = helpers.increment(self.float_index, 1, 1) self.index_animation_meleeattack = helpers.increment( self.index_animation_meleeattack, int(self.float_index), len(self.animation_meleeattack) - 1) self.animation_body = self.prefix_animation_name + 'meleeattack' self.animation_body_index = self.index_animation_meleeattack if self.index_animation_meleeattack == len( self.animation_meleeattack) - 1: self.is_meleeattack = False self.index_animation_meleeattack = 0 self.original_image = self.animation_meleeattack[ self.index_animation_meleeattack] elif self.is_idle: self.float_index = helpers.increment(self.float_index, 0.25, 1) self.index_animation_idle = helpers.increment( self.index_animation_idle, int(self.float_index), len(self.animation_idle) - 1) self.original_image = self.animation_idle[ self.index_animation_idle] self.animation_body = self.prefix_animation_name + 'idle' self.animation_body_index = self.index_animation_idle elif self.is_moving_forward or self.is_moving_left or self.is_moving_right: self.index_animation_move = helpers.increment( self.index_animation_move, 1, len(self.animation_move) - 1) self.original_image = self.animation_move[ self.index_animation_move] self.animation_body = self.prefix_animation_name + 'move' self.animation_body_index = self.index_animation_move # feet animation if self.is_moving_forward: self.original_feet = self.animation.feet_walk[ self.index_animation_feet_walk] self.animation_feet_index = self.index_animation_feet_walk self.animation_feet = 'feet_walk' self.index_animation_feet_walk = helpers.increment( self.index_animation_feet_walk, 1, 19) elif self.is_moving_left: self.original_feet = self.animation.feet_strafe_left[ self.index_animation_feet_strafe_left] self.animation_feet_index = self.index_animation_feet_strafe_left self.animation_feet = 'feet_strafe_left' self.index_animation_feet_strafe_left = helpers.increment( self.index_animation_feet_strafe_left, 1, 19) elif self.is_moving_right: self.original_feet = self.animation.feet_strafe_right[ self.index_animation_feet_strafe_right] self.animation_feet_index = self.index_animation_feet_strafe_right self.animation_feet = 'feet_strafe_right' self.index_animation_feet_strafe_right = helpers.increment( self.index_animation_feet_strafe_right, 1, 19) else: self.original_feet = self.animation.feet_idle[0] self.animation_feet_index = 0 self.animation_feet = 'feet_idle'
def make_sound(self, sound_type): if sound_type == 'shoot': if self.type == 'rifle': helpers.get_free_channel().play(Sound.Weapon.rifle_shoot) elif self.type == 'shotgun': helpers.get_free_channel().play(Sound.Weapon.shotgun_shoot) elif self.type == 'handgun': helpers.get_free_channel().play(Sound.Weapon.rifle_shoot) elif sound_type == 'reload': if self.type == 'rifle': helpers.get_free_channel().play(Sound.Weapon.rifle_reload) elif self.type == 'shotgun': helpers.get_free_channel().play(Sound.Weapon.shotgun_reload) elif self.type == 'handgun': helpers.get_free_channel().play(Sound.Weapon.rifle_reload) elif sound_type == 'meleeattack': helpers.get_free_channel().play(Sound.Weapon.meleeattack) elif sound_type == 'empty': helpers.get_free_channel().play(Sound.Weapon.empty) if self.loaded_ammo_list[self.type] == 0: if self.unloaded_ammo_list[self.type] == 0 and not self.player_out_of_ammo_played: helpers.get_free_channel().play(Sound.Weapon.player_out_of_ammo) self.player_out_of_ammo_played = True elif self.unloaded_ammo_list[self.type] != 0 and not self.player_reload_played: helpers.get_free_channel().play(Sound.Weapon.player_reload) self.player_reload_played = True else: print('sound type invalid <Weapon class>')