示例#1
0
        internal void Update(float elapsedTime)
        {
            time += elapsedTime;
            windShader.SetValue("time", time);



            SPAWN_TIME_COUNTER = SPAWN_TIME_COUNTER + elapsedTime;//contamos el tiempo que paso desde el ultimo spawn de enemigos

            player1.Update(elapsedTime);
            if (SPAWN_TIME_COUNTER > SPAWN_TIME && enemies.Count < MAX_ENEMIES)
            {
                //si paso un tiempo = SPAWN_TIME agregamos un nuevo enemigo seleccionado al azar
                rand = random.Next(1, 4);
                if (rand == 1)
                {
                    Enemy enemigo = new Enemy_lvl_1();
                    enemies.Add(enemigo);
                    enemigo.Init();
                }
                if (rand == 2)
                {
                    Enemy enemigo = new Enemy_lvl_2();
                    enemies.Add(enemigo);
                    enemigo.Init();
                }
                if (rand == 3)
                {
                    Enemy enemigo = new Enemy_lvl_3();
                    enemies.Add(enemigo);
                    enemigo.Init();
                }
                SPAWN_TIME_COUNTER = 0;
            }

            //update de los enemigos
            enemies.ForEach(enemy => updateYEliminarMuertos(elapsedTime, enemy));
            proyectiles.ForEach(proyectil => proyectil.Update(elapsedTime));


            if (KILL_DELAY > 0)
            {
                KILL_DELAY -= elapsedTime;
            }
            if (KILL_DELAY <= 0 && killMultiTracker >= 0)
            {
                if (killMultiTracker >= 2)
                {
                    HUDManager.Instance.denied();
                }
                killMultiTracker = 0;
            }

            if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.N))
            {
                if (PostProcessManager.Instance.renderFlux == "RenderAll")
                {
                    PostProcessManager.Instance.renderFlux = "NightVision";
                }
                else
                {
                    PostProcessManager.Instance.renderFlux = "RenderAll";
                }
            }
            if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.Q))
            {
                if (player1.weapon.Equals(player1.sniper))
                {
                    player1.weapon = player1.launcher;
                }
                else
                {
                    player1.weapon = player1.sniper;
                }
                player1.weapon.muzzle.scale = player1.weapon.scaleMuzzle;
            }
            if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.F6))
            {
                if (drawBoundingBoxes)
                {
                    drawBoundingBoxes = false;
                }
                else
                {
                    drawBoundingBoxes = true;
                }
            }
            if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.F7))
            {
                if (invincibility)
                {
                    invincibility = false;
                }
                else
                {
                    invincibility = true;
                }
            }
            if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.P))
            {
                CustomFpsCamera.Instance.JumpSpeed += 100;
            }

            if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.O))
            {
                CustomFpsCamera.Instance.JumpSpeed -= 100;
            }

            //hacemos que el skybox siga al player para no tener problemas con el farplane
            Matrix translate = Matrix.Translation(CustomFpsCamera.Instance.Position);

            skyBox.transform(translate);

            foreach (Barril barril in barriles)
            {
                barril.Update(elapsedTime);
            }

            if (positiveMove0)
            {
                tLeftMoved0  += 0.02f;
                tRightMoved0 += 0.02f;
                if (tLeftMoved0 >= maxMoved)
                {
                    positiveMove0 = false;
                }
            }
            else
            {
                tLeftMoved0  -= 0.02f;
                tRightMoved0 -= 0.02f;
                if (tLeftMoved0 <= minMoved)
                {
                    positiveMove0 = true;
                }
            }

            if (positiveMove1)
            {
                tLeftMoved1  += 0.015f;
                tRightMoved1 += 0.015f;
                if (tLeftMoved1 >= maxMoved)
                {
                    positiveMove1 = false;
                }
            }
            else
            {
                tLeftMoved1  -= 0.015f;
                tRightMoved1 -= 0.015f;
                if (tLeftMoved1 <= minMoved)
                {
                    positiveMove1 = true;
                }
            }

            if (positiveMove2)
            {
                tLeftMoved2  += 0.01f;
                tRightMoved2 += 0.01f;
                if (tLeftMoved2 >= maxMoved)
                {
                    positiveMove2 = false;
                }
            }
            else
            {
                tLeftMoved2  -= 0.01f;
                tRightMoved2 -= 0.01f;
                if (tLeftMoved2 <= minMoved)
                {
                    positiveMove2 = true;
                }
            }

            bool capture = false;
            int  v, captured = 0;

            for (v = 1; v < tesoros.Count; v++)
            {
                TgcCollisionUtils.BoxBoxResult result = TgcCollisionUtils.classifyBoxBox(CustomFpsCamera.Instance.boundingBox, tesoros[v].BoundingBox);
                if (result == TgcCollisionUtils.BoxBoxResult.Adentro || result == TgcCollisionUtils.BoxBoxResult.Atravesando)
                {
                    capturas++;
                    captured = v;
                    capture  = true;
                    HUDManager.Instance.refreshCapture();
                }
            }
            if (capture)
            {
                tesoros[captured].dispose();
                tesoros.RemoveAt(captured);
                pointers[captured].dispose();
                pointers.RemoveAt(captured);
            }
            if (capturas == 11)
            {
                WINNER = true;
            }

            if (WINNER)
            {
                gameWinner();
            }
        }
        internal void Update(float elapsedTime)
        {
            time += elapsedTime;
            windShader.SetValue("time", time);

            SPAWN_TIME_COUNTER = SPAWN_TIME_COUNTER + elapsedTime;//contamos el tiempo que paso desde el ultimo spawn de enemigos

            player1.Update(elapsedTime);
            if (SPAWN_TIME_COUNTER > SPAWN_TIME && enemies.Count < MAX_ENEMIES)
            {
                //si paso un tiempo = SPAWN_TIME agregamos un nuevo enemigo seleccionado al azar
                rand = random.Next(1, 4);
                if (rand == 1)
                {
                    Enemy enemigo = new Enemy_lvl_1();
                    enemies.Add(enemigo);
                    enemigo.Init();
                }
                if (rand == 2)
                {
                    Enemy enemigo = new Enemy_lvl_2();
                    enemies.Add(enemigo);
                    enemigo.Init();
                }
                if (rand == 3)
                {
                    Enemy enemigo = new Enemy_lvl_3();
                    enemies.Add(enemigo);
                    enemigo.Init();
                }
                SPAWN_TIME_COUNTER = 0;
            }

            //update de los enemigos
            enemies.ForEach(enemy => updateYEliminarMuertos(elapsedTime, enemy));
            proyectiles.ForEach(proyectil => proyectil.Update(elapsedTime));

            if (KILL_DELAY > 0) { KILL_DELAY -= elapsedTime; }
            if (KILL_DELAY <= 0 && killMultiTracker >= 0)
            {
                if (killMultiTracker >= 2) {
                    HUDManager.Instance.denied(); }
                killMultiTracker = 0;
            }

            if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.N))
            {
                if (PostProcessManager.Instance.renderFlux == "RenderAll")
                {
                    PostProcessManager.Instance.renderFlux = "NightVision";
                   }
                else
                {
                    PostProcessManager.Instance.renderFlux = "RenderAll";
                }
            }
            if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.Q))
            {
                if (player1.weapon.Equals( player1.sniper))
                {
                    player1.weapon = player1.launcher;
                }
                else
                {
                    player1.weapon = player1.sniper;
                }
                player1.weapon.muzzle.scale = player1.weapon.scaleMuzzle;
            }
            if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.F6))
            {
                if (drawBoundingBoxes)
                {
                    drawBoundingBoxes = false;
                }
                else
                {
                    drawBoundingBoxes = true;
                }
            }
            if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.F7))
            {
                if (invincibility)
                {
                    invincibility = false;
                }
                else
                {
                    invincibility = true;
                }
            }
            if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.P))
            {
                CustomFpsCamera.Instance.JumpSpeed += 100;
            }

            if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.O))
            {
                CustomFpsCamera.Instance.JumpSpeed -= 100;
            }

            //hacemos que el skybox siga al player para no tener problemas con el farplane
            Matrix translate = Matrix.Translation(CustomFpsCamera.Instance.Position);
            skyBox.transform(translate);

            foreach (Barril barril in barriles)
            {
                barril.Update(elapsedTime);
            }

            if (positiveMove0)
            {
                tLeftMoved0 += 0.02f;
                tRightMoved0 += 0.02f;
                if (tLeftMoved0 >= maxMoved) positiveMove0 = false;
            }
            else
            {
                tLeftMoved0 -= 0.02f;
                tRightMoved0 -= 0.02f;
                if (tLeftMoved0 <= minMoved) positiveMove0 = true;
            }

            if (positiveMove1)
            {
                tLeftMoved1 += 0.015f;
                tRightMoved1 += 0.015f;
                if (tLeftMoved1 >= maxMoved) positiveMove1 = false;
            }
            else
            {
                tLeftMoved1 -= 0.015f;
                tRightMoved1 -= 0.015f;
                if (tLeftMoved1 <= minMoved) positiveMove1 = true;
            }

            if (positiveMove2)
            {
                tLeftMoved2 += 0.01f;
                tRightMoved2 += 0.01f;
                if (tLeftMoved2 >= maxMoved) positiveMove2 = false;
            }
            else
            {
                tLeftMoved2 -= 0.01f;
                tRightMoved2 -= 0.01f;
                if (tLeftMoved2 <= minMoved) positiveMove2 = true;
            }

            bool capture = false;
            int v, captured = 0;
            for (v = 1; v < tesoros.Count; v++)
            {
                TgcCollisionUtils.BoxBoxResult result = TgcCollisionUtils.classifyBoxBox(CustomFpsCamera.Instance.boundingBox, tesoros[v].BoundingBox);
                if (result == TgcCollisionUtils.BoxBoxResult.Adentro || result == TgcCollisionUtils.BoxBoxResult.Atravesando)
                {
                    capturas++;
                    captured = v;
                    capture = true;
                    HUDManager.Instance.refreshCapture();
                }
            }
            if (capture)
            {
                tesoros[captured].dispose();
                tesoros.RemoveAt(captured);
                pointers[captured].dispose();
                pointers.RemoveAt(captured);
            }
            if (capturas == 11) WINNER = true;

            if (WINNER) gameWinner();
        }