コード例 #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            //Check the gamestate
            switch (currentState)
            {
            //If we're playing the game
            case GameState.Playing:
            {
                //Update the world controller and world
                World.Update(this);
                WorldController.Update(this);
                break;
            }

            case GameState.Menu:
            {
                Menu.Update();
                MenuController.Update(this);
                break;
            }

            case GameState.GameOver:
            {
                GameOverController.Update(this);
                break;
            }

            case GameState.HowToPlay:
            {
                HowToPlayController.Update(this);
                break;
            }
            }
            //Update
            base.Update(gameTime);
        }
コード例 #2
0
 public override void Update()
 {
     //Update the sprite
     setSprite();
     //Facing angle equals the angle the playyer is looking at
     FacingAngle = WorldController.SurvivorAngle(PlayerIndex);
     //Velocity is speed multiplied by movement direction
     Velocity = SpeedMultiplier * WorldController.SurvivorMovement(PlayerIndex);
     //Position of the survivor set
     Position += Velocity;
     //If the cooldown timer is above 0
     if (WeaponCooldownTimer > 0)
     {
         CanFire = false;
         //Put down the cooldown timer
         WeaponCooldownTimer--;
     }
     else
     {
         //No cooldown left, so fire the gun and then reset the timer
         CanFire = true;
     }
     if (IsSlowed)
     {
         if (SlowedCooldownTimer > 0)
         {
             //Put down the cooldown timer
             SlowedCooldownTimer--;
         }
         else
         {
             IsSlowed            = false;
             SpeedMultiplier     = 10;
             SlowedCooldownTimer = SlowedTime;
         }
     }
 }
コード例 #3
0
        public override void Update()
        {
            switch (Personality)
            {
            case DirectorPersonality.Human:
            {
                //Constant speed equals 10
                const float Speed = 10;
                //Velocity is speed multiplied by movement direction
                Velocity = Speed * WorldController.DirectorSwarmFlagMovement();
                //Position of the survivor set
                SwarmFlag += Velocity;
                //Now do the same for the special flag, reusing velocity
                Velocity = Speed * WorldController.DirectorSpecialFlagMovement();
                //Position of the survivor set
                SpecialFlag += Velocity;
                break;
            }

            case DirectorPersonality.Bully:
            {
                BullyAI.Instance.Logic();
                //Set the flags
                SwarmFlag   = BullyAI.Instance.Target.Position;
                SpecialFlag = BullyAI.Instance.Target.Position;
                break;
            }

            case DirectorPersonality.Spammer:
            {
                SpammerAI.Instance.Logic();
                //Set the flags
                SwarmFlag   = SpammerAI.Instance.Target.Position;
                SpecialFlag = SpammerAI.Instance.Target.Position;
                break;
            }

            case DirectorPersonality.Swarmer:
            {
                SwarmAI.Instance.Logic();
                //Set the flags
                SwarmFlag   = SwarmAI.Instance.Target.Position;
                SpecialFlag = SwarmAI.Instance.Target.Position;
                break;
            }
            }
            //If the user cant spawn a weapon
            if (!CanSpawnWeapon)
            {
                if (WeaponSpawnTimer > 0)
                {
                    //Put down the cooldown timer
                    WeaponSpawnTimer--;
                }
                else
                {
                    CanSpawnWeapon   = true;
                    WeaponSpawnTimer = WeaponSpawnTime;
                }
            }
        }