Example #1
0
        /*
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }
        */
        public Bullet SpawnBullet(Vector3 origin, Vector3 initialVelocity)
        {
            Bullet bullet = new Bullet(game,
                                           explosionParticles,
                                           explosionSmokeParticles,
                                           projectileTrailParticles,
                                           origin,
                                           initialVelocity,
                                           explosionSFX);
            bullets.Add(bullet);
            game.Components.Add(bullet);

            ActiveBullet = bullet;

            return bullet;
        }
Example #2
0
 /// <summary>
 /// This method gets called when a bullet hits the tank.
 /// </summary>
 public void GetHit(Bullet bullet)
 {
     health -= 40;
     game.mainHUD.hitTimer = 0;
     if (health <= 0)
     {
         Dies();
     }
 }
Example #3
0
 public void RemoveBullet(Bullet bullet)
 {
     bullets.Remove(bullet);
 }
Example #4
0
        private void HandleInput(GameTime gameTime)
        {
            currentTank = tanks[currentPlayer];
            KeyboardState currentKeyboardState = Keyboard.GetState();
            GamePadState currentGamePadState = GamePad.GetState(PlayerIndex.One);
            MouseState currentMouseState = Mouse.GetState();

            Boolean suddenDeath = false;

            // Allows the game to exit
            if (currentKeyboardState.IsKeyDown(Keys.Escape) ||
                    currentGamePadState.Buttons.Back == ButtonState.Pressed)
                this.Exit();

            switch (gameState)
            {
                case GameState.Menu:

                    Keys[] pressed_Key = Keyboard.GetState().GetPressedKeys();

                    for(int i = 0; i < pressed_Key.Length; i++)
                    {
                        switch (pressed_Key[i])
                        {
                            case Keys.F2:
                                suddenDeath = true;
                                numPlayers = 2;
                                gameState = GameState.Play;
                                break;

                            case Keys.D2:
                                numPlayers = 2;
                                gameState = GameState.Play;
                            break;

                            case Keys.F3:
                            suddenDeath = true;
                            numPlayers = 3;
                            gameState = GameState.Play;
                            break;

                            case Keys.D3:
                                numPlayers = 3;
                                gameState = GameState.Play;
                            break;

                            case Keys.F4:
                            suddenDeath = true;
                            numPlayers = 4;
                            gameState = GameState.Play;
                            break;

                            case Keys.D4:
                                numPlayers = 4;
                                gameState = GameState.Play;
                            break;

                            case Keys.F5:
                            suddenDeath = true;
                            numPlayers = 5;
                            gameState = GameState.Play;
                            break;

                            case Keys.D5:
                                numPlayers = 5;
                                gameState = GameState.Play;
                            break;

                            case Keys.F6:
                            suddenDeath = true;
                            numPlayers = 6;
                            gameState = GameState.Play;
                            break;

                            case Keys.D6:
                                numPlayers = 6;
                                gameState = GameState.Play;
                            break;

                            case Keys.F7:
                                suddenDeath = true;
                                numPlayers = 7;
                                gameState = GameState.Play;
                            break;

                            case Keys.D7:
                                numPlayers = 7;
                                gameState = GameState.Play;
                            break;

                            case Keys.F8:
                                suddenDeath = true;
                                numPlayers = 8;
                                gameState = GameState.Play;
                            break;

                            case Keys.D8:
                                numPlayers = 8;
                                gameState = GameState.Play;
                            break;

                            case Keys.F9:
                                suddenDeath = true;
                                numPlayers = 9;
                                gameState = GameState.Play;
                            break;

                            case Keys.D9:
                                numPlayers = 9;
                                gameState = GameState.Play;
                            break;

                            case Keys.F10:
                                suddenDeath = true;
                                numPlayers = 10;
                                gameState = GameState.Play;
                            break;

                            case Keys.D0:
                                numPlayers = 10;
                                gameState = GameState.Play;
                            break;

                            default:
                            break;
                        }
                    }

                    for (int i = 0; i < numPlayers; i++)
                    {
                        if (gameState == GameState.Play)
                        {
                            Components.Remove(tanks[9 - i]);
                            tanks[i].moveLimit += 500 - (50 * (numPlayers - 2));
                            tanks[i].IsAlive = true;
                        }
                        if (suddenDeath)
                        {
                            tanks[i].health = 1;
                        }
                    }

                    numPlayersAlive = numPlayers;

                    break;
                case GameState.Play:
                    if (currentKeyboardState.IsKeyDown(Keys.Tab))
                        mainHUD.showScoreBoard = true;
                    if (currentKeyboardState.IsKeyUp(Keys.Tab))
                        mainHUD.showScoreBoard = false;
                    if (previousKeyboardState.IsKeyDown(Keys.P))
                    {
                        if (currentKeyboardState.IsKeyUp(Keys.P))
                            gameState = GameState.Pause;
                    }
                    if (previousKeyboardState.IsKeyDown(Keys.H))
                    {
                        if (currentKeyboardState.IsKeyUp(Keys.H))
                            gameState = GameState.Pause;
                    }

                    if (canControlTank)
                    {
                        // Fires bullets
                        if (previousKeyboardState.IsKeyDown(Keys.Space))
                        {
                            if (VelocityCount < VelocityCountMax)
                            {
                                VelocityCount += .5f;
                            }

                            if (currentKeyboardState.IsKeyUp(Keys.Space))
                            {
                                firing.Play();
                                Bullet bullet = weaponManager.Weapons[WeaponTypes.Weapon1].Fire(VelocityCount * VelocityMult);
                                VelocityCount = 0;
                                //switchCurrentTank();

                                currentTank.currentPlayerState = PlayerState.Aim;
                                canControlTank = false;
                                // Switch to bullet view after a small delay
                                //
                                enteringBulletView = true;
                                followBullet = bullet;
                                bulletViewTimer = 0.2f;
                                followBulletStartPos = bullet.position;
                                followBulletStartVelocity = bullet.velocity;
                            }
                        }

                        // CannonView
                        if (previousKeyboardState.IsKeyDown(Keys.C))
                        {
                            if (currentKeyboardState.IsKeyUp(Keys.C))
                            {
                                if (worldCamera.CurrentBehavior != QuaternionCamera.Behavior.CannonView)
                                {
                                    worldCamera.CurrentBehavior = QuaternionCamera.Behavior.CannonView;
                                }
                                else
                                {
                                    currentTank.currentPlayerState = PlayerState.Aim;
                                    worldCamera.CurrentBehavior = QuaternionCamera.Behavior.AimMode;
                                }
                            }
                        }

                        if (previousKeyboardState.IsKeyDown(Keys.Enter))
                        {
                            if (currentKeyboardState.IsKeyUp(Keys.Enter))
                            {
                                switchCurrentTank();
                            }
                        }

                        currentTank.HandleInput(currentGamePadState,
                                            currentKeyboardState,
                                            currentMouseState,
                                            terrain.heightMapInfo,
                                            gameTime);
                    }

                    break;

                case GameState.Pause:
                    if (previousKeyboardState.IsKeyDown(Keys.P))
                    {
                        if (currentKeyboardState.IsKeyUp(Keys.P))
                            gameState = GameState.Play;
                    }

                    if (previousKeyboardState.IsKeyDown(Keys.H))
                    {
                        if (currentKeyboardState.IsKeyUp(Keys.H))
                            gameState = GameState.Play;
                    }
                    break;

                case GameState.End:
                    if (previousKeyboardState.IsKeyDown(Keys.P))
                    {
                        if (currentKeyboardState.IsKeyUp(Keys.P))
                            gameState = GameState.Menu;
                    }
                    break;
            }
            previousKeyboardState = currentKeyboardState;
        }