Пример #1
0
        internal override void Update(GameTime gameTime)
        {
            if (Input.WasPressed(Keys.Escape) || Input.WasPressed(Buttons.Start, PlayerIndex.One))
            {
                thisGame.ChangeCurrentStage(this, new EscStage(this, thisGame));
            }

            #region Player One Camera
            if (Input.IsPressedDown(Keys.F1) && !(currentCameraPlayerOne is CameraThirdPerson))
            {
                currentCameraPlayerOne = new CameraThirdPerson(currentCameraPlayerOne, playerOne, 2.0f, gameTime);
            }
            else if (Input.IsPressedDown(Keys.F2) && !(currentCameraPlayerOne is CameraFreeSurfaceFolow) && currentCameraPlayerOne.Position.X > 0 && currentCameraPlayerOne.Position.X < Floor.heightMap.Width && currentCameraPlayerOne.Position.Z > 0 && currentCameraPlayerOne.Position.Z < Floor.heightMap.Height)
            {
                currentCameraPlayerOne = new CameraFreeSurfaceFolow(currentCameraPlayerOne);
            }
            else if (Input.IsPressedDown(Keys.F3))
            {
                currentCameraPlayerOne = new CameraFree(currentCameraPlayerOne);
            }
            else if (Input.IsPressedDown(Keys.F4))
            {
                currentCameraPlayerOne = new CameraThirdPersonFixed(currentCameraPlayerOne, playerOne.turret, 2.0f, new Vector3(0.0f, 0.1f, 1.0f), new Vector3(0.2f, 0.3f, 0.2f));
            }
            else if (Input.IsPressedDown(Keys.F5))
            {
                currentCameraPlayerOne = new CameraThirdPersonFixed(currentCameraPlayerOne, playerOne.turret, 2.0f, new Vector3(0.0f, 0.1f, 1.0f), new Vector3(-0.2f, 0.3f, 0.2f));
            }
            #endregion
            #region Player Two Camera
            if (Input.IsPressedDown(Keys.F7) && !(currentCameraPlayerTwo is CameraThirdPerson))
            {
                currentCameraPlayerTwo = new CameraThirdPerson(currentCameraPlayerTwo, playerTwo, 2.0f, gameTime);
            }
            else if (Input.IsPressedDown(Keys.F8) && !(currentCameraPlayerTwo is CameraFreeSurfaceFolow) && currentCameraPlayerTwo.Position.X > 0 && currentCameraPlayerTwo.Position.X < Floor.heightMap.Width && currentCameraPlayerTwo.Position.Z > 0 && currentCameraPlayerTwo.Position.Z < Floor.heightMap.Height)
            {
                currentCameraPlayerTwo = new CameraFreeSurfaceFolow(currentCameraPlayerTwo);
            }
            else if (Input.IsPressedDown(Keys.F9))
            {
                currentCameraPlayerTwo = new CameraFree(currentCameraPlayerTwo);
            }
            else if (Input.IsPressedDown(Keys.F10))
            {
                currentCameraPlayerTwo = new CameraThirdPersonFixed(currentCameraPlayerTwo, playerTwo.turret, 2.0f, new Vector3(0.0f, 0.1f, 1.0f), new Vector3(0.2f, 0.3f, 0.2f));
            }
            else if (Input.IsPressedDown(Keys.F11))
            {
                currentCameraPlayerTwo = new CameraThirdPersonFixed(currentCameraPlayerTwo, playerTwo.turret, 2.0f, new Vector3(0.0f, 0.1f, 1.0f), new Vector3(-0.2f, 0.3f, 0.2f));
            }
            #endregion

            currentCameraPlayerOne.Update(gameTime);
            currentCameraPlayerTwo.Update(gameTime);

            foreach (Player p in playerList)
            {
                if (p.hp > 0)
                {
                    p.Update(gameTime);
                }
                else
                {
                    if (p == playerOne)
                    {
                        thisGame.ChangeCurrentStage(this, new EndStage(false, true, thisGame));
                    }
                    else
                    {
                        thisGame.ChangeCurrentStage(this, new EndStage(true, false, thisGame));
                    }
                }
            }

            for (int i = playerOne.bulletList.Count - 1; i >= 0; i--)
            {
                if (OBB.AreColliding(playerOne.bulletList[i].boundingBox, playerTwo.boundingBox) || OBB.AreColliding(playerOne.bulletList[i].boundingBox, playerTwo.turret.boundingBox))
                {
                    particleSystemList.Add(new ParticleSystem(ParticleType.Explosion, playerOne.bulletList[i].position, new ParticleSpawner(0.2f, true), thisGame.Content, 200, 2000, 1));
                    SoundEffectInstance aux = explosionSoundFX.CreateInstance();
                    aux.Volume = 0.3f;
                    aux.Play();
                    playerTwo.hp -= 34f;
                    playerOne.bulletList.Remove(playerOne.bulletList[i]);
                }
            }

            for (int i = playerTwo.bulletList.Count - 1; i >= 0; i--)
            {
                if (OBB.AreColliding(playerTwo.bulletList[i].boundingBox, playerOne.boundingBox) || OBB.AreColliding(playerTwo.bulletList[i].boundingBox, playerOne.turret.boundingBox))
                {
                    particleSystemList.Add(new ParticleSystem(ParticleType.Explosion, playerTwo.bulletList[i].position, new ParticleSpawner(0.2f, true), thisGame.Content, 200, 2000, 1));
                    SoundEffectInstance aux = explosionSoundFX.CreateInstance();
                    aux.Volume = 0.3f;
                    aux.Play();
                    playerOne.hp -= 34f;
                    playerTwo.bulletList.Remove(playerTwo.bulletList[i]);
                }
            }

            #region Collisions between bullets and players floor.
            foreach (Player p in playerList)
            {
                for (int i = p.bulletList.Count - 1; i >= 0; i--)
                {
                    if (i >= 0 && p.bulletList[i].position.Y <= Floor.GetHeight(p.bulletList[i].position))
                    {
                        particleSystemList.Add(new ParticleSystem(ParticleType.Explosion, p.bulletList[i].position, new ParticleSpawner(0.2f, true), thisGame.Content, 200, 2000, 1));
                        SoundEffectInstance aux = explosionSoundFX.CreateInstance();
                        aux.Volume = 0.3f;
                        aux.Play();
                        p.bulletList.Remove(p.bulletList[i]);
                    }
                }
            }
            #endregion
            #region Collision between players
            if (OBB.AreColliding(playerOne.boundingBox, playerTwo.boundingBox))
            {
                playerOne.position = playerOne.lastFramePosition;
                playerTwo.position = playerTwo.lastFramePosition;
            }
            #endregion


            //Particle Update
            playerOneRain.Update(new Vector3(playerOne.position.X, 10, playerOne.position.Z), gameTime);
            playerTwoRain.Update(new Vector3(playerTwo.position.X, 10, playerTwo.position.Z), gameTime);
            for (int i = particleSystemList.Count - 1; i >= 0; i--)
            {
                if (particleSystemList[i].particleCount == 0)
                {
                    particleSystemList.Remove(particleSystemList[i]);
                }
                else
                {
                    particleSystemList[i].Update(Vector3.Zero, gameTime);
                }
            }

            //TODO: apply to all objects
            if (OBB.AreColliding(playerOne.boundingBox, playerTwo.boundingBox))
            {
                playerOne.position = playerOne.lastFramePosition;
            }
        }