public override void Render()
        {
            PreRender();
            ClearTextures();

            bool invisibilidadActivada = (SwitchInvisibilidadJ1 - 1 == SwitchCamara) || (SwitchInvisibilidadJ2 == SwitchCamara);

            //Permito las particulas
            D3DDevice.Instance.ParticlesEnabled = true;
            D3DDevice.Instance.EnableParticles();


            switch (SwitchInicio)
            {
            case 1:
            {
                Hud.PantallaInicio();
                if (Input.keyPressed(Key.C))
                {
                    SwitchInicio = 2;
                }
                if (Input.keyPressed(Key.D1))
                {
                    Jugadores[1] = null;
                    SwitchInicio = 3;
                    SwitchMusica = true;
                    SwitchFX     = true;
                    AutoFisico1.Encendido();
                    inGame = true;
                }
                if (Input.keyPressed(Key.D2))
                {
                    juegoDoble   = true;
                    SwitchInicio = 4;
                    SwitchMusica = true;
                    SwitchFX     = true;
                    SwitchCamara = 3;
                    AutoFisico1.Encendido();
                    AutoFisico2.Encendido();
                    inGame = true;
                }
                break;
            }

            case 2:
            {
                Hud.PantallaControles();
                if (Input.keyPressed(Key.V))
                {
                    SwitchInicio = 1;
                }
                break;
            }

            case 3:
            {
                var device = D3DDevice.Instance.Device;


                Tiempo += ElapsedTime;
                AutoFisico1.ElapsedTime = ElapsedTime;
                AutoFisico1.FXActivado  = SwitchFX;

                // ShaderInvisibilidad -----
                Invisibilidad.Technique = "DefaultTechnique";
                var pOldRT = device.GetRenderTarget(0);
                var pSurf  = g_pRenderTarget.GetSurfaceLevel(0);
                if (invisibilidadActivada)
                {
                    device.SetRenderTarget(0, pSurf);
                }
                var pOldDS = device.DepthStencilSurface;

                if (invisibilidadActivada)
                {
                    device.DepthStencilSurface = g_pDepthStencil;
                }

                device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                //---------------------------


                Plaza.RenderAll();
                AutoFisico1.Render(ElapsedTime);
                GrupoPolicias.Render(ElapsedTime);
                Cielo.Render();

                pSurf.Dispose();

                if (invisibilidadActivada)
                {
                    device.DepthStencilSurface = pOldDS;
                    device.SetRenderTarget(0, pOldRT);
                    Invisibilidad.Technique = "PostProcess";
                    Invisibilidad.SetValue("time", Tiempo);
                    device.VertexFormat = CustomVertex.PositionTextured.Format;
                    device.SetStreamSource(0, g_pVBV3D, 0);
                    Invisibilidad.SetValue("g_RenderTarget", g_pRenderTarget);

                    device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                    Invisibilidad.Begin(FX.None);
                    Invisibilidad.BeginPass(0);
                    device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
                    Invisibilidad.EndPass();
                    Invisibilidad.End();
                }

                Hud.Juego(invisibilidadActivada, JugadorActivo, juegoDoble, pantallaDoble, AutoFisico1, AutoFisico2);

                if (AutoFisico1.Vida < 0)
                {
                    TiempoFinal = Tiempo;
                    Sonidos.SuenaGameOver();
                    SwitchInicio = 5;
                }

                if (Input.keyDown(Key.F10))
                {
                    Hud.Pausar();
                }

                //  Shader Enviroment Map --------------------------------
                //D3DDevice.Instance.Device.EndScene();
                var g_pCubeMap = new CubeTexture(D3DDevice.Instance.Device, 256, 1, Usage.RenderTarget, Format.A16B16G16R16F, Pool.Default);
                var pOldRT2    = D3DDevice.Instance.Device.GetRenderTarget(0);

                D3DDevice.Instance.Device.Transform.Projection = TGCMatrix.PerspectiveFovLH(Geometry.DegreeToRadian(90.0f), 1f, 1f, 10000f).ToMatrix();

                // Genero las caras del enviroment map
                for (var nFace = CubeMapFace.PositiveX; nFace <= CubeMapFace.NegativeZ; ++nFace)
                {
                    var pFace = g_pCubeMap.GetCubeMapSurface(nFace, 0);
                    D3DDevice.Instance.Device.SetRenderTarget(0, pFace);
                    TGCVector3 Dir, VUP;
                    Color      color;
                    switch (nFace)
                    {
                    default:
                    case CubeMapFace.PositiveX:
                        // Left
                        Dir   = new TGCVector3(1, 0, 0);
                        VUP   = TGCVector3.Up;
                        color = Color.Black;
                        break;

                    case CubeMapFace.NegativeX:
                        // Right
                        Dir   = new TGCVector3(-1, 0, 0);
                        VUP   = TGCVector3.Up;
                        color = Color.Red;
                        break;

                    case CubeMapFace.PositiveY:
                        // Up
                        Dir   = TGCVector3.Up;
                        VUP   = new TGCVector3(0, 0, -1);
                        color = Color.Gray;
                        break;

                    case CubeMapFace.NegativeY:
                        // Down
                        Dir   = TGCVector3.Down;
                        VUP   = new TGCVector3(0, 0, 1);
                        color = Color.Yellow;
                        break;

                    case CubeMapFace.PositiveZ:
                        // Front
                        Dir   = new TGCVector3(0, 0, 1);
                        VUP   = TGCVector3.Up;
                        color = Color.Green;
                        break;

                    case CubeMapFace.NegativeZ:
                        // Back
                        Dir   = new TGCVector3(0, 0, -1);
                        VUP   = TGCVector3.Up;
                        color = Color.Blue;
                        break;
                    }

                    D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, color, 1.0f, 0);
                    //Renderizar

                    foreach (var mesh in AutoFisico1.Mayas)
                    {
                        mesh.Effect    = EnvMap;
                        mesh.Technique = "RenderScene";
                        mesh.Render();
                    }
                }

                D3DDevice.Instance.Device.SetRenderTarget(0, pOldRT2);
                D3DDevice.Instance.Device.Transform.View       = Camara.GetViewMatrix().ToMatrix();
                D3DDevice.Instance.Device.Transform.Projection = TGCMatrix.PerspectiveFovLH(Geometry.DegreeToRadian(45.0f), D3DDevice.Instance.AspectRatio, 1f, 10000f).ToMatrix();

                //D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                EnvMap.SetValue("g_txCubeMap", g_pCubeMap);

                foreach (var mesh in AutoFisico1.Mayas)
                {
                    mesh.Effect    = EnvMap;
                    mesh.Technique = "RenderScene";
                    mesh.Render();
                }
                foreach (var rueda in AutoFisico1.Ruedas)
                {
                    rueda.Effect    = EnvMap;
                    rueda.Technique = "RenderScene";
                    rueda.Render();
                }
                foreach (var mesh in GrupoPolicias.Todos[0].Mayas)
                {
                    mesh.Effect    = EnvMap;
                    mesh.Technique = "RenderScene";
                    mesh.Render();
                }

                g_pCubeMap.Dispose();
                //-------------------------------------------------------------

                Hud.Tiempo(FastMath.Floor(Tiempo));
                break;
            }

            case 4:
            {
                var device = D3DDevice.Instance.Device;


                Tiempo += ElapsedTime;
                AutoFisico1.ElapsedTime = ElapsedTime;
                AutoFisico2.ElapsedTime = ElapsedTime;
                AutoFisico1.FXActivado  = SwitchFX;
                AutoFisico2.FXActivado  = SwitchFX;

                // ShaderInvisibilidad -----
                Invisibilidad.Technique = "DefaultTechnique";
                var pOldRT = device.GetRenderTarget(0);
                var pSurf  = g_pRenderTarget.GetSurfaceLevel(0);
                if (invisibilidadActivada)
                {
                    device.SetRenderTarget(0, pSurf);
                }
                var pOldDS = device.DepthStencilSurface;

                if (invisibilidadActivada)
                {
                    device.DepthStencilSurface = g_pDepthStencil;
                }

                device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                //--------------------------


                DrawText.drawText("Velocidad P1:" + AutoFisico1.Velocidad, 0, 90, Color.Green);


                Plaza.RenderAll();
                AutoFisico1.Render(ElapsedTime);
                AutoFisico2.Render(ElapsedTime);
                GrupoPolicias.Render(ElapsedTime);
                Cielo.Render();

                pSurf.Dispose();

                if (invisibilidadActivada)
                {
                    device.DepthStencilSurface = pOldDS;
                    device.SetRenderTarget(0, pOldRT);
                    Invisibilidad.Technique = "PostProcess";
                    Invisibilidad.SetValue("time", Tiempo);
                    device.VertexFormat = CustomVertex.PositionTextured.Format;
                    device.SetStreamSource(0, g_pVBV3D, 0);
                    Invisibilidad.SetValue("g_RenderTarget", g_pRenderTarget);

                    device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                    Invisibilidad.Begin(FX.None);
                    Invisibilidad.BeginPass(0);
                    device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
                    Invisibilidad.EndPass();
                    Invisibilidad.End();
                }

                Hud.Juego(invisibilidadActivada, JugadorActivo, juegoDoble, pantallaDoble, AutoFisico1, AutoFisico2);
                if (AutoFisico1.Vida < 0)
                {
                    Hud.GanoJ2();
                    SwitchCamara = 2;
                    Jugadores[1] = null;
                    Sonidos.SuenaAplausos();
                    inGame = false;
                }
                if (AutoFisico2.Vida < 0)
                {
                    Hud.GanoJ1();
                    SwitchCamara = 1;
                    Jugadores[0] = null;
                    Sonidos.SuenaAplausos();
                    inGame = false;
                }

                if (Input.keyDown(Key.F10))
                {
                    Hud.Pausar();
                }

                if (Input.keyDown(Key.F10))
                {
                    Hud.Pausar();
                }

                //  Shader Enviroment Map --------------------------------
                //D3DDevice.Instance.Device.EndScene();
                var g_pCubeMap = new CubeTexture(D3DDevice.Instance.Device, 256, 1, Usage.RenderTarget, Format.A16B16G16R16F, Pool.Default);
                var pOldRT2    = D3DDevice.Instance.Device.GetRenderTarget(0);

                D3DDevice.Instance.Device.Transform.Projection = TGCMatrix.PerspectiveFovLH(Geometry.DegreeToRadian(90.0f), 1f, 1f, 10000f).ToMatrix();

                // Genero las caras del enviroment map
                for (var nFace = CubeMapFace.PositiveX; nFace <= CubeMapFace.NegativeZ; ++nFace)
                {
                    var pFace = g_pCubeMap.GetCubeMapSurface(nFace, 0);
                    D3DDevice.Instance.Device.SetRenderTarget(0, pFace);
                    TGCVector3 Dir, VUP;
                    Color      color;
                    switch (nFace)
                    {
                    default:
                    case CubeMapFace.PositiveX:
                        // Left
                        Dir   = new TGCVector3(1, 0, 0);
                        VUP   = TGCVector3.Up;
                        color = Color.Black;
                        break;

                    case CubeMapFace.NegativeX:
                        // Right
                        Dir   = new TGCVector3(-1, 0, 0);
                        VUP   = TGCVector3.Up;
                        color = Color.Red;
                        break;

                    case CubeMapFace.PositiveY:
                        // Up
                        Dir   = TGCVector3.Up;
                        VUP   = new TGCVector3(0, 0, -1);
                        color = Color.Gray;
                        break;

                    case CubeMapFace.NegativeY:
                        // Down
                        Dir   = TGCVector3.Down;
                        VUP   = new TGCVector3(0, 0, 1);
                        color = Color.Yellow;
                        break;

                    case CubeMapFace.PositiveZ:
                        // Front
                        Dir   = new TGCVector3(0, 0, 1);
                        VUP   = TGCVector3.Up;
                        color = Color.Green;
                        break;

                    case CubeMapFace.NegativeZ:
                        // Back
                        Dir   = new TGCVector3(0, 0, -1);
                        VUP   = TGCVector3.Up;
                        color = Color.Blue;
                        break;
                    }

                    D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, color, 1.0f, 0);
                    //Renderizar

                    foreach (var mesh in AutoFisico1.Mayas)
                    {
                        mesh.Effect    = EnvMap;
                        mesh.Technique = "RenderScene";
                        mesh.Render();
                    }

                    foreach (var mesh in AutoFisico2.Mayas)
                    {
                        mesh.Effect    = EnvMap;
                        mesh.Technique = "RenderScene";
                        mesh.Render();
                    }
                }

                D3DDevice.Instance.Device.SetRenderTarget(0, pOldRT2);
                D3DDevice.Instance.Device.Transform.View       = Camara.GetViewMatrix().ToMatrix();
                D3DDevice.Instance.Device.Transform.Projection = TGCMatrix.PerspectiveFovLH(Geometry.DegreeToRadian(45.0f), D3DDevice.Instance.AspectRatio, 1f, 10000f).ToMatrix();

                //D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                EnvMap.SetValue("g_txCubeMap", g_pCubeMap);

                foreach (var mesh in AutoFisico1.Mayas)
                {
                    mesh.Effect    = EnvMap;
                    mesh.Technique = "RenderScene";
                    mesh.Render();
                }
                foreach (var mesh in AutoFisico2.Mayas)
                {
                    mesh.Effect    = EnvMap;
                    mesh.Technique = "RenderScene";
                    mesh.Render();
                }
                foreach (var rueda in AutoFisico1.Ruedas)
                {
                    rueda.Effect    = EnvMap;
                    rueda.Technique = "RenderScene";
                    rueda.Render();
                }
                foreach (var mesh in GrupoPolicias.Todos[0].Mayas)
                {
                    mesh.Effect    = EnvMap;
                    mesh.Technique = "RenderScene";
                    mesh.Render();
                }

                g_pCubeMap.Dispose();
                //-------------------------------------------------------------

                Hud.Tiempo(FastMath.Floor(Tiempo));
                break;
            }

            case 5:
            {
                SwitchFX     = false;
                SwitchMusica = false;
                inGame       = false;
                Hud.JuegoTerminado();
                Hud.TiempoFinal(FastMath.Floor(TiempoFinal));
                if (Input.keyPressed(Key.M))
                {
                    SwitchInicio = 1;
                }
                break;
            }
            }

            PostRender();
        }
