Пример #1
0
 public Indicator(Game1 g, Tank owner)
     : base(g)
 {
     game = g;
     this.owner = owner;
 }
Пример #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            worldCamera = new Cameras.QuaternionCameraComponent(this);
            float fov = 9.0f/16.0f*this.GraphicsDevice.Viewport.AspectRatio*90.0f;
            worldCamera.Perspective(fov, 16.0f / 9.0f, 0.5f, 20000.0f);
            worldCamera.Position = new Vector3(0, -370, 160);
            worldCamera.LookAt(new Vector3(0.0f, 0.0f, 0.0f));
            worldCamera.ClickAndDragMouseRotation = true;
            worldCamera.CurrentBehavior = Cameras.QuaternionCamera.Behavior.AimMode;
            worldCamera.MovementSpeed = 100.0f;
            Components.Add(worldCamera);

            originalWorldCamera = worldCamera;
            bulletViewCamera = new PhysicsCamera(this);
            bulletViewCamera.Perspective(fov, 16.0f / 9.0f, 0.5f, 20000.0f);

            wireframeRasterizerState = new RasterizerState();
            wireframeRasterizerState.FillMode = FillMode.WireFrame;

            solidRasterizerState = new RasterizerState();
            solidRasterizerState.FillMode = FillMode.Solid;

            playerColors = new List<Vector3>();
            playerColors.Add(new Vector3(1.0f, 0.0f, 0.0f));
            playerColors.Add(new Vector3(0.0f, 1.0f, 0.0f));
            playerColors.Add(new Vector3(0.0f, 0.0f, 1.0f));
            playerColors.Add(new Vector3(1.0f, 1.0f, 0.0f));
            playerColors.Add(new Vector3(0.0f, 1.0f, 1.0f));
            playerColors.Add(new Vector3(1.0f, 0.0f, 1.0f));
            playerColors.Add(new Vector3(1.0f, 1.0f, 1.0f));
            playerColors.Add(new Vector3(1.0f, 0.5f, 0.5f));
            playerColors.Add(new Vector3(0.5f, 1.0f, 0.5f));
            playerColors.Add(new Vector3(0.5f, 0.5f, 1.0f));

            terrain = new Terrain.Terrain(this);
            Components.Add(terrain);

            physicsEngine = new PhysicsEngine(this, IntegrationMethod.RungeKutta4);
            Components.Add(physicsEngine);

            mainHUD = new HUD(this);
            Components.Add(mainHUD);

            drawUtils = new DrawUtils(this);
            Components.Add(drawUtils);

            tanks = new Tank[numPlayers];
            players = new Player[numPlayers];

            for (int i = 0; i < numPlayers; i++)
            {
                players[i] = new Player(this);
                tanks[i] = new Tank(this, Vector3.Zero, i, playerColors.ElementAt(i));
            }

            numPlayersAlive = numPlayers;

            currentTank = tanks[currentPlayer];

            weaponManager = new WeaponManager(this);

            bulletManager = new BulletManager(this);
            Components.Add(bulletManager);

            base.Initialize();
        }
Пример #3
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;
        }
Пример #4
0
        public void switchCurrentTank()
        {
            if (currentPlayer < numPlayers - 1)
            {
                currentPlayer++;
                currentTank = tanks[currentPlayer];
            }
            else
            {
                currentPlayer = 0;
                currentTank = tanks[currentPlayer];
            }

            if (!currentTank.IsAlive && numPlayersAlive > 0)
            {
                switchCurrentTank();
            }

            currentTank.moves = 0;
        }