예제 #1
0
 private void idleState(float delta, Vector2 Knockback)
 {
     Velocity = Velocity.MoveToward(Vector2.Zero, Friction * delta);
     seekPlayer();
     if (wanderController.GetTimeLeft() == 0)
     {
         state = pickRandomState(new Global.BehaviorState[] { Global.BehaviorState.STATE_IDLE, Global.BehaviorState.STATE_WANDER });
         Random r = new Random();
         wanderController.StartWanderTimer(r.Next(1, 4));
     }
 }
예제 #2
0
    public override void _PhysicsProcess(float delta)
    {
        knockback = knockback.MoveToward(Vector2.Zero, 200 * delta);
        knockback = MoveAndSlide(knockback);

        Vector2 dir = Vector2.Zero;

        switch (state)
        {
        case AIState.IDLE:
            velocity = velocity.MoveToward(Vector2.Zero, 200 * delta);
            SeekPlayer();
            RestartWander();
            break;

        case AIState.WANDER:
            SeekPlayer();
            RestartWander();
            dir             = GlobalPosition.DirectionTo(wanderController.TargetPosition);
            velocity        = velocity.MoveToward(dir * maxSpeed, acceleration * delta);
            batSprite.FlipH = velocity.x < 0;
            if (GlobalPosition.DistanceTo(wanderController.TargetPosition) <= maxSpeed * delta)
            {
                state = PickRandomState(stateArray);
                wanderController.StartWanderTimer(rng.RandfRange(1, 3));
            }
            break;

        case AIState.CHASE:
            var player = playerZone.Player;
            if (player != null)
            {
                dir      = GlobalPosition.DirectionTo(player.GlobalPosition);
                velocity = velocity.MoveToward(dir * maxSpeed, acceleration * delta);
            }
            else
            {
                state = AIState.IDLE;
            }
            batSprite.FlipH = velocity.x < 0;
            break;

        default:
            break;
        }
        if (softCollision.isColliding())
        {
            velocity += softCollision.GetPushVector() * delta * 300;
        }
        velocity = MoveAndSlide(velocity);
    }
예제 #3
0
 private void SetNextStateIfWanderTimerFinished()
 {
     if (_wanderController.GetTimeLeft() != 0)
     {
         return;
     }
     _state = GetRandomState(new List <EnemyState> {
         EnemyState.Idle, EnemyState.Wander
     });
     _rng.Randomize();
     _wanderController.StartWanderTimer(_rng.RandfRange(1, 3));
 }