示例#1
0
        //--------------------Functions--------------------//
        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
                {
                    //TODO: explosion on tank ?and gameover screen?
                }
            }

            #region Collisions between players and enemies
            foreach (Player p in playerList)
            {
                for (int i = p.bulletList.Count - 1; i >= 0; i--)
                {
                    #region bullets and enemies
                    for (int j = enemyList.Count - 1; j >= 0; j--)
                    {
                        if ((p.bulletList[i].position - enemyList[j].position).Length() < 1 && OBB.AreColliding(p.bulletList[i].boundingBox, enemyList[j].boundingBox))
                        {
                            p.score += (int)Vector3.Distance(p.position, enemyList[j].position) * 50;
                            particleSystemList.Add(new ParticleSystem(ParticleType.Explosion, enemyList[j].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]);
                            enemyList.Remove(enemyList[j]);
                            i--;
                            if (i < 0)
                            {
                                break;
                            }
                        }
                    }
                    if (i < 0)
                    {
                        break;
                    }
                    #endregion
                    #region bullets and floor
                    if (p.bulletList[i].position.X <0 || p.bulletList[i].position.X> Floor.heightMap.Width - 1 || p.bulletList[i].position.Z <0 || p.bulletList[i].position.Z> Floor.heightMap.Height - 1)
                    {
                        if (p.bulletList[i].position.Y <= 0)
                        {
                            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]);
                        }
                    }
                    else 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 tank and enemies
                foreach (Enemy e in enemyList)
                {
                    if (OBB.AreColliding(p.boundingBox, e.boundingBox))
                    {
                        e.position = e.lastFramePosition;
                        p.position = p.lastFramePosition;
                    }
                }
                #endregion
            }
            #endregion
            #region Collision between players
            if (OBB.AreColliding(playerOne.boundingBox, playerTwo.boundingBox))
            {
                playerOne.position = playerOne.lastFramePosition;
                playerTwo.position = playerTwo.lastFramePosition;
            }
            #endregion

            foreach (Enemy e in enemyList)
            {
                if ((e.position - playerOne.position).Length() < (e.position - playerTwo.position).Length())
                {
                    e.Update(playerOne.position + playerOne.velocity * 60, gameTime);
                }
                else
                {
                    e.Update(playerTwo.position + playerOne.velocity * 60, gameTime);
                }
            }

            //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: DELETE AT END
            //DEBUG SECTION

            /*
             * debugLine1.Update(playerOne.cannon.position, playerOne.cannon.position + playerOne.cannon.Forward);
             * debugLine2.Update(playerOne.cannon.position, playerOne.cannon.position + playerOne.cannon.Right);
             * debugLine3.Update(playerOne.cannon.position, playerOne.cannon.position + playerOne.cannon.Up);
             *
             * debugLine4.Update(playerOne.turret.position, playerOne.turret.position + playerOne.turret.Forward);
             * debugLine5.Update(playerOne.turret.position, playerOne.turret.position + playerOne.turret.Right);
             * debugLine6.Update(playerOne.turret.position, playerOne.turret.position + playerOne.turret.Up);
             *
             * //TODO: fix cannon box
             * boxes[0].Update(playerOne.boundingBox);
             * boxes[1].Update(playerTwo.boundingBox);
             * boxes[2].Update(playerOne.turret.boundingBox);
             * boxes[3].Update(playerOne.cannon.boundingBox);
             * boxes[4].Update(playerTwo.turret.boundingBox);
             * boxes[5].Update(playerTwo.cannon.boundingBox);
             *
             * //for(int i = 6; i < boxes.Count-1; i++)
             * //{
             * //    boxes[i].Update(enemyList[i - 6].boundingBox);
             * //}
             */

            //TODO: apply to all objects
            if (OBB.AreColliding(playerOne.boundingBox, playerTwo.boundingBox))
            {
                playerOne.position = playerOne.lastFramePosition;
            }
        }
示例#2
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;
            }
        }