def update(self, delta_time: float):
        distance_to_target_sqr = EnemySettings.Ranged.DETECTION_RANGE_SQR + 1 if self._target is None else \
            self.center.distance_squared_to(self._target.center)

        # If too far away, just walk
        if distance_to_target_sqr > EnemySettings.Ranged.DETECTION_RANGE_SQR and self.is_on_ground:
            self.move(EnemySettings.CHILL_WALK_VELOCITY * self._direction *
                      delta_time)
            self._state = (EnemyState.RUNNING_LEFT if self._direction < 0 else
                           EnemyState.RUNNING_RIGHT)

        # If the player is on fear range run in the opposite direction
        elif distance_to_target_sqr < EnemySettings.Ranged.FEAR_RANGE_SQR and self.is_on_ground:
            self.move(EnemySettings.Ranged.FEAR_WALK_VELOCITY *
                      self._target_direction() * delta_time)
            self._state = (EnemyState.RUNNING_LEFT if self._direction < 0 else
                           EnemyState.RUNNING_RIGHT)

        # If in range
        elif time.time() > self.__cooldown_expire:
            self.attack()
            self._state = (EnemyState.ATTACKING_LEFT if self._direction < 0
                           else EnemyState.ATTACKING_RIGHT)

        RigidPhysicsAwareGameObject.update(self, delta_time)
        AnimatedSprite.update(self, delta_time)
    def update(self, delta_time: float):

        # I'am just good guy you kown
        self.move(EnemySettings.HeavyRock.SPEED * self._direction * delta_time)
        self._state = (EnemyState.RUNNING_LEFT
                       if self._direction < 0 else EnemyState.RUNNING_RIGHT)
        RigidPhysicsAwareGameObject.update(self, delta_time)
        AnimatedSprite.update(self, delta_time)
Пример #3
0
 def __init__(self, surface: Surface, weight: float, max_health: float, attack_cooldown: float,
              damage_reduction: float = 1):
     RigidPhysicsAwareGameObject.__init__(self, surface, weight)
     LivingEntity.__init__(self, max_health, damage_reduction)
     self._attack_cooldown: float = attack_cooldown
     self.__cooldown_expire: float = 0
     self._target: GameObject = None
     self._direction = 1
    def update(self, delta_time: float):
        self.is_pressed = False
        RigidPhysicsAwareGameObject.update(self, delta_time)
        AnimatedSprite.update(self, delta_time)
        if self.is_pressed != self.was_pressed:
            self.was_pressed = False

            for handler in self.on_exit:
                handler()
Пример #5
0
    def _on_collide(self, other: GameObject, direction_of_impact: Vector2, impact_side: ImpactSide, delta_time: float):
        collision_damage = LivingEntity._velocity_to_damage(self.velocity)
        if collision_damage > 0:
            self.take_damage(collision_damage)

        RigidPhysicsAwareGameObject._on_collide(self, other, direction_of_impact, impact_side, delta_time)

        if impact_side == ImpactSide.LEFT:
            self._direction = 1
        elif impact_side == ImpactSide.RIGHT:
            self._direction = -1
Пример #6
0
    def update(self, delta_time: float):
        # Update controls
        self.__update_controls(delta_time)

        # Passive mana regeneration
        self.__update_mana_regeneration(delta_time)

        # Finally, apply physics
        RigidPhysicsAwareGameObject.update(self, delta_time)

        # Update the state
        self.__update_state()
        AnimatedSprite.update(self, delta_time)
Пример #7
0
    def __init__(self, weight: float = .5):
        sprites = ResourceManagement.get_player_sprites()
        first_sprite = next(iter(sprites.values()))[0]

        RigidPhysicsAwareGameObject.__init__(self, first_sprite, weight)
        LivingEntity.__init__(self,
                              PlayerSettings.HEALTH_MAX,
                              invincibility_duration=1)
        AnimatedSprite.__init__(self, sprites, 3, PlayerState.IDLE)
        self.ability_tornado_jump = TornadoJumpAbility(1)
        self.ability_gust = GustAbility(0)
        self.ability_slam = SlamAbility(0)
        self.mana: float = PlayerSettings.MANA_MAX
        self._last_direction = 1
