Exemplo n.º 1
0
        /// <summary>
        /// Draws a guide line which shows the course of the shot
        /// </summary>
        public void DrawGuide()
        {
            bool guideDone = false;

            guideProjectile.ProjectilePosition = Catapult.ProjectileStartPosition;
            guideProjectile.Fire(Catapult.ShotVelocity, Catapult.ShotVelocity);

            while (guideDone == false)
            {
                guideProjectile.UpdateProjectileFlightData(0.1f, Catapult.Wind,
                                                           Catapult.Gravity, out guideDone);

                spriteBatch.Draw(guideDot, guideProjectile.ProjectilePosition,
                                 Color.Blue);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draws a guide line which shows the course of the shot
        /// </summary>
        public void DrawGuide()
        {
            guideProjectile.ProjectilePosition = Catapult.ProjectileStartPosition;

            Single direction = playerSide == PlayerSide.Left ? 1 : -1;

            guideProjectile.Fire(Catapult.ShotVelocity * (float)Math.Cos(Catapult.ShotAngle),
                                 Catapult.ShotVelocity * (float)Math.Sin(Catapult.ShotAngle));

            while (guideProjectile.State == ProjectileState.InFlight)
            {
                guideProjectile.UpdateProjectileFlightData(0.1f,
                                                           Catapult.Wind,
                                                           Catapult.Gravity);

                spriteBatch.Draw(guideDot, guideProjectile.ProjectilePosition, null,
                                 playerSide == PlayerSide.Left ? Color.Blue : Color.Red, 0f,
                                 Vector2.Zero, 1f, spriteEffect, 0);
            }
        }
Exemplo n.º 3
0
        public override void Update(GameTime gameTime)
        {
            bool          isGroundHit;
            bool          startStall;
            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;
                    if (isAI == true)
                    {
                        animations["Aim"].PlayFromFrameIndex(0);
                        stallUpdateCycles = 20;
                        startStall        = false;
                    }
                }

                // Progress Aiming "animation"
                if (isAI == false)
                {
                    UpdateAimAccordingToShotStrength();
                }
                else
                {
                    animations["Aim"].Update();
                    startStall   = AimReachedShotStrength();
                    currentState = (startStall) ?
                                   CatapultState.Stalling : CatapultState.Aiming;
                }
                break;

            case CatapultState.Stalling:
                if (stallUpdateCycles-- <= 0)
                {
                    // We've finished stalling, fire the projectile
                    Fire(ShotVelocity, ShotAngle);
                    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);
        }
Exemplo n.º 4
0
        public override void Update(GameTime gameTime)
        {
            bool          isGroundHit;
            CatapultState postUpdateStateChange = 0;

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

            if (!IsActive)
            {
                base.Update(gameTime);
                return;
            }

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

            case CatapultState.Aiming:
                if (lastUpdateState != CatapultState.Aiming)
                {
                    // TODO: Play sound

                    AnimationRunning = true;
                    if (isAI == true)
                    {
                        // TODO: Play animation
                        stallUpdateCycles = 20;
                    }
                }

                // Progress Aiming "animation"
                if (isAI == false)
                {
                    // TODO: Play animation
                }
                else
                {
                    // TODO: Play animation
                    // TODO: take �startStall� into account
                    currentState = (true) ?
                                   CatapultState.Stalling : CatapultState.Aiming;
                }
                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)
                {
                    // TODO: Play Sounds and animate
                }

                // TODO: Play animation

                // TODO: Fire at the appropriate animation frame
                postUpdateStateChange = currentState |
                                        CatapultState.ProjectileFlying;
                projectile.ProjectilePosition =
                    projectile.ProjectileStartPosition;
                break;

            case CatapultState.Firing | CatapultState.ProjectileFlying:
                // Progress Fire animation
                // TODO: Play animation

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

                if (isGroundHit)
                {
                    // Start hit sequence
                    postUpdateStateChange = CatapultState.ProjectileHit;
                    // TODO: Play animation
                }
                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;
                    // TODO: Play animation
                }

                break;

            case CatapultState.ProjectileHit:
                // Check hit on ground impact
                if (!CheckHit())
                {
                    if (lastUpdateState != CatapultState.ProjectileHit)
                    {
                        // TODO: Vibrate device and play sound
                    }

                    // TODO: Relate to animation when changing state
                    postUpdateStateChange = CatapultState.Reset;

                    // TODO: Update animation
                }
                else
                {
                    // TODO: Vibrate the device
                }

                break;

            case CatapultState.Hit:
                // TODO: only check score when animation is finished
                if (enemy.Score >= winScore)
                {
                    GameOver = true;
                    break;
                }

                postUpdateStateChange = CatapultState.Reset;

                // TODO: Update animation
                break;

            case CatapultState.Reset:
                AnimationRunning = false;
                break;

            default:
                break;
            }

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

            base.Update(gameTime);
        }