Exemplo n.º 1
0
 public void renderExplosion(float tiempo)
 {
     foreach (FuegoShaders xfuego in explosiones)
     {
         xfuego.mesh.rotateY(39);
         xfuego.mesh.rotateZ(168);
         xfuego.mesh.rotateX(74);
         xfuego.render(tiempo);
         sonido2.render(tiempo);
     }
 }
Exemplo n.º 2
0
        public void explotarParticulas(float tiempo)
        {
            //d3dDevice = GuiController.Instance.D3dDevice;


            explo.updateParticulas(tiempo);

            explo = new Explosion(new Vector3(this.ExplotoX, 0, this.ExplotoZ), Color.OrangeRed, new Vector3(1f, 1f, 1f), 1, 100, new Vector3(0, 0, 0), r.Next(0, 1000), 5, d3dDevice, 100);

            sonido.render(tiempo);

            explo.render(d3dDevice);
        }
Exemplo n.º 3
0
        //=======================================
        // Actualizo estados
        //=======================================
        public override void update(float Tiempo)
        {
            Microsoft.DirectX.Direct3D.Device d3dDevice = GuiController.Instance.D3dDevice;

            //obtener velocidades de Modifiers
            bool  showBB            = (bool)GuiController.Instance.Modifiers.getValue("showBoundingBox");
            float velocidadCaminar  = 160 * Tiempo;
            float velocidadRotacion = 70 * Tiempo;
            float fuerzaSalto       = (float)GuiController.Instance.Modifiers.getValue("FuerzaSalto");


            //Calcular proxima posicion de personaje segun Input
            TgcD3dInput d3dInput           = GuiController.Instance.D3dInput;
            float       moveForward        = 0f;
            float       rotate             = 0;
            float       jumpingElapsedTime = 0;
            bool        moving             = false;
            bool        rotating           = false;
            bool        pegando            = false;
            bool        saltando           = false;
            bool        pateando           = false;

            #region inputs

            //Adelante
            if (d3dInput.keyDown(Key.W))
            {
                moveForward = -velocidadCaminar;
                moving      = true;
                sonido.render(Tiempo);
            }

            //Atras
            if (d3dInput.keyDown(Key.S))
            {
                moveForward = velocidadCaminar;
                moving      = true;
                sonido.render(Tiempo);
            }

            //Derecha
            if (d3dInput.keyDown(Key.D))
            {
                rotate   = velocidadRotacion;
                rotating = true;
            }

            //Izquierda
            if (d3dInput.keyDown(Key.A))
            {
                rotate   = -velocidadRotacion;
                rotating = true;
            }

            //Golpe
            if (d3dInput.keyDown(Key.Q))
            {
                pegando = true;
            }

            //Patada
            if (d3dInput.keyDown(Key.E))
            {
                pateando = true;
            }

            //Disparando
            if (d3dInput.keyDown(Key.P))
            {
                cDisparando = true;

                Vector3 frentePersonaje = new Vector3(0 - 13 * (FastMath.Sin(this.mesh.Rotation.Y)),
                                                      0,
                                                      0 - 13 * (FastMath.Cos(this.mesh.Rotation.Y)));

                disparo.explotando = false;
                disparo.explota    = 0;
                disparo.PosicionDisparo(this.mesh.Position, frentePersonaje);

                disparo.setPosicionInicial(GuiController.Instance.ThirdPersonCamera.getPosition());
                sonido2.render(Tiempo);
                disparo.inicioDisparo = mesh.Position;
                disparo.explota       = 0;
            }
            #endregion

            #region salto
            ///////////////////JUMP///////////////////
            //DESLIGAR DEL TIEMPO DE PROCESAMIENTO
            if (jump > 0)
            {
                jumpingElapsedTime += Tiempo;
                // 1/2 de gravedad * tiempo al cuadrado
                //jump -= 4.9f * jumpingElapsedTime * jumpingElapsedTime;
                jump    -= 150f * jumpingElapsedTime * jumpingElapsedTime;
                moving   = true;
                saltando = true;
                if (jump <= 0)
                {
                    jump = 0;
                }
            }
            else
            {
                //bloqueo de varios saltos sucesivos, sin el jumpingElapsedTime <= 0 salta indefinidamente al mantener apretada la barra
                //se asume que el personaje tarda en bajar lo mismo que en subir
                if (jumpingElapsedTime > 0)
                {
                    jumpingElapsedTime -= Tiempo;
                }
                else
                {
                    if (d3dInput.keyDown(Key.Space))
                    {
                        jump               = fuerzaSalto;
                        moving             = true;
                        saltando           = true;
                        jumpingElapsedTime = 0;
                    }
                }
            }
            ///////////////////JUMP//////////////////
            #endregion


            //Si hubo rotacion
            if (rotating)
            {
                //Rotar personaje y la camara, hay que multiplicarlo por el tiempo transcurrido para no atarse a la velocidad el hardware
                float rotAngle = Geometry.DegreeToRadian(rotate);
                mesh.rotateY(rotAngle);
                RotacionPersonaje = rotAngle;
                GuiController.Instance.ThirdPersonCamera.rotateY(rotAngle);
            }

            //Si hubo desplazamiento
            if (moving)
            {
                if (saltando)
                {
                    //Activar animacion de salto
                    mesh.playAnimation("MatrixJump", true);
                }
                else
                {
                    //Activar animacion de caminando
                    mesh.playAnimation("Walk", true);
                }
            }

            else if (pegando)
            {
                mesh.playAnimation("ComboPunch", true);
            }

            else if (pateando)
            {
                mesh.playAnimation("HighKick", true);
            }

            else if (saltando)
            {
                mesh.playAnimation("MatrixJump", true);
            }


            //Si no se esta moviendo, activar animacion de Parado
            else
            {
                mesh.playAnimation("StandBy", true);
            }

            #region personaje
            //Mover personaje con detección de colisiones, sliding y gravedad
            Vector3 movementVector = Vector3.Empty;
            if (moving)
            {
                //Aplicar movimiento, desplazarse en base a la rotacion actual del personaje
                movementVector = new Vector3(
                    FastMath.Sin(mesh.Rotation.Y) * moveForward,
                    jump,
                    FastMath.Cos(mesh.Rotation.Y) * moveForward
                    );
            }

            //Actualizar valores de gravedad
            collisionManager.GravityEnabled = (bool)GuiController.Instance.Modifiers["HabilitarGravedad"];
            collisionManager.GravityForce   = (Vector3)GuiController.Instance.Modifiers["Gravedad"];
            collisionManager.SlideFactor    = (float)GuiController.Instance.Modifiers["SlideFactor"];

            //Mover personaje con detección de colisiones, sliding y gravedad

            Vector3 realMovement = collisionManager.moveCharacter(characterSphere, movementVector, ControladorJuego.getInstance().objetosColisionablesDinamicos);
            PosicionActual = mesh.Position;
            mesh.move(realMovement);
            #endregion

            #region camara

            // GuiController.Instance.ThirdPersonCamera.Target = mesh.Position;
            // GuiController.Instance.ThirdPersonCamera.OffsetForward = -700f;
            #endregion
        }