Пример #8
0
    def update(self, delta_time: float):
        distance_to_target_sqr = EnemySettings.DETECTION_RANGE_SQR + 1 if self._target is None else \
            self.center.distance_squared_to(self._target.center)

        # If too far away, just walk
        if distance_to_target_sqr > EnemySettings.DETECTION_RANGE_SQR and self.is_on_ground:
            self.move(EnemySettings.CHILL_WALK_VELOCITY * self._direction * delta_time)

        # If in range
        elif time.time() > self.__cooldown_expire:
            if self.attack(delta_time, distance_to_target_sqr):
                self.__cooldown_expire = time.time() + self._attack_cooldown

        RigidPhysicsAwareGameObject.update(self, delta_time)
    def __init__(self, on_enter: [Callable[[], None]] = None, on_stay_inside: [Callable[[], None]] = None,
                 on_exit: [Callable[[], None]] = None):
        sprites = ResourceManagement.get_environment_button_sprites()
        first_sprite = next(iter(sprites.values()))[0]

        RigidPhysicsAwareGameObject.__init__(self, first_sprite, 0)
        AnimatedSprite.__init__(self, sprites, 1, ButtonState.OFF)
        self.on_enter = on_enter if on_enter is not None else []
        self.on_enter.append(self.__hide)

        self.during_activation = on_stay_inside if on_stay_inside is not None else []

        self.on_exit = on_exit if on_exit is not None else []
        self.on_exit.append(self.__show)

        self.was_pressed = False
        self.is_pressed = False
    def __init__(self, size: (int, int), direction: Vector2, force: float):
        surface = Surface(size)

        RigidPhysicsAwareGameObject.__init__(self, surface, 0)
        AnimatedSprite.__init__(
            self,
            ResourceManagement.get_environment_wind_stream_sprites(size),
            2, WindDirection.UP)
        self._direction = direction.normalize()
        self._force = force
        if abs(direction.x) > abs(direction.y):
            if direction.x > 0:
                self._state = WindDirection.RIGHT
            else:
                self._state = WindDirection.LEFT
        else:
            if direction.y > 0:
                self._state = WindDirection.DOWN
            else:
                self._state = WindDirection.UP
Пример #11
0
 def _on_collide(self, other: GameObject, direction_of_impact: Vector2,
                 impact_side: ImpactSide, delta_time: float):
     # Common collision with something normal
     if isinstance(other, HthEnemy):
         if direction_of_impact != VECTOR2_NULL:
             # Collided with an enemy
             other: Enemy
             # Apply knockback
             direction_of_impact.normalize_ip()
             self.apply_force(direction_of_impact *
                              PlayerSettings.DAMAGE_REPULSION_FACTOR)
     elif isinstance(other, Enemy):
         if isinstance(other,
                       HeavyRockEnemy) and impact_side == ImpactSide.BOTTOM:
             RigidPhysicsAwareGameObject._on_collide(
                 self, other, direction_of_impact, impact_side, delta_time)
         else:
             pass
     else:
         RigidPhysicsAwareGameObject._on_collide(self, other,
                                                 direction_of_impact,
                                                 impact_side, delta_time)
Пример #12
0
    def use(self, player: RigidPhysicsAwareGameObject):
        if self.level > 0:
            if self._next_usage <= time.time(
            ) and player.mana > self.mana_cost:
                player.mana -= self.mana_cost
                scene: Scene = SceneManagement.active_scene

                gust_projectile: GustProjectile = GustProjectile()
                gust_projectile.add_to_collision_mask(scene.environment,
                                                      scene.enemies)
                gust_projectile.move(
                    Vector2(player.transform.x + player.width,
                            player.transform.y + 10))

                scene.projectiles.add(gust_projectile)
                scene.dynamics.add(gust_projectile)

                gust_projectile.apply_force(
                    GustAbility._gust_strength_calc(player))
                player.apply_force(self._gust_backward_strength_calc(player))

                self._next_usage = time.time() + self.cooldown
                MusicManager.play_sound_effect('gust')
    def __parse_rigid_box(cls, scene: Scene,
                          element: ET.Element) -> GameObject:
        if element.attrib['color']:
            surface: Surface = Surface(cls.__parse_dimensions(element))
            surface.fill(cls.__parse_color(element))

            if element.attrib['weight']:
                weight = float(element.attrib['weight'])
            else:
                weight = 0

            go = RigidPhysicsAwareGameObject(surface, weight)
            cls.__assign_transform(element, go)
            cls.__assign_collision_masks(scene, go,
                                         cls.__parse_collision_mask(element))

            return go
        else:
            raise RuntimeError('no color on rigid box')
 def __init__(self, surface: Surface, weight: float, force_threshold: float):
     RigidPhysicsAwareGameObject.__init__(self, surface, weight)
     self.force_threshold = force_threshold
Пример #15
0
 def __init__(self, surface: Surface):
     RigidPhysicsAwareGameObject.__init__(self, surface, 0)
     self.resistance_amount = 0
 def update(self, delta_time: float):
     RigidPhysicsAwareGameObject.update(self, delta_time)
     AnimatedSprite.update(self, delta_time)
 def start(self, scene: Scene):
     RigidPhysicsAwareGameObject.start(self, scene)
     self.add_to_collision_mask(scene.player)
 def __init__(self, size: (int, int), level_name: str):
     surface: Surface = Surface(size, flags=pygame.SRCALPHA)
     surface.fill((0, 0, 0, 0))
     RigidPhysicsAwareGameObject.__init__(self, surface, 0)
     self._level_name = level_name
Пример #19
0
 def __init__(self):
     sprite: Surface = ResourceManagement.get_image('orb_slam.png')
     RigidPhysicsAwareGameObject.__init__(self, sprite, 0)
 def __assign_collision_masks(scene: Scene, go: RigidPhysicsAwareGameObject,
                              layers: [Layers]):
     for layer in layers:
         go.add_to_collision_mask(scene.layers.get(layer))
Пример #21
0
 def kill(self):
     self.collision_masks.clear()
     RigidPhysicsAwareGameObject.kill(self)
 def apply_force(self, force: Vector2):
     if force.magnitude > self.force_threshold:
         RigidPhysicsAwareGameObject.apply_force(self, force)