public void HudJugador(AutoManejable jugador, float posicionPorcentualX, float posicionPorcentualY, bool pantallaDoble) { var posicionEnX = D3DDevice.Instance.Width * posicionPorcentualX; var posicionEnY = D3DDevice.Instance.Height * posicionPorcentualY; var ratioVida = jugador.Vida / 1000; var extraPixelesVida = 118 * EscalaVelocimetro; Vida.Scaling = new TGCVector2(ratioVida * (EscalaVelocimetro + 0.01f), EscalaVelocimetro); VelocimetroAguja.Rotation = jugador.Velocidad / 50; VelocimetroFondo.Position = new TGCVector2(FastMath.Max(posicionEnX, 0), FastMath.Max(posicionEnY, 0)); VelocimetroAguja.Position = new TGCVector2(FastMath.Max(posicionEnX, 0), FastMath.Max(posicionEnY, 0)); BarraVida.Position = new TGCVector2(FastMath.Max(posicionEnX, 0), FastMath.Max(D3DDevice.Instance.Height * (posicionPorcentualY + 0.245f), 0)); Vida.Position = new TGCVector2(FastMath.Max(posicionEnX + extraPixelesVida, 0), FastMath.Max(D3DDevice.Instance.Height * (posicionPorcentualY + 0.245f), 0)); ChapaInvisibilidad.Position = new TGCVector2(FastMath.Max(posicionEnX, 0), FastMath.Max(D3DDevice.Instance.Height * (posicionPorcentualY + 0.285f), 0)); Invisible.Position = new TGCVector2(FastMath.Max(posicionEnX, 0), FastMath.Max(D3DDevice.Instance.Height * (posicionPorcentualY + 0.285f), 0)); Huds.DrawSprite(VelocimetroFondo); Huds.DrawSprite(VelocimetroAguja); Huds.DrawSprite(BarraVida); Huds.DrawSprite(Vida); Huds.DrawSprite(ChapaInvisibilidad); if (jugador.Invisible) { Huds.DrawSprite(Invisible); if (!pantallaDoble) { Huds.DrawSprite(Alarma); } } }
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); }
public void Juego(bool invisibilidadActivada, AutoManejable jugadorActivo, bool juegoDoble, bool pantallaDoble, AutoManejable J1, AutoManejable J2) { Huds.BeginDrawSprite(); if (juegoDoble) { if (pantallaDoble) { HudJugador(J1, 0.03f, 0.67f, pantallaDoble); HudJugador(J2, 0.85f, 0.67f, pantallaDoble); } else { HudJugador(jugadorActivo, 0.03f, 0.67f, pantallaDoble); } Huds.DrawSprite(Barra2); } else { HudJugador(J1, 0.03f, 0.67f, pantallaDoble); Huds.DrawSprite(Barra1); } Huds.EndDrawSprite(); }
public float DistanciaAlEnemigo(AutoManejable enemigo) { return(FastMath.Pow((FastMath.Pow2(enemigo.CuerpoRigidoAuto.CenterOfMassPosition.X - CuerpoRigidoAuto.CenterOfMassPosition.X) + FastMath.Pow2(enemigo.CuerpoRigidoAuto.CenterOfMassPosition.Z - CuerpoRigidoAuto.CenterOfMassPosition.Z)), 0.5f)); }
public void Render(AutoManejable AutoFisico1, AutoManejable AutoFisico2, PoliciasIA GrupoPolicias, Core.Camara.TgcCamera Camara, bool juegoDoble) { // 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(); } if (juegoDoble) { 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 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(); } if (juegoDoble) { foreach (var mesh in AutoFisico2.Mayas) { mesh.Effect = EnvMap; mesh.Technique = "RenderScene"; mesh.Render(); } foreach (var rueda in AutoFisico2.Ruedas) { rueda.Effect = EnvMap; rueda.Technique = "RenderScene"; rueda.Render(); } } g_pCubeMap.Dispose(); //------------------------------------------------------------- }
public CamaraAtrasAF(AutoManejable nuevo_objetivo) { objetivo = nuevo_objetivo; this.SetCamera(PosicionCamaraAtras, CentroDelAuto); }
//Vector que va desde el centro de Masa de la IA al centro de Masa del Jugador Objetivo public TGCVector2 VectorAlEnemigo(AutoManejable enemigo) { return(new TGCVector2(enemigo.CuerpoRigidoAuto.CenterOfMassPosition.X - CuerpoRigidoAuto.CenterOfMassPosition.X, enemigo.CuerpoRigidoAuto.CenterOfMassPosition.Z - CuerpoRigidoAuto.CenterOfMassPosition.Z)); }
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); }