Exemplo n.º 1
0
        public override void Init()
        {
            Tiempo    = 0;
            D3dDevice = D3DDevice.Instance.Device;

            Plaza            = new TgcSceneLoader().loadSceneFromFile(MediaDir + "Plaza-TgcScene.xml");
            MayasIA          = new TgcSceneLoader().loadSceneFromFile(MediaDir + "AutoPolicia-TgcScene.xml").Meshes;
            MayasAutoFisico1 = new TgcSceneLoader().loadSceneFromFile(MediaDir + "AutoAmarillo-TgcScene.xml").Meshes;
            MayasAutoFisico2 = new TgcSceneLoader().loadSceneFromFile(MediaDir + "AutoNaranja-TgcScene.xml").Meshes;
            PathHumo         = MediaDir + "Textures\\TexturaHumo.png";

            Sonidos   = new Sonidos(MediaDir, DirectSound.DsDevice);
            Invisible = new ShaderInvisibilidad(D3dDevice, ShadersDir);
            EnvMap    = new ShaderEnvMap(ShadersDir);

            //Cielo
            Cielo = new TgcSkyBox
            {
                Center = TGCVector3.Empty,
                Size   = new TGCVector3(10000, 10000, 10000)
            };
            var cieloPath = MediaDir + "Cielo\\";

            Cielo.setFaceTexture(TgcSkyBox.SkyFaces.Up, cieloPath + "cloudtop_up.jpg");
            Cielo.setFaceTexture(TgcSkyBox.SkyFaces.Down, cieloPath + "cloudtop_down.jpg");
            Cielo.setFaceTexture(TgcSkyBox.SkyFaces.Left, cieloPath + "cloudtop_left.jpg");
            Cielo.setFaceTexture(TgcSkyBox.SkyFaces.Right, cieloPath + "cloudtop_right.jpg");
            Cielo.setFaceTexture(TgcSkyBox.SkyFaces.Front, cieloPath + "cloudtop_front.jpg");
            Cielo.setFaceTexture(TgcSkyBox.SkyFaces.Back, cieloPath + "cloudtop_back.jpg");

            Cielo.SkyEpsilon = 11f;
            Cielo.Init();


            // Implemento la fisica
            Fisica = new FisicaMundo();
            for (int i = 30; i < 238; i++)
            {
                var objetos = BulletRigidBodyFactory.Instance.CreateRigidBodyFromTgcMesh(Plaza.Meshes[i]);
                Fisica.dynamicsWorld.AddRigidBody(objetos);
            }

            // Inicializo los coches
            AutoFisico1 = new AutoManejable(MayasAutoFisico1, new TGCVector3(-1000, 0, 3500), 270, Fisica, PathHumo, MediaDir, Sonidos);
            AutoFisico2 = new AutoManejable(MayasAutoFisico2, new TGCVector3(4000, 0, 3500), 270, Fisica, PathHumo, MediaDir, Sonidos);
            AutoFisico2.ConfigurarTeclas(Key.W, Key.S, Key.D, Key.A, Key.LeftControl, Key.Tab);
            AutoFisico1.ConfigurarTeclas(Key.UpArrow, Key.DownArrow, Key.RightArrow, Key.LeftArrow, Key.RightControl, Key.Space);
            AutoFisico1.Vida = 1000;
            AutoFisico2.Vida = 1000;
            Jugadores        = new[] { AutoFisico1, AutoFisico2 };
            GrupoPolicias    = new PoliciasIA(MayasIA, Fisica, PathHumo, Jugadores, MediaDir, Sonidos);
            Players          = new List <AutoManejable> {
                AutoFisico1, AutoFisico2
            };                                                              // Para el sonido y las colisiones

            SwitchInicio = 1;
            SwitchCamara = 1;
            Hud          = new Hud(MediaDir, Jugadores);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Se llama una sola vez, al principio cuando se ejecuta el ejemplo.
        ///     Escribir aquí todo el código de inicialización: cargar modelos, texturas, estructuras de optimización, todo
        ///     procesamiento que podemos pre calcular para nuestro juego.
        ///     Borrar el codigo ejemplo no utilizado.
        /// </summary>
        public override void Init()
        {
            FinishedLoading = false;
            crono           = new Cronometro(tiempoJuego, this);
            //Device de DirectX para crear primitivas.
            var d3dDevice = D3DDevice.Instance.Device;

            GodModeOn = true; //cuando llamo a toggle lo pone en false

            sonidos = new Sonidos(MediaDir);
            CargarScenes();
            ToggleGodCamera();
            pointLuz  = new PointLight2(this, new Vector3(100f, 100f, 100f));
            pointLuz2 = new PointLight2(this, new Vector3(100f, 100f, 100f));
            Vector3 posicion = new Vector3(800f, 20f, 250f); //Y=8 para q este cerca del piso

            float velocidad   = dificultadJuego;
            float tiempEspera = 70f;
            float ang         = 30f;

            autoOponente = new AutoOponente(this, AutoJugador, 0.1f * velocidad, ang, tiempEspera, posicion);
        }
Exemplo n.º 3
0
 public PoliciasIA(List <TgcMesh> mayas, FisicaMundo fisica, string pathHumo, AutoManejable[] enemigos, string mediaDir, Sonidos sonido)
 {
     Policia01 = new AutoIA(mayas, new TGCVector3(-1000, 0, 0), 270, fisica, pathHumo, enemigos, mediaDir, sonido);
     Policia02 = new AutoIA(mayas, new TGCVector3(0, 0, 0), 270, fisica, pathHumo, enemigos, mediaDir, sonido);
     Policia03 = new AutoIA(mayas, new TGCVector3(1000, 0, 0), 270, fisica, pathHumo, enemigos, mediaDir, sonido);
     Policia04 = new AutoIA(mayas, new TGCVector3(2000, 0, 0), 270, fisica, pathHumo, enemigos, mediaDir, sonido);
     Policia05 = new AutoIA(mayas, new TGCVector3(3000, 0, 0), 270, fisica, pathHumo, enemigos, mediaDir, sonido);
     Policia06 = new AutoIA(mayas, new TGCVector3(-1000, 0, 300), 270, fisica, pathHumo, enemigos, mediaDir, sonido);
     Policia07 = new AutoIA(mayas, new TGCVector3(0, 0, 300), 270, fisica, pathHumo, enemigos, mediaDir, sonido);
     Policia08 = new AutoIA(mayas, new TGCVector3(1000, 0, 300), 270, fisica, pathHumo, enemigos, mediaDir, sonido);
     Policia09 = new AutoIA(mayas, new TGCVector3(2000, 0, 300), 270, fisica, pathHumo, enemigos, mediaDir, sonido);
     Policia10 = new AutoIA(mayas, new TGCVector3(3000, 0, 300), 270, fisica, pathHumo, enemigos, mediaDir, sonido);
     Todos     = new List <AutoIA>
     {
         Policia01,
         Policia02,
         Policia03,
         Policia04,
         Policia05,
         Policia06,
         Policia07,
         Policia08,
         Policia09,
         Policia10
     };
 }
        public void Update(TgcD3dInput input, TgcScene escneraio, PoliciasIA policias, bool inGame)
        {
            Fisica.dynamicsWorld.StepSimulation(1 / 60f, 10);
            CuerpoRigidoAuto.ActivationState = ActivationState.ActiveTag;
            CuerpoRigidoAuto.AngularVelocity = TGCVector3.Empty.ToBulletVector3();
            float fuerzaMotor = 0;

            Sonidos.SuenaMotor(false, this);

            //Movimientos Adelante-Atras
            if (EnElPiso())
            {
                CuerpoRigidoAuto.SetDamping(0.32f, 0.1f);
                if (input.keyDown(TeclaAcelerar))
                {
                    if (Velocidad >= 0)
                    {
                        Direccion   = 1;
                        fuerzaMotor = 14000f * ElapsedTime;
                        if (FXActivado)
                        {
                            Sonidos.SuenaMotor(true, this);
                        }
                        else
                        {
                            Sonidos.SuenaMotor(false, this);
                        }
                    }
                }
                else if (input.keyDown(TeclaAtras))
                {
                    if (Velocidad <= 5f)
                    {
                        Direccion   = -1;
                        fuerzaMotor = 300f;
                        if (FXActivado)
                        {
                            Sonidos.SuenaMotor(true, this);
                        }
                        else
                        {
                            Sonidos.SuenaMotor(false, this);
                        }
                    }
                }

                //Movimientos Derecha-Izquierda
                if (input.keyDown(TeclaIzquierda))
                {
                    CuerpoRigidoAuto.ApplyImpulse(new TGCVector3(1, 0, 0).ToBulletVector3() * FuerzaAlGirar(), new TGCVector3(20, 10, -60).ToBulletVector3());
                    CuerpoRigidoAuto.ApplyImpulse(new TGCVector3(-1, 0, 0).ToBulletVector3() * FuerzaAlGirar(), new TGCVector3(20, 10, 60).ToBulletVector3());
                    GradosRuedaAlDoblar = FastMath.Max(GradosRuedaAlDoblar - 0.04f, -0.7f);
                }
                else if (input.keyDown(TeclaDerecha))
                {
                    CuerpoRigidoAuto.ApplyImpulse(new TGCVector3(-1, 0, 0).ToBulletVector3() * FuerzaAlGirar(), new TGCVector3(20, 10, -60).ToBulletVector3());
                    CuerpoRigidoAuto.ApplyImpulse(new TGCVector3(1, 0, 0).ToBulletVector3() * FuerzaAlGirar(), new TGCVector3(20, 10, 60).ToBulletVector3());
                    GradosRuedaAlDoblar = FastMath.Min(GradosRuedaAlDoblar + 0.04f, 0.7f);
                }
                else
                {
                    GradosRuedaAlDoblar = 0;
                }

                //Movimientos Freno
                if (input.keyDown(TeclaFreno))
                {
                    CuerpoRigidoAuto.Friction = 8f;
                    if (FXActivado)
                    {
                        Sonidos.SuenaFrenada();
                    }
                }
                else
                {
                    CuerpoRigidoAuto.Friction = FriccionAuto;
                }

                //Movimientos Salto
                if (input.keyPressed(TeclaSalto))
                {
                    FuerzaSalto = 21f;
                    CuerpoRigidoAuto.ApplyCentralImpulse(VectorSalto.ToBulletVector3() * FuerzaSalto * Velocidad);
                }
            }
            else
            {
                CuerpoRigidoAuto.SetDamping(0f, 0f);
                if (input.keyDown(TeclaIzquierda))
                {
                    GradosRuedaAlDoblar = FastMath.Max(GradosRuedaAlDoblar - 0.04f, -0.7f);
                }
                else if (input.keyDown(TeclaDerecha))
                {
                    GradosRuedaAlDoblar = FastMath.Min(GradosRuedaAlDoblar + 0.04f, 0.7f);
                }
            }
            float impulso = 0;

            if (Velocidad < 15)
            {
                impulso = fuerzaMotor;
            }
            else if (Velocidad >= 15 && Velocidad < 35)
            {
                impulso = 1.8f * fuerzaMotor;
            }
            else if (Velocidad >= 35 && Velocidad < 60)
            {
                impulso = 3.2f * fuerzaMotor;
            }
            else if (Velocidad >= 60 && Velocidad < 80)
            {
                impulso = 4.2f * fuerzaMotor;
            }
            else if (Velocidad >= 80 && Velocidad < 100)
            {
                impulso = 5.2f * fuerzaMotor;
            }
            else
            {
                impulso = FastMath.Min(7f * fuerzaMotor, 1020f);
            }
            CuerpoRigidoAuto.ApplyCentralImpulse(impulso * VersorDirector.ToBulletVector3() * Direccion);

            //Colisiones entre los autos y los policias
            foreach (var Policia in policias.Todos)
            {
                if (TgcCollisionUtils.testAABBAABB(BBFinal, Policia.BBFinal) && inGame)
                {
                    Vida -= 5;
                    Sonidos.SuenaChoque();
                }
            }
            //Colisiones entre los autos y el escenario
            foreach (var mesh in escneraio.Meshes)
            {
                if (TgcCollisionUtils.testAABBAABB(BBFinal, mesh.BoundingBox) && inGame)
                {
                    Vida -= 5;
                    Sonidos.SuenaChoque();
                }
            }
        }
        public AutoManejable(List <TgcMesh> mayas, TGCVector3 posicionInicial, float direccionInicialEnGrados, FisicaMundo fisica, string pathHumo, string mediaDir, Sonidos sonidos) : base(mayas, posicionInicial, direccionInicialEnGrados, fisica, pathHumo, mediaDir, sonidos)
        {
            Direccion = 1;
            //Cuerpo Rigido Auto
            FriccionAuto = 0.1f;
            var tamañoAuto = new TGCVector3(25, AlturaCuerpoRigido, 80);

            CuerpoRigidoAuto             = BulletRigidBodyFactory.Instance.CreateBox(tamañoAuto, 100, PosicionInicial, 0, 0, 0, FriccionAuto, true);
            CuerpoRigidoAuto.Restitution = 0.3f;
            //CuerpoRigidoAuto.RollingFriction = 1000000;
            Fisica.dynamicsWorld.AddRigidBody(CuerpoRigidoAuto);
        }
Exemplo n.º 6
0
        public override void Init()
        {
            Tiempo = 0;
            var d3dDevice = D3DDevice.Instance.Device;

            Plaza            = new TgcSceneLoader().loadSceneFromFile(MediaDir + "Plaza-TgcScene.xml");
            MayasIA          = new TgcSceneLoader().loadSceneFromFile(MediaDir + "AutoPolicia-TgcScene.xml").Meshes;
            MayasAutoFisico1 = new TgcSceneLoader().loadSceneFromFile(MediaDir + "AutoAmarillo-TgcScene.xml").Meshes;
            MayasAutoFisico2 = new TgcSceneLoader().loadSceneFromFile(MediaDir + "AutoNaranja-TgcScene.xml").Meshes;
            PathHumo         = MediaDir + "Textures\\TexturaHumo.png";

            //Shader Invisibilidad
            Invisibilidad           = TGCShaders.Instance.LoadEffect(ShadersDir + "\\Invisibilidad.fx");
            Invisibilidad.Technique = "DefaultTechnique";

            g_pDepthStencil = d3dDevice.CreateDepthStencilSurface(d3dDevice.PresentationParameters.BackBufferWidth,
                                                                  d3dDevice.PresentationParameters.BackBufferHeight,
                                                                  DepthFormat.D24S8, MultiSampleType.None, 0, true);

            g_pRenderTarget = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                                          , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8,
                                          Pool.Default);

            Invisibilidad.SetValue("g_RenderTarget", g_pRenderTarget);

            // Resolucion de pantalla
            Invisibilidad.SetValue("screen_dx", d3dDevice.PresentationParameters.BackBufferWidth);
            Invisibilidad.SetValue("screen_dy", d3dDevice.PresentationParameters.BackBufferHeight);

            CustomVertex.PositionTextured[] vertices =
            {
                new CustomVertex.PositionTextured(-1,  1, 1, 0, 0),
                new CustomVertex.PositionTextured(1,   1, 1, 1, 0),
                new CustomVertex.PositionTextured(-1, -1, 1, 0, 1),
                new CustomVertex.PositionTextured(1,  -1, 1, 1, 1)
            };
            //Vertex buffer de los triangulos
            g_pVBV3D = new VertexBuffer(typeof(CustomVertex.PositionTextured),
                                        4, d3dDevice, Usage.Dynamic | Usage.WriteOnly,
                                        CustomVertex.PositionTextured.Format, Pool.Default);
            g_pVBV3D.SetData(vertices, 0, LockFlags.None);

            // --------------------------------------------------------------------
            //Shader EnvMap
            EnvMap           = TGCShaders.Instance.LoadEffect(ShadersDir + "\\EnvMap.fx");
            EnvMap.Technique = "RenderScene";
            posicionLuz      = new TGCVector3(1500, 600, 1500);

            // --------------------------------------------------------------------

            //Cielo
            Cielo = new TgcSkyBox
            {
                Center = TGCVector3.Empty,
                Size   = new TGCVector3(10000, 10000, 10000)
            };
            var cieloPath = MediaDir + "Cielo\\";

            Cielo.setFaceTexture(TgcSkyBox.SkyFaces.Up, cieloPath + "cloudtop_up.jpg");
            Cielo.setFaceTexture(TgcSkyBox.SkyFaces.Down, cieloPath + "cloudtop_down.jpg");
            Cielo.setFaceTexture(TgcSkyBox.SkyFaces.Left, cieloPath + "cloudtop_left.jpg");
            Cielo.setFaceTexture(TgcSkyBox.SkyFaces.Right, cieloPath + "cloudtop_right.jpg");
            Cielo.setFaceTexture(TgcSkyBox.SkyFaces.Front, cieloPath + "cloudtop_front.jpg");
            Cielo.setFaceTexture(TgcSkyBox.SkyFaces.Back, cieloPath + "cloudtop_back.jpg");

            Cielo.SkyEpsilon = 11f;
            Cielo.Init();


            // Implemento la fisica
            Fisica = new FisicaMundo();
            for (int i = 30; i < 238; i++)
            {
                var objetos = BulletRigidBodyFactory.Instance.CreateRigidBodyFromTgcMesh(Plaza.Meshes[i]);
                Fisica.dynamicsWorld.AddRigidBody(objetos);
            }


            // Inicializo los coches
            AutoFisico1 = new AutoManejable(MayasAutoFisico1, new TGCVector3(-1000, 0, 3500), 270, Fisica, PathHumo, MediaDir, DirectSound.DsDevice);
            AutoFisico2 = new AutoManejable(MayasAutoFisico2, new TGCVector3(4000, 0, 3500), 270, Fisica, PathHumo, MediaDir, DirectSound.DsDevice);
            AutoFisico2.ConfigurarTeclas(Key.W, Key.S, Key.D, Key.A, Key.LeftControl, Key.Tab);
            AutoFisico1.ConfigurarTeclas(Key.UpArrow, Key.DownArrow, Key.RightArrow, Key.LeftArrow, Key.RightControl, Key.Space);
            AutoFisico1.Vida = 1000;
            AutoFisico2.Vida = 1000;
            Jugadores        = new[] { AutoFisico1, AutoFisico2 };
            GrupoPolicias    = new PoliciasIA(MayasIA, Fisica, PathHumo, Jugadores, MediaDir, DirectSound.DsDevice);
            Players          = new List <AutoManejable> {
                AutoFisico1, AutoFisico2
            };                                                              // Para el sonido y las colisiones



            // Jugadores
            foreach (var auto in Players)
            {
                auto.sonidoAceleracion    = new TgcStaticSound();
                auto.sonidoDesaceleracion = new TgcStaticSound();
                auto.frenada = new TgcStaticSound();
                auto.choque  = new TgcStaticSound();

                auto.sonidoDesaceleracion.loadSound(MediaDir + "Musica\\Desacelerando.wav", -2000, DirectSound.DsDevice);
                auto.sonidoAceleracion.loadSound(MediaDir + "Musica\\Motor2.wav", -1700, DirectSound.DsDevice);
                auto.frenada.loadSound(MediaDir + "Musica\\Frenada.wav", -2000, DirectSound.DsDevice);
                auto.choque.loadSound(MediaDir + "Musica\\Choque1.wav", -2000, DirectSound.DsDevice);
            }

            SwitchInicio = 1;
            SwitchCamara = 1;
            Hud          = new Hud(MediaDir, Jugadores);
            Sonidos      = new Sonidos(MediaDir, DirectSound.DsDevice);
        }