Ejemplo n.º 1
0
        /// <summary>
        /// Initialize the static AudioManager functionality.
        /// </summary>
        /// <param name="game">The game that this component will be attached to.</param>
        public static void Initialize(Game game)
        {
            audioManager = new AudioManager(game);

            if (game != null)
            {
                game.Components.Add(audioManager);
            }
        }
Ejemplo n.º 2
0
        public override void Update(GameTime gameTime)
        {
            bool          isGroundHit;
            CatapultState postUpdateStateChange = 0;

            if (gameTime == null)
            {
                throw new ArgumentNullException("gameTime");
            }

            // The catapult is inactive, so there is nothing to update
            if (!IsActive)
            {
                base.Update(gameTime);
                return;
            }

            switch (currentState)
            {
            case CatapultState.Idle:
                // Nothing to do
                break;

            case CatapultState.Aiming:
                if (lastUpdateState != CatapultState.Aiming)
                {
                    AudioManager.PlaySound("ropeStretch", true);

                    AnimationRunning = true;
                    animations["Aim"].PlayFromFrameIndex(0);
                    stallUpdateCycles = 20;
                }

                UpdateAimAccordingToShotStrength();
                break;

            case CatapultState.Stalling:
                if (stallUpdateCycles-- <= 0)
                {
                    // We've finished stalling, fire the projectile
                    Fire(ShotVelocity);
                    postUpdateStateChange = CatapultState.Firing;
                }
                break;

            case CatapultState.Firing:
                // Progress Fire animation
                if (lastUpdateState != CatapultState.Firing)
                {
                    AudioManager.StopSound("ropeStretch");
                    AudioManager.PlaySound("catapultFire");
                    StartFiringFromLastAimPosition();
                }

                animations["Fire"].Update();

                // If in the "split" point of the animation start
                // projectile fire sequence
                if (animations["Fire"].FrameIndex == splitFrames["Fire"])
                {
                    postUpdateStateChange =
                        currentState | CatapultState.ProjectileFlying;
                    projectile.ProjectilePosition =
                        projectile.ProjectileStartPosition;
                }
                break;

            case CatapultState.Firing | CatapultState.ProjectileFlying:
                // Progress Fire animation
                animations["Fire"].Update();

                // Update projectile velocity & position in flight
                projectile.UpdateProjectileFlightData(gameTime, wind,
                                                      gravity, out isGroundHit);

                if (isGroundHit)
                {
                    // Start hit sequence
                    postUpdateStateChange = CatapultState.ProjectileHit;
                    animations["fireMiss"].PlayFromFrameIndex(0);
                }
                break;

            case CatapultState.ProjectileFlying:
                // Update projectile velocity & position in flight
                projectile.UpdateProjectileFlightData(gameTime, wind,
                                                      gravity, out isGroundHit);
                if (isGroundHit)
                {
                    // Start hit sequence
                    postUpdateStateChange = CatapultState.ProjectileHit;
                    animations["fireMiss"].PlayFromFrameIndex(0);
                }

                break;

            case CatapultState.ProjectileHit:
                // Check hit on ground impact
                if (!CheckHit())
                {
                    if (lastUpdateState != CatapultState.ProjectileHit)
                    {
                        VibrateController.Default.Start(
                            TimeSpan.FromMilliseconds(100));
                        // Play hit sound only on a missed hit,
                        // a direct hit will trigger the explosion sound
                        AudioManager.PlaySound("boulderHit");
                    }

                    // Hit animation finished playing
                    if (animations["fireMiss"].IsActive == false)
                    {
                        postUpdateStateChange = CatapultState.Reset;
                    }

                    animations["fireMiss"].Update();
                }
                else
                {
                    // Catapult hit - start longer vibration on any catapult hit
                    // Remember that the call to "CheckHit" updates the catapult's
                    // state to "Hit"
                    VibrateController.Default.Start(
                        TimeSpan.FromMilliseconds(500));
                }

                break;

            case CatapultState.Hit:
                // Progress hit animation
                if ((animations["Destroyed"].IsActive == false) &&
                    (animations["hitSmoke"].IsActive == false))
                {
                    if (enemy.Score >= winScore)
                    {
                        GameOver = true;
                        break;
                    }

                    postUpdateStateChange = CatapultState.Reset;
                }

                animations["Destroyed"].Update();
                animations["hitSmoke"].Update();

                break;

            case CatapultState.Reset:
                AnimationRunning = false;
                break;

            default:
                break;
            }

            lastUpdateState = currentState;
            if (postUpdateStateChange != 0)
            {
                currentState = postUpdateStateChange;
            }

            base.Update(gameTime);
        }