Пример #1
0
        /// <summary>
        /// Determines the objects next state and fires the appropriate event
        /// handler to notify the view of the state change.
        /// </summary>
        public override void Update()
        {
            // Determine the next state
            state = EnemyState.GetNextState(this);
            state.Setup();

            if (state is EggHatchedState)
            {
                // Allow the hatched animation to run before notifying
                if (milliseconds > 30 && !alreadyHatched)
                {
                    if (EggHatched != null)
                    {
                        EggHatched(this, null);
                        alreadyHatched = true;
                    }
                }
            }

            // Check if the hatched Mik has mounted a Buzzard
            if (mounted)
            {
                if (EggDestroyed != null)
                {
                    EggDestroyed(this, null);
                }
                Die();
            }

            // Slow the rate of updating the graphic
            if (updateGraphic > 3)
            {
                updateGraphic = 0;
            }
            else
            {
                updateGraphic++;
            }

            // Always fire the move event
            if (EggMoveEvent != null)
            {
                EggMoveEvent(this, null);
            }

            // Slow the rate of updating the graphic
            if (updateGraphic == 0)
            {
                if (EggStateChange != null)
                {
                    EggStateChange(this, null);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Determines the objects next state and fires the appropriate event
        /// handler to notify the view of the state change.
        /// </summary>
        public override void Update()
        {
            if (!charging)
            {
                // Determine the next state
                state = EnemyState.GetNextState(this);
                state.Setup();
            }

            if (state is EnemyFlappingState)
            {
                // "Gravity" purposes
                if (speed > TERMINAL_VELOCITY)
                {
                    if (prevAngle == 225 || prevAngle == 270 || prevAngle == 315)
                    {
                        speed = 0.05;
                    }
                    else
                    {
                        speed = TERMINAL_VELOCITY;
                    }
                }
            }
            else if (state is EnemyFallingState)
            {
                // "Gravity" purposes
                if (speed > TERMINAL_VELOCITY)
                {
                    if (prevAngle == 45 || prevAngle == 90 || prevAngle == 135)
                    {
                        speed = 0.05;
                    }
                    else
                    {
                        speed = TERMINAL_VELOCITY;
                    }
                }
            }
            else if (state is PterodactylDestroyedState)
            {
                // Slow the last 2 frames of the destroyed pterodactyl
                dieAnimateTime++;
                updateGraphicRate = 10;
                if (dieAnimateTime > 18)
                {
                    if (PterodactylDestroyed != null)
                    {
                        PterodactylDestroyed(this, null);
                    }
                    Die();
                }
            }
            else if (state is PterodactylChargeState)
            {
                // Don't allow the state to change when charging
                charging = true;
                chargeTime++;
                speed = 10;
                if (chargeTime > 40)
                {
                    charging   = false;
                    chargeTime = 0;
                }
            }

            // "Gravity" purposes
            prevAngle = angle;

            // Slow the rate of updating the graphic
            if (updateGraphic > updateGraphicRate)
            {
                updateGraphic = 0;
            }
            else
            {
                updateGraphic++;
            }

            // Always fire the move event
            if (PterodactylMoveEvent != null)
            {
                PterodactylMoveEvent(this, null);
            }

            // Slow the rate of updating the graphic
            if (updateGraphic == 0)
            {
                if (PterodactylStateChange != null)
                {
                    PterodactylStateChange(this, null);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Determines the objects next state and fires the appropriate event
        /// handler to notify the view of the state change.
        /// </summary>
        public override void Update()
        {
            // Determine the next state
            state = EnemyState.GetNextState(this);
            state.Setup();

            if (state is EnemyFlappingState)
            {
                // "Gravity" purposes
                if (speed > TERMINAL_VELOCITY)
                {
                    if (prevAngle == 225 || prevAngle == 270 || prevAngle == 315)
                    {
                        speed = 0.05;
                    }
                    else
                    {
                        speed = TERMINAL_VELOCITY;
                    }
                }
            }
            else if (state is EnemyFallingState)
            {
                // "Gravity" purposes
                if (speed > TERMINAL_VELOCITY)
                {
                    if (prevAngle == 45 || prevAngle == 90 || prevAngle == 135)
                    {
                        speed = 0.05;
                    }
                    else
                    {
                        speed = TERMINAL_VELOCITY;
                    }
                }
            }
            else if (state is EnemyRunningState)
            {
                speed = SPEED;
            }
            else if (state is BuzzardFleeingState)
            {
                // When the Buzzard has been hit, it drops an egg and
                // flies to the left side. Destroy the Buzzard when
                // close enough to the edge of the screen.
                if (coords.x < 3)
                {
                    if (BuzzardDestroyed != null)
                    {
                        BuzzardDestroyed(this, null);
                    }
                    Die();
                }
            }

            // "Gravity" purposes
            prevAngle = angle;

            // Slow the rate of updating the graphic
            if (updateGraphic > 3)
            {
                updateGraphic = 0;
            }
            else
            {
                updateGraphic++;
            }

            // Always fire the move event
            if (BuzzardMoveEvent != null)     // Is anyone subscribed?
            {
                BuzzardMoveEvent(this, null); // Raise event
            }
            // Slow the rate of updating the graphic
            if (updateGraphic == 0)
            {
                if (BuzzardStateChange != null)
                {
                    BuzzardStateChange(this, null);
                }
            }

            // *** Check if lost in a joust against the player ***
            if (coords.y > 450 && coords.y < 525 && coords.x > 650 && coords.x < 800 && !droppedEgg)
            {
                if (BuzzardDropEgg != null)
                {
                    BuzzardDropEgg(this, null);
                }
                droppedEgg = true;
            }
        }
Пример #4
0
        /// <summary>
        /// Determines the objects next state and fires the appropriate event
        /// handler to notify the view of the state change.
        /// </summary>
        public override void Update()
        {
            // Check Collision
            CheckEnemyCollision();

            // Determine the next state
            EnemyState.GetNextState(this);
            stateMachine.currentState.Update();

            if (stateMachine.currentState is EggHatchedState)
            {
                // Allow the hatched animation to run before notifying
                if (milliseconds > 30 && !alreadyHatched)
                {
                    if (EggHatched != null)
                    {
                        EggHatched(this, null);
                        alreadyHatched = true;
                    }
                }
            }

            // Check if the hatched Mik has mounted a Buzzard
            if (mounted || collected)
            {
                if (collected)
                {
                    Task.Run(() => {
                        PlaySounds.Instance.Play_Collect();
                    });
                }
                if (EggDestroyed != null)
                {
                    EggDestroyed(this, null);
                }
                Die();
                Trace.WriteLine("EGG NEW COORDS" + coords);
            }

            // Slow the rate of updating the graphic
            if (updateGraphic > 3)
            {
                updateGraphic = 0;
            }
            else
            {
                updateGraphic++;
            }

            // Always fire the move event
            if (EggMoveEvent != null)
            {
                EggMoveEvent(this, null);
            }

            // Slow the rate of updating the graphic
            if (updateGraphic == 0)
            {
                if (EggStateChange != null)
                {
                    EggStateChange(this, null);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Determines the objects next state and fires the appropriate event
        /// handler to notify the view of the state change.
        /// </summary>
        public override void Update()
        {
            //Console.WriteLine("Buzzard state = " + stateMachine.currentState.ToString());
            if (!isSpawning)
            {
                if (!droppedEgg)
                {
                    CheckEnemyCollision();
                }

                // Determine the next state
                EnemyState.GetNextState(this);
                stateMachine.currentState.Update();
            }

            if (stateMachine.currentState is EnemyFlappingState)
            {
                // "Gravity" purposes
                if (speed > TERMINAL_VELOCITY)
                {
                    if (prevAngle == 225 || prevAngle == 270 || prevAngle == 315)
                    {
                        speed = 0.05;
                    }
                    else
                    {
                        speed = TERMINAL_VELOCITY;
                    }
                }
            }
            else if (stateMachine.currentState is EnemyFallingState)
            {
                // "Gravity" purposes
                if (speed > TERMINAL_VELOCITY)
                {
                    if (prevAngle == 45 || prevAngle == 90 || prevAngle == 135)
                    {
                        speed = 0.05;
                    }
                    else
                    {
                        speed = TERMINAL_VELOCITY;
                    }
                }
            }
            else if (stateMachine.currentState is EnemyRunningState)
            {
                speed = SPEED;
            }
            else if (stateMachine.currentState is BuzzardFleeingState)
            {
                // When the Buzzard has been hit, it drops an egg and
                // flies to the left side. Destroy the Buzzard when
                // close enough to the edge of the screen.
                if (!droppedEgg)
                {
                    if (BuzzardDropEgg != null)
                    {
                        BuzzardDropEgg(this, null);
                    }
                    droppedEgg = true;
                }

                if (coords.x < 3)
                {
                    if (BuzzardDestroyed != null)
                    {
                        BuzzardDestroyed(this, null);
                    }
                    Die();
                }
            }
            else if (stateMachine.currentState is EnemySpawningState)
            {
                respawning++;
                isSpawning = true;
                prevAngle  = 90;
                angle      = 90;
                speed      = 0.5;
                imagePath  = "Images/Enemy/mik_respawn.png";
                if (respawning > 100)
                {
                    if (droppedEgg)
                    {
                        stateMachine.Change("pickup");
                        BuzzardPickupState pState = stateMachine.currentState as BuzzardPickupState;
                        pState.TargetEgg = pickupEgg;
                        stateMachine.currentState.Update();
                    }
                    else
                    {
                        stateMachine.Change("spawn");
                    }
                    respawning = 0;
                    isSpawning = false;
                }
            }

            // "Gravity" purposes
            prevAngle = angle;

            // Slow the rate of updating the graphic
            if (updateGraphic > 3)
            {
                updateGraphic = 0;
            }
            else
            {
                updateGraphic++;
            }

            // Always fire the move event
            if (BuzzardMoveEvent != null)     // Is anyone subscribed?
            {
                BuzzardMoveEvent(this, null); // Raise event
            }
            // Slow the rate of updating the graphic
            if (updateGraphic == 0)
            {
                if (BuzzardStateChange != null)
                {
                    BuzzardStateChange(this, null);
                }
            }
        }