Example #2
0
        public override void Render()
        {
            PreRender();
            ClearTextures();

            bool invisibilidadActivada = ((JugadorActivo == AutoFisico1 && AutoFisico1.Invisible) || (JugadorActivo == AutoFisico2 && AutoFisico2.Invisible));

            //Permito las particulas
            D3DDevice.Instance.ParticlesEnabled = true;
            D3DDevice.Instance.EnableParticles();


            switch (SwitchInicio)
            {
            case 1:
            {
                Hud.PantallaInicio();
                if (Input.keyPressed(Key.C))
                {
                    SwitchInicio = 2;
                }
                if (Input.keyPressed(Key.D1))
                {
                    Jugadores[1] = null;
                    SwitchInicio = 3;
                    //SwitchMusica = true;
                    SwitchFX = true;
                    AutoFisico1.Encendido();
                    InGame = true;
                }
                if (Input.keyPressed(Key.D2))
                {
                    juegoDoble   = true;
                    SwitchInicio = 4;
                    //SwitchMusica = true;
                    SwitchFX     = true;
                    SwitchCamara = 3;
                    AutoFisico1.Encendido();
                    AutoFisico2.Encendido();
                    InGame = true;
                }
                break;
            }

            case 2:
            {
                Hud.PantallaControles();
                if (Input.keyPressed(Key.V))
                {
                    SwitchInicio = 1;
                }
                break;
            }

            case 3:
            {
                var device = D3DDevice.Instance.Device;

                Tiempo += ElapsedTime;
                AutoFisico1.ElapsedTime = ElapsedTime;
                AutoFisico1.FXActivado  = SwitchFX;

                Invisible.PreRender(invisibilidadActivada);

                Plaza.RenderAll();
                AutoFisico1.Render(ElapsedTime);
                GrupoPolicias.Render(ElapsedTime);
                Cielo.Render();

                Invisible.PostRender(invisibilidadActivada, Tiempo);

                Hud.Juego(invisibilidadActivada, JugadorActivo, juegoDoble, pantallaDoble, AutoFisico1, AutoFisico2);

                if (AutoFisico1.Vida < 0)
                {
                    TiempoFinal = Tiempo;
                    Sonidos.SuenaGameOver();
                    SwitchInicio = 5;
                }

                if (Input.keyDown(Key.F10))
                {
                    Hud.Pausar();
                }
                EnvMap.Render(AutoFisico1, AutoFisico2, GrupoPolicias, Camara, juegoDoble);

                Hud.Tiempo(FastMath.Floor(Tiempo));
                break;
            }

            case 4:
            {
                Tiempo += ElapsedTime;
                AutoFisico1.ElapsedTime = ElapsedTime;
                AutoFisico2.ElapsedTime = ElapsedTime;
                AutoFisico1.FXActivado  = SwitchFX;
                AutoFisico2.FXActivado  = SwitchFX;

                Invisible.PreRender(invisibilidadActivada);

                DrawText.drawText("Velocidad P1:" + AutoFisico1.Velocidad, 0, 90, Color.Green);


                Plaza.RenderAll();
                AutoFisico1.Render(ElapsedTime);
                AutoFisico2.Render(ElapsedTime);
                GrupoPolicias.Render(ElapsedTime);
                Cielo.Render();

                Invisible.PostRender(invisibilidadActivada, Tiempo);

                Hud.Juego(invisibilidadActivada, JugadorActivo, juegoDoble, pantallaDoble, AutoFisico1, AutoFisico2);
                if (AutoFisico1.Vida < 0)
                {
                    Hud.GanoJ2();
                    SwitchCamara = 2;
                    Sonidos.SuenaAplausos();
                    InGame = false;
                }
                if (AutoFisico2.Vida < 0)
                {
                    Hud.GanoJ1();
                    SwitchCamara = 1;
                    Sonidos.SuenaAplausos();
                    InGame = false;
                }

                if (Input.keyDown(Key.F10))
                {
                    Hud.Pausar();
                }

                if (Input.keyDown(Key.F10))
                {
                    Hud.Pausar();
                }

                EnvMap.Render(AutoFisico1, AutoFisico2, GrupoPolicias, Camara, juegoDoble);

                Hud.Tiempo(FastMath.Floor(Tiempo));
                break;
            }

            case 5:
            {
                SwitchFX     = false;
                SwitchMusica = false;
                InGame       = false;
                Hud.JuegoTerminado();
                Hud.TiempoFinal(FastMath.Floor(TiempoFinal));
                if (Input.keyPressed(Key.M))
                {
                    SwitchInicio = 1;
                }
                break;
            }
            }

            PostRender();
        }