Exemplo n.º 4
0
        public void render(float time)
        {
            d3dDevice.RenderState.AlphaBlendEnable = false;
            skyBox.render();
            sonido.render(time);
            sonido2.render(time);

            bool showQuadtree = (bool)GuiController.Instance.Modifiers["showQuadtree"];
            bool showTerrain  = (bool)GuiController.Instance.Modifiers["showTerrain"];

            if (showTerrain)
            {
                foreach (TgcMesh mesh in terrenoMesh)
                {
                    mesh.render();
                }
            }
            bool    showBB = (bool)GuiController.Instance.Modifiers.getValue("showBoundingBox");
            bool    frustumCullingEnabled = (bool)GuiController.Instance.Modifiers["culling"];
            bool    disparando            = ControladorJuego.getInstance().personaje.cDisparando;
            Vector3 lightPosition         = ControladorJuego.getInstance().personaje.disparo.PosicionActual;
            Vector3 initialPosition       = ControladorJuego.getInstance().personaje.disparo.getPosicionInicial();

            //solo aplico shader cuando estoy a cierta distancia del disparo y este existe
            Vector3 posicionDisparo = ControladorJuego.getInstance().personaje.disparo.PosicionActual;

            quadtree.render(GuiController.Instance.Frustum, showQuadtree);

            //Analizar cada malla contra el Frustum - con fuerza bruta
            int totalMeshes = 0;

            foreach (TgcMeshShader mesh in terreno.Meshes)
            {
                if (disparando /*&& calcularDistancia(mesh.Position ,posicionDisparo) >500*/)
                {
                    //Cargar variables de shader globales a todos los objetos
                    mesh.Effect.SetValue("fvLightPosition", TgcParserUtils.vector3ToFloat3Array(lightPosition));
                    mesh.Effect.SetValue("fvEyePosition", TgcParserUtils.vector3ToFloat3Array(initialPosition));
                    mesh.Effect.SetValue("fvAmbient", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["AmbientColor"]));
                    mesh.Effect.SetValue("fvDiffuse", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["DiffuseColor"]));
                    mesh.Effect.SetValue("fvSpecular", ColorValue.FromColor((Color)GuiController.Instance.Modifiers["SpecularColor"]));
                    mesh.Effect.SetValue("fSpecularPower", (float)GuiController.Instance.Modifiers["SpecularPower"]);
                }
                mesh.render();
            }



            //Render meshes
            if (showBB)
            {
                foreach (TgcMesh mesh in terreno.Meshes)
                {
                    mesh.BoundingBox.render();
                }
            }

            camera.Acercar();

            //foreach (TgcMesh mesh in meshes2)
            //{
            //    mesh.render();


            //}

            //foreach (TgcMesh mesh in meshes3)
            //{
            //    mesh.render();


            //}
        }