Пример #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 )
        {
            KeyboardState keyState = Keyboard.GetState();
            MouseState mouseState = Mouse.GetState();
            GamePadState padState = GamePad.GetState( PlayerIndex.One );

            Collisions = new Dictionary<Tuple<int, int>, bool>();

            if ( keyState.IsKeyDown( Keys.Escape ) )
            {
                this.Exit();
            }

            if ( ScheduledTasks.Count > 0 )
            {
                HashSet<Tuple<TimeSpan, int, Action>> ScheduledTasksCopy = new HashSet<Tuple<TimeSpan, int, Action>>( ScheduledTasks );
                foreach ( var task in ScheduledTasksCopy )
                {
                    if ( ( currentGameTime - task.Item1 ).TotalMilliseconds >= task.Item2 )
                    {
                        task.Item3();
                        ScheduledTasks.Remove( task );
                    }
                }
            }

            if ( CurrentMenu != null )
            {
                CurrentMenu.Update( currentGameTime, keyState, mouseState, padState );
                return;
            }

            if ( currentGameTime == null )
            {
                currentGameTime = gameTime.TotalGameTime;
            }
            else
            {
                currentGameTime += gameTime.ElapsedGameTime;
            }
            if ( keyState.IsKeyDown( Keys.R ) && prevKeyState.IsKeyUp( Keys.R ) )
            {
                NewRound( false, false, false );
            }
            if ( keyState.IsKeyDown( Keys.Z ) && prevKeyState.IsKeyUp( Keys.Z ) )
            {
                p1.AI = !p1.AI;
            }
            if ( keyState.IsKeyDown( Keys.M ) && prevKeyState.IsKeyUp( Keys.M ) )
            {
                loopInstance.Volume = 1.0f - loopInstance.Volume;
            }
            if ( keyState.IsKeyDown( Keys.P ) || padState.IsButtonDown( Buttons.Start ) )
            {
                CurrentMenu = new PauseMenu( this );
            }

            HashSet<GameEntity> EntitiesCopy = new HashSet<GameEntity>( Entities );
            int NumberOfLivingTanks = 0;
            foreach ( GameEntity entity in EntitiesCopy )
            {
                entity.ConUpdate( currentGameTime, EntitiesCopy, keyState );
                if ( entity is Tank && ( (Tank)entity ).IsAlive )
                {
                    NumberOfLivingTanks++;
                }
            }

            if ( ( currentGameTime - timeSinceLastPickup ).TotalMilliseconds > SpawnMillisecs )
            {
                SpawnPickup( currentGameTime );
                timeSinceLastPickup = currentGameTime;
            }

            if ( NumberOfLivingTanks <= 1 )
            {
                if ( !HasBeganWait )
                {
                    ScheduleTask( currentGameTime, WaitMillisecs, NewRound );
                    HasBeganWait = true;
                }
            }
            prevKeyState = keyState;
            prevPadState = padState;
            base.Update( gameTime );
        }
Пример #2
0
 public void ReferMenu( Menu menu )
 {
     Game.CurrentMenu = menu;
 }