Exemple #1
0
 private void OnAnimationFinished(String animName)
 {
     if (animName == "fly")
     {
         AnimatPlay.Play(animName);
     }
 }
Exemple #2
0
    public override void _PhysicsProcess(float delta)
    {
        var newAnim = Animation;

        if (IsDead)
        {
            newAnim = "dead";
            var posY = Position.y + Constants.FallingDeadSpeed * delta;
            if (posY > GetViewport().Size.y)             //If it is greater than height, then free it.
            {
                QueueFree();
            }
        }
        else
        {
            newAnim = "fly";
            SpawnLocation.Offset = SpawnLocation.Offset + Constants.RandRand(MinSpeed, MaxSpeed) * delta;
            var direction = SpawnLocation.Rotation;
            Rotation = direction;
            Position = SpawnLocation.Position;
        }

        if (IsInAttack)
        {
            newAnim = "hit";
        }

        if (Animation != newAnim)
        {
            Animation = newAnim;
            AnimatPlay.Play(Animation);
        }
    }
Exemple #3
0
    public override void _IntegrateForces(Physics2DDirectBodyState state)
    {
        var lv      = state.LinearVelocity;
        var newAnim = Animation;

        if (IsDead)
        {
            newAnim = "dead";
        }
        else
        {
            newAnim = "walk";

            var wallSide = 0.0;

            for (int i = 0; i < state.GetContactCount(); ++i)
            {
                var contactObj         = state.GetContactColliderObject(i);
                var contactObjId       = state.GetContactColliderId(i);
                var contactLocalNormal = state.GetContactLocalNormal(i);

                if (contactObj != null)
                {
                    if (contactObj is Player)                     //Player is the object to get a collision with this mob.
                    {
                        Player player = (Player)contactObj;
                        Hit(player);
                    }
                }

                if (contactLocalNormal.x > 0.9)
                {
                    wallSide = 1;
                }
                else if (contactLocalNormal.x < -0.9)
                {
                    wallSide = -1;
                }
            }

            if (wallSide != 0 && wallSide != _direction)
            {
                _direction         = -_direction;
                MovingSprite.Scale = new Vector2(MovingSprite.Scale.x * -_direction, MovingSprite.Scale.y);
                newAnim            = "idle";
            }

            if (_direction < 0 && !_rcLeft.IsColliding() && _rcRight.IsColliding())
            {
                _direction         = -_direction;
                MovingSprite.Scale = new Vector2(MovingSprite.Scale.x * -_direction, MovingSprite.Scale.y);
                newAnim            = "idle";
            }
            else if (_direction > 0 && !_rcRight.IsColliding() && _rcLeft.IsColliding())
            {
                _direction         = -_direction;
                MovingSprite.Scale = new Vector2(MovingSprite.Scale.x * -_direction, MovingSprite.Scale.y);
                newAnim            = "idle";
            }

            var speed = (int)Constants.RandRand(MinSpeed, MaxSpeed);
            lv.x = _direction * speed;
        }

        if (IsInAttack)
        {
            newAnim = "hit";
        }

        if (Animation != newAnim)
        {
            Animation = newAnim;
            if (_direction > 0)
            {
                AnimatPlay.Play(Animation);
            }
            else
            {
                AnimatPlay.PlayBackwards(Animation);
            }
        }

        state.LinearVelocity = lv;
    }