예제 #1
0
def player_receive_healing(healing_amount: float, game_state: GameState):
    health_gained_integer = game_state.player_state.health_resource.gain(
        healing_amount)
    if health_gained_integer > 0:
        game_state.game_world.visual_effects.append(
            create_visual_healing_text(game_state.game_world.player_entity,
                                       health_gained_integer))
 def on_select(self, game_state: GameState) -> Optional[str]:
     if not game_state.player_state.health_resource.is_at_max():
         health_gained = game_state.player_state.health_resource.gain_to_max()
         game_state.visual_effects.append(create_visual_healing_text(game_state.player_entity, health_gained))
         play_sound(SoundId.CONSUMABLE_POTION)
         return "You feel healthy again!"
     play_sound(SoundId.WARNING)
     return "Already at full health!"
예제 #3
0
    def control_npc(self, game_state: GameState, npc: NonPlayerCharacter,
                    player_entity: WorldEntity, _is_player_invisible: bool,
                    time_passed: Millis):
        self._time_since_decision += time_passed
        self._time_since_healing += time_passed
        self._time_since_shoot += time_passed
        if self._time_since_healing > self._healing_cooldown:
            self._time_since_healing = 0
            self._healing_cooldown = self._random_healing_cooldown()
            if not npc.health_resource.is_at_max():
                healing_amount = random.randint(10, 20)
                npc.health_resource.gain(healing_amount)
                circle_effect = VisualCircle(
                    (80, 200, 150), npc.world_entity.get_center_position(), 30,
                    50, Millis(350), 3)
                game_state.visual_effects.append(circle_effect)
                number_effect = create_visual_healing_text(
                    npc.world_entity, healing_amount)
                game_state.visual_effects.append(number_effect)
                play_sound(SoundId.ENEMY_SKELETON_MAGE_HEAL)

        if self._time_since_shoot > self._shoot_cooldown:
            self._time_since_shoot = 0
            self._shoot_cooldown = self._random_shoot_cooldown()
            npc.world_entity.direction = get_directions_to_position(
                npc.world_entity, player_entity.get_position())[0]
            npc.world_entity.set_not_moving()
            center_position = npc.world_entity.get_center_position()
            distance_from_enemy = 35
            projectile_pos = translate_in_direction(
                get_position_from_center_position(center_position,
                                                  PROJECTILE_SIZE),
                npc.world_entity.direction, distance_from_enemy)
            projectile_speed = 0.2
            projectile_entity = WorldEntity(projectile_pos, PROJECTILE_SIZE,
                                            Sprite.NONE,
                                            npc.world_entity.direction,
                                            projectile_speed)
            projectile = Projectile(
                projectile_entity,
                create_projectile_controller(PROJECTILE_TYPE))
            game_state.projectile_entities.append(projectile)
            play_sound(SoundId.ENEMY_ATTACK_SKELETON_MAGE)

        if self._time_since_decision > self._decision_interval:
            self._time_since_decision = 0
            if random.random() < 0.2:
                direction = random_direction()
                npc.world_entity.set_moving_in_dir(direction)
            else:
                npc.world_entity.set_not_moving()
예제 #4
0
 def apply_middle_effect(self, game_state: GameState,
                         buffed_entity: WorldEntity,
                         buffed_npc: NonPlayerCharacter,
                         time_passed: Millis):
     self._time_since_graphics += time_passed
     healing_amount = 0.04
     game_state.player_state.health_resource.gain(healing_amount *
                                                  float(time_passed))
     if self._time_since_graphics > 500:
         estimate_health_gained = int(self._time_since_graphics *
                                      healing_amount)
         game_state.visual_effects.append(
             create_visual_healing_text(game_state.player_entity,
                                        estimate_health_gained))
         game_state.visual_effects.append(
             VisualCircle((200, 200, 50),
                          game_state.player_entity.get_center_position(), 5,
                          10, Millis(100), 0))
         self._time_since_graphics = 0
예제 #5
0
    def control_npc(self, game_state: GameState, npc: NonPlayerCharacter,
                    player_entity: WorldEntity, _is_player_invisible: bool,
                    time_passed: Millis):
        if npc.stun_status.is_stunned():
            return
        self._time_since_healing += time_passed
        if self._time_since_healing > self._healing_cooldown:
            self._time_since_healing = 0
            self._healing_cooldown = self._random_healing_cooldown()
            if not npc.health_resource.is_at_max():
                healing_amount = random.randint(10, 20)
                npc.health_resource.gain(healing_amount)
                circle_effect = VisualCircle(
                    (80, 200, 150), npc.world_entity.get_center_position(), 30,
                    50, Millis(350), 3)
                game_state.game_world.visual_effects.append(circle_effect)
                number_effect = create_visual_healing_text(
                    npc.world_entity, healing_amount)
                game_state.game_world.visual_effects.append(number_effect)
                play_sound(SoundId.ENEMY_SKELETON_MAGE_HEAL)

        self._shoot_fireball_trait.update(npc, game_state, time_passed)
        self._random_walk_trait.update(npc, game_state, time_passed)