예제 #1
0
 private void Reset( bool toAddScore, GameTime gameTime )
 {
     bool addScore = toAddScore;
     if ( CheckVictory( gameTime ) ) addScore = true;
     IsGameDone = false;
     Projectiles = new HashSet<ProjectileObject>();
     Projectiles.Add( new AProj( blank, width, height ) );
     Fences = new HashSet<FenceObject>();
     Pickups = new HashSet<Pickup>();
     if ( appearingPowerUp != null )
     {
         appearingPowerUp.Stop();
         appearingPowerUp = null;
     }
     string WinnerString = "";
     foreach ( TankObject Tank in Tanks )
     {
         if ( Tank.IsInGame )
         {
             WinnerString = Tank.TeamString;
         }
     }
     foreach ( TankObject Tank in Tanks )
     {
         if ( Tank.TeamString == WinnerString && addScore )
         {
             Tank.Score++;
         }
         Tank.Reset();
     }
     if ( StartDelay > 0 && toAddScore )
     {
         System.Threading.Thread.Sleep( StartDelay );
     }
     Round = gameTime.TotalGameTime;
     roundDeath = null;
 }
예제 #2
0
 private void BeginSuddenDeath( GameTime gameTime )
 {
     roundDeath = SuddenDeaths[ random.Next( SuddenDeaths.Length ) ];
     roundDeath.Initialize( gameTime, Content );
     if ( roundDeath is SuperNoveyDeath )
     {
         SuperNoveyBlackHole supernova = new SuperNoveyBlackHole( gameTime );
         supernova.LoadTex( Content );
         appearingPowerUp = supernova;
         float speed = 5;
         for ( int i = 0; i < 180; i++ )
         {
             Projectiles.Add( new BasicBullet( Vector2.Zero, 0, gameTime, width, height, speed, new TankObject() ) );
             Projectiles.Add( new BasicBullet( Vector2.UnitX * width, 0, gameTime, width, height, speed, new TankObject() ) );
             Projectiles.Add( new BasicBullet( Vector2.UnitY * height, 0, gameTime, width, height, speed, new TankObject() ) );
             Projectiles.Add( new BasicBullet( new Vector2( width, height ), 0, gameTime, width, height, speed, new TankObject() ) );
         }
     }
 }
예제 #3
0
        private void PlacePickup( GameTime gameTime, bool notfirst )
        {
            if ( PickupableOptions.Length == 0 ) return;
            Type pickup = PickupableOptions[ random.Next( PickupableOptions.Length ) ];
            Object pickupToAdd = null;
            if ( pickup.IsSubclassOf( typeof( PowerUp ) ) )
            {
                PowerUp powerUp = ( PowerUp )Activator.CreateInstance( pickup, gameTime );
                powerUp = ProcessPowerUp( powerUp, gameTime );
                pickupToAdd = powerUp;
            }
            try
            {
                Pickups.Add( new Pickup( width, height, gameTime, PickupDuration, pickupToAdd, Content ) );
            }
            catch ( NullReferenceException )
            {
                Pickups.Add( new Pickup( width, height, gameTime, PickupDuration, pickup, Content ) );
            }
            catch ( ArgumentException )
            {
                if ( pickup.IsSubclassOf( typeof( PowerUp ) ) )
                {
                    PowerUp powerUp = ( PowerUp )Activator.CreateInstance( pickup, gameTime );
                    powerUp = ProcessPowerUp( powerUp, gameTime );

                    if ( powerUp is AppearingPowerUp )
                    {
                        AppearingPowerUp newAppearingPowerUp = ( AppearingPowerUp )powerUp;
                        if ( appearingPowerUp == null )
                        {
                            newAppearingPowerUp.LoadTex( Content );
                            newAppearingPowerUp.ChangeDuration( PickupDuration );
                            appearingPowerUp = newAppearingPowerUp;
                        }
                        else
                        {
                            if ( !notfirst ) PlacePickup( gameTime, true );
                            else
                            {
                                //Give up.
                            }
                        }
                    }
                }
            }
        }
예제 #4
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 )
        {
            KeyboardState key = Keyboard.GetState();
            // Allows the game to exit
            if ( GamePad.GetState( PlayerIndex.One ).Buttons.Back == ButtonState.Pressed || key.IsKeyDown( Keys.Escape ) )
                this.Exit();
            if ( key.IsKeyDown( Keys.D3 ) )
            {
                IsFixedTimeStep = true;
                TargetElapsedTime = TimeSpan.FromMilliseconds( 100 );
            }
            else
            {
                IsFixedTimeStep = false;
            }
            bool shouldUpdate = roundDeath == null || roundDeath.Update( Tanks, Projectiles, Fences, Pickups, gameTime );
            if ( !shouldUpdate )
            {
                CheckGeneralGame( gameTime, ref key, false );
                return;
            }
            if ( gameTime.TotalGameTime.TotalMilliseconds % PickupTime < 50 )
            {
                if ( !DidPlacePickup )
                {
                    PlacePickup( gameTime, false );
                    DidPlacePickup = true;
                }
            }
            else
            {
                DidPlacePickup = false;
            }

            if ( key.IsKeyDown( Keys.R ) && oldkey.IsKeyUp( Keys.R ) )
            {
                Reset( false, gameTime );
            }

            TimeSpan previousTime = gameTime.TotalGameTime - gameTime.ElapsedGameTime;
            float millisecsOfElapsation = 175;
            /*if ( key.IsKeyDown( Keys.LeftShift ) )
            {
                millisecsOfElapsation /= 4;
            }*/
            if ( gameTime.TotalGameTime.Milliseconds % millisecsOfElapsation < previousTime.Milliseconds % millisecsOfElapsation )
            {
                frame += 1;
                frame %= 8;
            }
            // TODO: Add your update logic here

            if ( appearingPowerUp == null || appearingPowerUp.UpdateProjectiles( gameTime, Projectiles ) )
            {
                HashSet<ProjectileObject> CopyOfProjectiles = new HashSet<ProjectileObject>( Projectiles );

                foreach ( ProjectileObject Proj in Projectiles )
                {
                    if ( Proj is Missile ) ( ( Missile )Proj ).changeBlastRadius( BlastRadius );
                    if ( Proj.Update( gameTime, Tanks, Fences, Pickups ) )
                    {
                        CopyOfProjectiles.Remove( Proj );
                        if ( Proj.doesCount )
                        {
                            Proj.Owner.ShotsOnBoard--;
                        }
                    }
                }

                Projectiles = CopyOfProjectiles;
            }

            HashSet<FenceObject> CopyOfFences = new HashSet<FenceObject>( Fences );
            foreach ( FenceObject Fence in Fences )
            {
                if ( Fence.Update( gameTime ) )
                {
                    CopyOfFences.Remove( Fence );
                }
            }

            Fences = CopyOfFences;

            HashSet<Pickup> CopyOfPickups = new HashSet<Pickup>( Pickups );
            foreach ( Pickup Pickup in Pickups )
            {
                if ( Pickup.Update( gameTime ) )
                {
                    CopyOfPickups.Remove( Pickup );
                }
            }

            Pickups = CopyOfPickups;

            if ( appearingPowerUp != null && appearingPowerUp.Update( gameTime, Tanks, Projectiles, Fences ) )
            {
                appearingPowerUp.Stop();
                appearingPowerUp = null;
            }

            CheckGeneralGame( gameTime, ref key, true );

            oldkey = key;
            base.Update( gameTime );
        }