Exemplo n.º 1
0
        public void UpdateMovement(GameTime GameTime)
        {
            switch (SatelliteSpecialAnimationState)
            {
            /* When the satellite is idle, it just rotates toward the target and have the
             * natural behavior of flying, it must only be changed if the satellite engages
             * n the SS, wich its behavior changes depending on the attack phase. */
            case SatelliteSpecialAnimationState.Idle:
                //Calculate oscilating movement
                Center = mobile.Position + CurrentOffset;
                oscilationCurrentAngle += oscilationAngleFactor * GameTime.ElapsedGameTime.TotalSeconds;
                Vector2 currentOscilation = new Vector2(0, (float)(Math.Sin(oscilationCurrentAngle) * oscilationAmplitude));

                //Repositioning
                Flipbook.Position = mobile.Position + CurrentOffset + currentOscilation;

                //Update Position Based on Motion
                if (yMovementComponent.IsMoving)
                {
                    yMovementComponent.RefreshCurrentPosition((float)GameTime.ElapsedGameTime.TotalSeconds);
                    CurrentOffset = new Vector2(0, yMovementComponent.CurrentPosition);
                }

                break;

            /* When the attack starts, the satellite must load all variables that are going
             * to be necessary on the movement. First all the phys related variable changes
             * to make the satellite move above the target. */
            case SatelliteSpecialAnimationState.Initializing1:
                ySSAnimationMovement = new DefinedAcceleratedMovement();
                xSSAnimationMovement = new DefinedAcceleratedMovement();
                ySSAnimationMovement.Preset(Flipbook.Position.Y, AttackingTarget.Position.Y + SSTargetOffset.Y, 0, Parameter.SatelliteSSAnimationTotalMotionTime);
                xSSAnimationMovement.Preset(Flipbook.Position.X, AttackingTarget.Position.X - Parameter.SatelliteSSAnimationMovementRange.X, 0, Parameter.SatelliteSSAnimationTotalMotionTime);
                SatelliteSpecialAnimationState = SatelliteSpecialAnimationState.Moving1;

                break;

            /* After changing the physics variables its time to start moving to the selected
             * position. Here only the satellite position is updated, when the movement ends the
             * satellite now can start performing the attack. */
            case SatelliteSpecialAnimationState.Moving1:
                ySSAnimationMovement.RefreshCurrentPosition((float)GameTime.ElapsedGameTime.TotalSeconds);
                xSSAnimationMovement.RefreshCurrentPosition((float)GameTime.ElapsedGameTime.TotalSeconds);
                Flipbook.Position       = new Vector2(xSSAnimationMovement.CurrentPosition, ySSAnimationMovement.CurrentPosition);
                currentSSAnimationAngle = Parameter.SatelliteSSAnimationInitialAngle;

                if (!ySSAnimationMovement.IsMoving)
                {
                    SatelliteSpecialAnimationState = SatelliteSpecialAnimationState.Attacking;
                }

                break;

            /* While attacking, the satellite just moves around by multiplying the cos factor to
             * the x position. After 360 degrees are past, the satellite should start moving back
             * to its former position. */
            case SatelliteSpecialAnimationState.Attacking:
                Flipbook.Position        = new Vector2(xSSAnimationMovement.CurrentPosition, ySSAnimationMovement.CurrentPosition) - Parameter.SatelliteSSAnimationMovementRange * ((float)Math.Cos(currentSSAnimationAngle) - 1);
                currentSSAnimationAngle += (float)Math.PI * Parameter.StelliteAttackSpeedFactor * (float)GameTime.ElapsedGameTime.TotalSeconds;

                if (currentSSAnimationAngle > Parameter.SatelliteSSAnimationTotalAngle)
                {
                    SatelliteSpecialAnimationState = SatelliteSpecialAnimationState.Initializing2;
                }

                break;

            /* In order to make the satellite move all we gotta do is just reset the phys
             * variables to come back. */
            case SatelliteSpecialAnimationState.Initializing2:
                ySSAnimationMovement.Preset(Flipbook.Position.Y, mobile.Position.Y + CurrentOffset.Y, 0, Parameter.SatelliteSSAnimationTotalMotionTime);
                xSSAnimationMovement.Preset(Flipbook.Position.X, mobile.Position.X, 0, Parameter.SatelliteSSAnimationTotalMotionTime);
                SatelliteSpecialAnimationState = SatelliteSpecialAnimationState.Moving2;
                break;

            /* Then start the motion. When its finally over, it changes back to the original
             * behavior.  */
            case SatelliteSpecialAnimationState.Moving2:
                ySSAnimationMovement.RefreshCurrentPosition((float)GameTime.ElapsedGameTime.TotalSeconds);
                xSSAnimationMovement.RefreshCurrentPosition((float)GameTime.ElapsedGameTime.TotalSeconds);
                Flipbook.Position = new Vector2(xSSAnimationMovement.CurrentPosition, ySSAnimationMovement.CurrentPosition);

                if (!ySSAnimationMovement.IsMoving)
                {
                    SatelliteSpecialAnimationState = SatelliteSpecialAnimationState.Idle;
                }

                break;
            }
        }
Exemplo n.º 2
0
 public void StartSSAnimation()
 {
     SatelliteSpecialAnimationState = SatelliteSpecialAnimationState.Initializing1;
 }