Exemplo n.º 1
0
        private void FinishGame(Boolean isVictory)
        {
            IsActiveGameMode = false;

            _dispatcherFunction(() =>
            {
                PlayerBulletList.ForEach(x => x.Reset());
                EnemyBulletList.ForEach(x => x.Reset());
            });

            if (isVictory && OnWin != null)
            {
                OnWin(this, new EventArgs());
            }
            if (!isVictory && OnLose != null)
            {
                OnLose(this, new EventArgs());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Manages all the bullets and their collisions on screen as well as remove them from their list if they are inActive
        /// Does NOT move the bullets since that needs to be frame dependent and this can be on a different thread
        /// </summary>
        private void BulletManage()
        {
            //Manage enemy bullets
            if (BulletList.Count > 0)
            {
                int count = BulletList.Count;
                for (int i = 0; i < count; i++)
                {
                    Bullet currB = BulletList[i];
                    currB.CheckCollision(P1);

                    //Take the bullet out of the list if the collision check caused it to be inactive
                    if (!currB.IsActive)
                    {
                        BulletList.Remove(currB);
                    }

                    count = BulletList.Count;
                }
            }

            //Manage player bullets
            if (PlayerBulletList.Count > 0)
            {
                int count = PlayerBulletList.Count;
                for (int i = 0; i < count; i++)
                {
                    PlayerBullet currPB = PlayerBulletList[i];
                    currPB.CheckCollision(EnemyList);

                    //Take the bullet out of the list if the collision check caused it to be inactive
                    if (!currPB.IsActive)
                    {
                        PlayerBulletList.Remove(currPB);
                    }

                    //Updates the for loop boundary since a bullet could be added before it finishes
                    count = PlayerBulletList.Count;
                }
            }
        }
Exemplo n.º 3
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 (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            currState = Keyboard.GetState(); //Update keyboard state


            //If the game is at the menu, only check if the player pressed enter.
            if (gameState == GameState.Menu)
            {
                if (currState.IsKeyUp(Keys.Enter) && prevState.IsKeyDown(Keys.Enter))
                {
                    gameState = GameState.Controls;
                }

                prevState = currState; //Set previous state to last current state
            }
            //If the game is at the controls
            else if (gameState == GameState.Controls)
            {
                if (currState.IsKeyUp(Keys.Enter) && prevState.IsKeyDown(Keys.Enter))
                {
                    gameState = GameState.InWave;
                }
            }
            //If the game is playing
            else if (gameState == GameState.InWave)
            {
                if (P1.Health <= 0)
                {
                    gameState = GameState.GameOver;

                    //Clear out the bullets
                    BulletList.Clear();
                    PlayerBulletList.Clear();
                }

                //Check if the player paused the game
                if (currState.IsKeyUp(Keys.P) && prevState.IsKeyDown(Keys.P))
                {
                    gameState = GameState.Pause;
                }
                // activate developer tool
                if (currState.IsKeyUp(Keys.F1) && prevState.IsKeyDown(Keys.F1))
                {
                    GameBalanceTool gameBalance = new GameBalanceTool();
                    gameBalance.Show();
                }

                //Check for player movement
                P1.Movement();


                //Move and Manage enemies and bullets
                MoveBullets();
                MoveEnemies();

                BulletManage();
                EnemyManage();

                //Manage the wave
                WaveManage();


                /** Threading code to use if optimization needed
                 * bulletThread = new Thread(BulletManage);
                 * bulletThread.Start();
                 */

                //keeps tank from moving past screen
                if (P1.position.X < 0)
                {
                    P1.position.X = 0;
                }
                if (P1.position.X > GAME_WIDTH - P1.position.Width)
                {
                    P1.position.X = GAME_WIDTH - P1.position.Width;
                }
            }
            else if (gameState == GameState.Pause)
            {
                //Check if player unpaused the game
                if (currState.IsKeyUp(Keys.P) && prevState.IsKeyDown(Keys.P))
                {
                    gameState = GameState.InWave;
                }
            }
            else if (gameState == GameState.GameOver)
            {
                if (currState.IsKeyUp(Keys.Enter) && prevState.IsKeyDown(Keys.Enter))
                {
                    //Reset player
                    P1.Reset();

                    //Clear all active items off screen
                    bulletList.Clear();
                    playerBulletList.Clear();
                    enemyList.Clear();

                    //Reset the wave
                    currWave     = new Wave();
                    enemyIndex   = 0;
                    currCoolDown = spawnCoolDown;

                    gameState = GameState.InWave; //Go back to a new game
                }
            }

            prevState = currState; //Update prev keyboard state

            base.Update(gameTime);
        }
Exemplo n.º 4
0
 private void HandleBulletCreated(Bullet newBullet)
 {
     PlayerBulletList.Add(newBullet);
 }