public void Dispose(TgcMp3Player music) { if (music.FileName != null) { music.closeFile(); } }
private void Player() { TgcMp3Player player = new TgcMp3Player(); //if ((bool)GuiController.Instance.Modifiers["Musica"]) { if (player.getStatus() == TgcMp3Player.States.Open) { //Reproducir MP3 //FIXME //player.play(true); } if (player.getStatus() == TgcMp3Player.States.Stopped) { //Parar y reproducir MP3 player.closeFile(); player.play(true); } } /*else * { * if (player.getStatus() == TgcMp3Player.States.Playing) * { * //Parar el MP3 * player.stop(); * } * }*/ }
private void InitSoundtrack() { mp3Player = new TgcMp3Player { FileName = $"{ Game.Default.MediaDirectory}\\Soundtracks\\01-naughty-dog-logo.mp3" }; mp3Player.play(true); }
public override void render(float elapsedTime) { Device d3dDevice = GuiController.Instance.D3dDevice; //Ver si cambio el MP3 string filePath = (string)GuiController.Instance.Modifiers["MP3-File"]; loadMp3(filePath); //Contro del reproductor por teclado TgcMp3Player player = GuiController.Instance.Mp3Player; TgcMp3Player.States currentState = player.getStatus(); if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.Y)) { if (currentState == TgcMp3Player.States.Open) { //Reproducir MP3 player.play(true); } if (currentState == TgcMp3Player.States.Stopped) { //Parar y reproducir MP3 player.closeFile(); player.play(true); } } else if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.U)) { if (currentState == TgcMp3Player.States.Playing) { //Pausar el MP3 player.pause(); } } else if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.I)) { if (currentState == TgcMp3Player.States.Paused) { //Resumir la ejecución del MP3 player.resume(); } } else if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.O)) { if (currentState == TgcMp3Player.States.Playing) { //Parar el MP3 player.stop(); } } //Render texto currentMusicText.render(); instruccionesText.render(); }
/// <summary> /// Crea todos los modulos necesarios de la aplicacion /// </summary> internal void initGraphics(MainForm mainForm, Control panel3d) { this.mainForm = mainForm; this.panel3d = panel3d; this.fullScreenPanel = new FullScreenPanel(); panel3d.Focus(); //Iniciar graficos this.tgcD3dDevice = new TgcD3dDevice(panel3d); this.texturesManager = new TgcTexture.Manager(); this.tgcD3dDevice.OnResetDevice(tgcD3dDevice.D3dDevice, null); //Iniciar otras herramientas this.texturesPool = new TgcTexture.Pool(); this.logger = new Logger(mainForm.LogConsole); this.text3d = new TgcDrawText(tgcD3dDevice.D3dDevice); this.tgcD3dInput = new TgcD3dInput(mainForm, panel3d); this.fpsCamera = new TgcFpsCamera(); this.rotCamera = new TgcRotationalCamera(); this.thirdPersonCamera = new TgcThirdPersonCamera(); this.axisLines = new TgcAxisLines(tgcD3dDevice.D3dDevice); this.userVars = new TgcUserVars(mainForm.getDataGridUserVars()); this.modifiers = new TgcModifiers(mainForm.getModifiersPanel()); this.elapsedTime = -1; this.frustum = new TgcFrustum(); this.mp3Player = new TgcMp3Player(); this.directSound = new TgcDirectSound(); this.fog = new TgcFog(); this.currentCamera = this.rotCamera; this.customRenderEnabled = false; this.drawer2D = new TgcDrawer2D(); this.shaders = new TgcShaders(); //toogles this.rotCamera.Enable = true; this.fpsCamera.Enable = false; this.thirdPersonCamera.Enable = false; this.fpsCounterEnable = true; this.axisLines.Enable = true; //Cargar algoritmos exampleLoader = new ExampleLoader(); examplesDir = System.Environment.CurrentDirectory + "\\" + ExampleLoader.EXAMPLES_DIR + "\\"; examplesMediaDir = examplesDir + "Media" + "\\"; alumnoEjemplosDir = System.Environment.CurrentDirectory + "\\" + "AlumnoEjemplos" + "\\"; alumnoEjemplosMediaDir = alumnoEjemplosDir + "AlumnoMedia" + "\\"; exampleLoader.loadExamplesInGui(mainForm.TreeViewExamples, new string[] { examplesDir, alumnoEjemplosDir }); //Cargar shaders del framework this.shaders.loadCommonShaders(); //Cargar ejemplo default TgcExample defaultExample = exampleLoader.getExampleByName(mainForm.Config.defaultExampleName, mainForm.Config.defaultExampleCategory); executeExample(defaultExample); }
public override void Init() { time = 0; playerModel.Init(); collectModel.Init(); collectModel.Player = playerModel; historyModel.Init(); youWinModel.Init(); //Skybox LoadSkyBox(); //LoadSkyBoxUndersea(); //Heightmap currentHeightmap = MediaDir + "\\Level1\\Heigthmap\\" + "hm_level1.jpg"; var currentTexture = MediaDir + "\\Level1\\Textures\\" + "level1.PNG"; currentScaleXZ = 150f; currentScaleY = 2f; underseaTerrain = new TgcSimpleTerrain(); underseaTerrain.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, new TGCVector3(0, 0, 0)); underseaTerrain.loadTexture(currentTexture); underseaTerrain.AlphaBlendEnable = true; bulletManager = new BulletSharpManager(initialPosition, Input, Camera, playerModel); bulletManager.Init(underseaTerrain); //Surface LoadSurface(); //Meshes LoadMeshes(); //Collectables LoadCollectableMeshes(); //HUD hudModel.Init(); //Shaders LoadShaders(); fogEffect = TGCShaders.Instance.LoadEffect(ShadersDir + "TgcFogShader.fx"); //OnlyForDebug(); music = new TgcMp3Player(); music.FileName = MediaDir + "\\Sounds\\rain.mp3"; music.play(true); }
public Musica(string mediaDir) { MediaDir = mediaDir; sonidos = new System.Collections.Generic.List <String>(); //sonidos.Add(MediaDir + "Sonido\\ambiente1.mp3"); //sonidos.Add(MediaDir + "Sonido\\ambiente2.mp3"); nroFile = 0; currentFile = null; mp3Player = new TgcMp3Player(); }
public EscenaGameOver(TgcCamera Camera, string MediaDir, string ShadersDir, TgcText2D DrawText, float TimeBetweenUpdates, TgcD3dInput Input) : base(Camera, MediaDir, ShadersDir, DrawText, TimeBetweenUpdates, Input) { gameOver = new CustomSprite(); gameOver.Bitmap = new CustomBitmap(MediaDir + "Textures\\GameOver.png", D3DDevice.Instance.Device); gameOver.Scaling = new TGCVector2((float)D3DDevice.Instance.Width / gameOver.Bitmap.Width, (float)D3DDevice.Instance.Height / gameOver.Bitmap.Height); gameOver.Position = new TGCVector2(0, 0); mp3Gameover = new TgcMp3Player(); mp3Gameover.FileName = MediaDir + "Music\\GameOver.mp3"; mp3Gameover.play(true); }
public Sonidos(string MediaDir) { //motor motor = new TgcMp3Player(); motor.FileName = MediaDir + "\\motor.mp3"; motor.play(true); frenada = new TgcMp3Player(); frenada.FileName = MediaDir + "\\frenada.mp3"; }
private void ReproducirMusica() { var player = new TgcMp3Player(); var currentState = player.getStatus(); if (currentState == TgcMp3Player.States.Open || currentState == TgcMp3Player.States.Stopped) { player.closeFile(); player.FileName = musicas[FuncionesMatematicas.Instance.NumeroAleatorioIntEntre(0, musicas.Count - 1)]; player.play(false); } }
//reproduce un tema previamente cargado, sino no pasa nada public void playMusica() { TgcMp3Player player = GuiController.Instance.Mp3Player; TgcMp3Player.States currentState = player.getStatus(); if (currentState == TgcMp3Player.States.Open) { //Reproducir MP3 player.play(true); } }
public static void play(TgcMp3Player music) { if (lastPlayed != null && lastPlayed == music) { return; } stop(lastPlayed); lastPlayed = music; lastPlayed.play(true); }
public override void close() { //corta la música al salir TgcMp3Player player = GuiController.Instance.Mp3Player; player.closeFile(); //dispose de blur effect.Dispose(); screenQuadVB.Dispose(); renderTarget2D.Dispose(); }
public Musica(string mediaDir) { MediaDir = mediaDir; sonidos = new System.Collections.Generic.List <String>(); sonidos.Add(MediaDir + "MySounds\\sound3.mp3"); sonidos.Add(MediaDir + "MySounds\\sound4.mp3"); sonidos.Add(MediaDir + "MySounds\\sound2.mp3"); sonidos.Add(MediaDir + "MySounds\\sound1.mp3"); nroFile = 0; currentFile = null; mp3Player = new TgcMp3Player(); }
public void render() { Device d3dDevice = GuiController.Instance.D3dDevice; TgcMp3Player player = GuiController.Instance.Mp3Player; TgcMp3Player.States currentState = player.getStatus(); if (currentState == TgcMp3Player.States.Open) { //Reproducir MP3 player.play(true); } }
public override void Init() { cameraOffset = new TGCVector3(0, 200, 400); personaje = new Personaje(MediaDir); nivel = new Nivel(MediaDir); collisionManager = new SphereCollisionManager(); collisionManager.GravityEnabled = true; collisionManager.GravityForce = VEC_GRAVEDAD; collisionManager.SlideFactor = 10f; ambiente = new TgcMp3Player(); ambiente.FileName = (MediaDir + "\\NsanityBeach.mp3"); ambiente.play(true); }
public GameSoundManager(string mediaDir, TgcDirectSound sound) { Menu = new TgcMp3Player(); Ambient = new TgcMp3Player(); SharkStalking = new TgcStaticSound(); Crafting = new TgcStaticSound(); SharkDead = new TgcStaticSound(); SharkAppear = new TgcStaticSound(); SharkAttack = new TgcStaticSound(); Collect = new TgcStaticSound(); EquipWeapon = new TgcStaticSound(); WeaponHit = new TgcStaticSound(); HitToShark = new TgcStaticSound(); ToSurface = new TgcStaticSound(); Submerge = new TgcStaticSound(); Init(mediaDir, sound); }
public void muteUnmute() { TgcMp3Player player = GuiController.Instance.Mp3Player; TgcMp3Player.States currentState = player.getStatus(); if (currentState == TgcMp3Player.States.Playing) { //Pausar el MP3 player.pause(); return; } else if (currentState == TgcMp3Player.States.Paused) { //Resumir la ejecución del MP3 player.resume(); } }
/// <summary> /// Método que carga los sonidos inicialmente. /// </summary> public static void Cargar() { Mp3Player = GuiController.Instance.Mp3Player; Mp3Player.FileName = Utiles.SonidosDir("Hans Zimmer - Drink up me hearties yo ho.mp3"); RuidoAmbienteOceano = new TgcStaticSound(); RuidoAmbienteOceano.loadSound(Utiles.SonidosDir("Oceano.wav")); RuidoAmbienteSubmarino = new TgcStaticSound(); RuidoAmbienteSubmarino.loadSound(Utiles.SonidosDir("Submarino.wav")); SonidoTrueno1 = new TgcStaticSound(); SonidoTrueno1.loadSound(Utiles.SonidosDir("Trueno01.wav")); SonidoTrueno2 = new TgcStaticSound(); SonidoTrueno2.loadSound(Utiles.SonidosDir("Trueno02.wav")); SuperMarioCoin = new TgcStaticSound(); SuperMarioCoin.loadSound(Utiles.SonidosDir("SuperMarioBros - Coin.wav")); }
public override void Init() { drawer2D = new Drawer2D(); //Crear Sprite backgroundSprite = new CustomSprite(); backgroundSprite.Bitmap = new CustomBitmap(MediaDir + "\\Bitmaps\\main3.jpg", D3DDevice.Instance.Device); text = new TgcText2D(); text.Text = "CARIBBEAN´S DEATH"; text.Color = Color.Red; text.Align = TgcText2D.TextAlign.RIGHT; text.Position = new Point(D3DDevice.Instance.Width - 500, 100); text.Size = new Size(300, 100); text.changeFont(new Font("TimesNewRoman", 25, FontStyle.Bold | FontStyle.Italic)); //Ubicarlo centrado en la pantalla var textureSize = backgroundSprite.Bitmap.Size; backgroundSprite.Position = new TGCVector2(0, 0); backgroundSprite.Scaling = new TGCVector2(0.75f, 0.35f); gui.Create(MediaDir); // menu principal gui.InitDialog(false, false); int W = D3DDevice.Instance.Width; int H = D3DDevice.Instance.Height; int x0 = W - 200; int y0 = H - 300; int dy = 80; int dy2 = dy; int dx = 200; gui.InsertMenuItem(ID_NUEVA_PARTIDA, " Jugar", "play.png", x0, y0, MediaDir, dx, dy); gui.InsertMenuItem(ID_CONTROLES, " Controles", "navegar.png", x0, y0 += dy2, MediaDir, dx, dy); gui.InsertMenuItem(ID_APP_EXIT, " Salir", "salir.png", x0, y0 += dy2, MediaDir, dx, dy); music = new TgcMp3Player(); music.FileName = MediaDir + "\\Sounds\\mainMenuMusic.mp3"; music.play(true); }
public override void Init() { //Texto para la musica actual currentMusicText = new TgcText2D(); currentMusicText.Text = "No music"; currentMusicText.Position = new Point(50, 20); currentMusicText.Color = Color.Gold; currentMusicText.changeFont(new Font(FontFamily.GenericMonospace, 16, FontStyle.Italic)); //Texto para las instrucciones de uso instruccionesText = new TgcText2D(); instruccionesText.Text = "Y = Play, U = Pause, I = Resume, O = Stop."; instruccionesText.Position = new Point(50, 60); instruccionesText.Color = Color.Green; instruccionesText.changeFont(new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold)); //Modifier para archivo MP3 currentFile = null; Modifiers.addFile("MP3-File", MediaDir + "Music\\I am The Money.mp3", "MP3s|*.mp3"); mp3Player = new TgcMp3Player(); }
public void render(float elapsedTime) { //moverse y rotar son variables que me indican a qué velocidad se moverá o rotará el mesh respectivamente. //Se inicializan en 0, porque por defecto está quieto. float moverse = 0f; float rotar = 0f; habilitarDecremento = true; GuiController.Instance.UserVars.setValue("Velocidad", Math.Abs(auto.velocidadActual)); GuiController.Instance.UserVars.setValue("Vida", escalaVida.X); GuiController.Instance.UserVars.setValue("AngCol", Geometry.RadianToDegree(anguloColision)); GuiController.Instance.UserVars.setValue("AngRot", Geometry.RadianToDegree(anguloARotar)); //aumento de la velocidad de rotacion al derrapar modificarVelocidadRotacion(auto); //Procesa las entradas del teclado. if (entrada.keyDown(Key.Q)) { finDeJuego = true; salirConQ = true; } if (entrada.keyDown(Key.S)) { moverse = auto.irParaAtras(elapsedTime); } if (entrada.keyDown(Key.W)) { moverse = auto.irParaAdelante(elapsedTime); } if (entrada.keyDown(Key.A) && (auto.velocidadActual > 0.5f || auto.velocidadActual < -0.5f)) //izquierda { rotar = -auto.velocidadRotacion; } if (entrada.keyDown(Key.D) && (auto.velocidadActual > 0.5f || auto.velocidadActual < -0.5f)) //derecha { rotar = auto.velocidadRotacion; } if (entrada.keyPressed(Key.M)) { musica.muteUnmute(); auto.mutearSonido(); } if (entrada.keyPressed(Key.R)) //boton de reset, el mesh vuelve a la posicion de inicio y restaura todos sus parametros { auto.reiniciar(); auto.mesh.move(new Vector3(0, 0, -3100)); auto.mesh.rotateY(-1.57f); EjemploAlumno.instance.activar_efecto = false; nivel.reiniciar(); this.reiniciar(); GuiController.Instance.ThirdPersonCamera.resetValues(); GuiController.Instance.ThirdPersonCamera.rotateY(-1.57f); } if (entrada.keyPressed(Key.B)) //Modo debug para visualizar BoundingBoxes entre otras cosas que nos sirvan a nosotros { Shared.debugMode = !Shared.debugMode; } if (entrada.keyPressed(Key.I)) { modoDios = !modoDios; } //Frenado por inercia if (!entrada.keyDown(Key.W) && !entrada.keyDown(Key.S) && auto.velocidadActual != 0) { moverse = auto.frenarPorInercia(elapsedTime); } if (moverse > auto.velocidadMaxima) { auto.velocidadActual = auto.velocidadMaxima; } if (moverse < (-auto.velocidadMaxima)) { auto.velocidadActual = -auto.velocidadMaxima; } int sentidoRotacion = 0; //sentido de rotacion del reajuste de camara float rotCamara = GuiController.Instance.ThirdPersonCamera.RotationY; float rotAuto = auto.mesh.Rotation.Y; float deltaRotacion = rotAuto - rotCamara; float dif = FastMath.Abs(Geometry.RadianToDegree(deltaRotacion)); float rapidez = 5f; //aceleracion de reajuste de camara if (rotar != 0) { habilitarDecremento = false; habilitarContador = true; } if (dif < 40) { if (dif < 30) { if (dif < 20) { rapidez = 0.8f; } else { rapidez = 2f; } } else { rapidez = 3f; } } if (habilitarContador) { pasaronSegundos += elapsedTime; } if (deltaRotacion < 0) { sentidoRotacion = -1; } else { sentidoRotacion = 1; } if (deltaRotacion != 0 && pasaronSegundos > 0.5f) { ajustar = true; pasaronSegundos = 0f; habilitarContador = false; } float rotAngle = Geometry.DegreeToRadian(rotar * elapsedTime); if (ajustar) { GuiController.Instance.ThirdPersonCamera.rotateY(sentidoRotacion * rapidez * elapsedTime); } if (deltaRotacion < 0) { sentidoRotacion = -1; } else { sentidoRotacion = 1; } incrementarTiempo(this, elapsedTime, habilitarDecremento); auto.mesh.rotateY(rotAngle); auto.obb.rotate(new Vector3(0, rotAngle, 0)); if (FastMath.Abs(Geometry.RadianToDegree(deltaRotacion)) % 360 < 3) { GuiController.Instance.ThirdPersonCamera.RotationY = rotAuto; ajustar = false; } if (habilitarDecremento) { incrementarTiempo(this, elapsedTime, habilitarDecremento); } if (moverse != 0 || auto.velocidadActual != 0) //Si hubo movimiento { Vector3 lastPos = auto.mesh.Position; auto.mesh.moveOrientedY(moverse * elapsedTime); Vector3 position = auto.mesh.Position; Vector3 posDiff = position - lastPos; auto.obb.move(posDiff); Vector3 direccion = new Vector3(FastMath.Sin(auto.mesh.Rotation.Y) * moverse, 0, FastMath.Cos(auto.mesh.Rotation.Y) * moverse); auto.direccion.PEnd = auto.obb.Center + Vector3.Multiply(direccion, 50f); //Detectar colisiones de BoundingBox utilizando herramienta TgcCollisionUtils bool collide = false; Vector3[] cornersAuto; Vector3[] cornersObstaculo; foreach (ObstaculoRigido obstaculo in nivel.obstaculos) { if (Colisiones.testObbObb2(auto.obb, obstaculo.obb)) //chequeo obstáculo por obstáculo si está chocando con auto { collide = true; obstaculoChocado = obstaculo; Shared.mostrarChispa = true; if (FastMath.Abs(auto.velocidadActual) > 800) { auto.reproducirSonidoChoque(FastMath.Abs(auto.velocidadActual)); auto.deformarMesh(obstaculo.obb, FastMath.Abs(auto.velocidadActual)); } if (FastMath.Abs(auto.velocidadActual) > 800 && !modoDios) { escalaVida.X -= 0.00003f * Math.Abs(auto.velocidadActual) * escalaInicial.X; if (escalaVida.X > 0.03f) { vida.setEscala(new Vector2(escalaVida.X, escalaVida.Y)); } else { finDeJuego = true; muerte = true; } } break; } } //Si hubo colision, restaurar la posicion anterior (sino sigo de largo) if (collide) { auto.mesh.Position = lastPos; auto.obb.updateValues(); moverse = auto.chocar(elapsedTime); if (FastMath.Abs(auto.velocidadActual) > 0) { cornersAuto = CalculosVectores.computeCorners(auto); cornersObstaculo = CalculosVectores.computeCorners(obstaculoChocado); List <Plane> carasDelObstaculo = CalculosVectores.generarCaras(cornersObstaculo); Vector3 NormalAuto = direccion; caraChocada = CalculosVectores.detectarCaraChocada(carasDelObstaculo, auto.puntoChoque); Vector3 NormalObstaculo = new Vector3(caraChocada.A, caraChocada.B, caraChocada.C); GuiController.Instance.UserVars.setValue("NormalObstaculoX", NormalObstaculo.X); GuiController.Instance.UserVars.setValue("NormalObstaculoZ", NormalObstaculo.Z); float desplazamientoInfinitesimal = 5f; float constanteDesvio = 1.3f; //Calculo el angulo entre ambos vectores anguloColision = CalculosVectores.calcularAnguloEntreVectoresNormalizados(NormalAuto, NormalObstaculo);//Angulo entre ambos vectores //rota mesh if (FastMath.Abs(auto.velocidadActual) > 800) { if (Geometry.RadianToDegree(anguloColision) < 25) //dado un cierto umbral, el coche rebota sin cambiar su direccion { auto.velocidadActual = -auto.velocidadActual; } else //el coche choca y cambia su direccion { if (NormalObstaculo.Z > 0 && direccion.X > 0 && direccion.Z > 0) { anguloARotar = constanteDesvio * (Geometry.DegreeToRadian(90) - anguloColision); auto.mesh.move(new Vector3(0, 0, -10)); colorDeColision = Color.Red; } if (NormalObstaculo.X > 0 && direccion.X > 0 && direccion.Z > 0) { anguloARotar = -constanteDesvio * (Geometry.DegreeToRadian(90) - anguloColision); auto.mesh.move(new Vector3(-5, 0, 0)); colorDeColision = Color.Salmon; } if (NormalObstaculo.X > 0 && direccion.X > 0 && direccion.Z < 0) { anguloARotar = constanteDesvio * (Geometry.DegreeToRadian(90) - anguloColision); colorDeColision = Color.Blue; auto.mesh.move(new Vector3(-desplazamientoInfinitesimal, 0, 0)); } if (NormalObstaculo.Z < 0 && direccion.X > 0 && direccion.Z < 0) { anguloARotar = -constanteDesvio * (Geometry.DegreeToRadian(90) - anguloColision); auto.mesh.move(new Vector3(0, 0, desplazamientoInfinitesimal)); colorDeColision = Color.Green; } if (NormalObstaculo.Z < 0 && direccion.X < 0 && direccion.Z < 0) { anguloARotar = constanteDesvio * (Geometry.DegreeToRadian(90) - anguloColision); auto.mesh.move(new Vector3(0, 0, desplazamientoInfinitesimal)); colorDeColision = Color.Pink; } if (NormalObstaculo.X < 0 && direccion.X < 0 && direccion.Z < 0) { anguloARotar = -constanteDesvio * (Geometry.DegreeToRadian(90) - anguloColision); auto.mesh.move(new Vector3(desplazamientoInfinitesimal, 0, 0)); colorDeColision = Color.Silver; } if (NormalObstaculo.X < 0 && direccion.X < 0 && direccion.Z > 0) { anguloARotar = constanteDesvio * (Geometry.DegreeToRadian(90) - anguloColision); auto.mesh.move(new Vector3(desplazamientoInfinitesimal, 0, 0)); colorDeColision = Color.Aquamarine; } if (NormalObstaculo.Z > 0 && direccion.X < 0 && direccion.Z > 0) { anguloARotar = -constanteDesvio * (Geometry.DegreeToRadian(90) - anguloColision); auto.mesh.move(new Vector3(0, 0, -desplazamientoInfinitesimal)); colorDeColision = Color.Yellow; } auto.mesh.rotateY(anguloARotar); } } } } foreach (Recursos recurso in nivel.recursos) { TgcCollisionUtils.BoxBoxResult result = TgcCollisionUtils.classifyBoxBox(auto.mesh.BoundingBox, recurso.modelo.BoundingBox); if (result == TgcCollisionUtils.BoxBoxResult.Adentro || result == TgcCollisionUtils.BoxBoxResult.Atravesando) { nivel.recursos.Remove(recurso); //Saca el recurso de la lista para que no se renderice más float puntos = Convert.ToSingle(this.puntos.Text) + 100f; this.puntos.Text = Convert.ToString(puntos); break; } } //Chequeo si el auto agarro el checkpoint actual if (Colisiones.testObbObb2(auto.obb, nivel.checkpointActual.obb)) { if (nivel.checkpointsRestantes.Text != "1") { nivel.checkpoints.Remove(nivel.checkpointActual); //Saca el checkpoint de la lista para que no se renderice más int restantes = (Convert.ToInt16(nivel.checkpointsRestantes.Text) - 1); nivel.checkpointsRestantes.Text = restantes.ToString(); //Le resto uno a los restantes this.tiempoRestante.Text = (Convert.ToSingle(this.tiempoRestante.Text) + 10f).ToString(); nivel.checkpointActual = nivel.checkpoints.ElementAt(0); } else { finDeJuego = true; } } //Efecto blur if (FastMath.Abs(auto.velocidadActual) > (auto.velocidadMaxima * 0.5555)) { EjemploAlumno.instance.activar_efecto = true; EjemploAlumno.instance.blur_intensity = 0.003f * (float)Math.Round(FastMath.Abs(auto.velocidadActual) / (auto.velocidadMaxima), 5); } else { EjemploAlumno.instance.activar_efecto = false; } } GuiController.Instance.ThirdPersonCamera.Target = auto.mesh.Position; //actualizo cam Vector2 vectorCam = (Vector2)GuiController.Instance.Modifiers["AlturaCamara"]; GuiController.Instance.ThirdPersonCamera.setCamera(auto.mesh.Position, vectorCam.X, vectorCam.Y); float tope = 1f; float constanteDerrape = ((tiempoTrans / 2) < tope) ? (tiempoTrans / 2) : tope; float proporcion = FastMath.Abs(auto.velocidadActual / auto.velocidadMaxima); if (sentidoAnterior != sentidoRotacion && tiempoTrans != 0) { incrementarTiempo(this, elapsedTime * 5, true); } if (tiempoTrans == 0) { sentidoAnterior = sentidoRotacion; } auto.mesh.rotateY(constanteDerrape * sentidoAnterior * proporcion); auto.render(); auto.obb = TgcObb.computeFromAABB(auto.mesh.BoundingBox); auto.obb.setRotation(auto.mesh.Rotation); auto.obb.setRenderColor(colorDeColision); auto.mesh.rotateY(-constanteDerrape * sentidoAnterior * proporcion); //dibuja el nivel nivel.render(elapsedTime); //AJUSTE DE CAMARA SEGUN COLISION ajustarCamaraSegunColision(auto, nivel.obstaculos); //Dibujo checkpoints restantes nivel.checkpointsRestantes.render(); //Dibujo el puntaje del juego this.puntos.render(); //CUENTA REGRESIVA if (this.tiempoRestante.Text == "1") { uno.render(); } if (this.tiempoRestante.Text == "2") { dos.render(); } if (this.tiempoRestante.Text == "3") { tres.render(); } //Actualizo y dibujo el relops if ((DateTime.Now.Subtract(this.horaInicio).TotalSeconds) > segundosAuxiliares && !modoDios) { this.tiempoRestante.Text = (Convert.ToDouble(tiempoRestante.Text) - 1).ToString(); if (this.tiempoRestante.Text == "0") //Si se acaba el tiempo, me muestra el game over y reseetea todo { finDeJuego = true; muerte = true; } segundosAuxiliares++; } this.tiempoRestante.render(); //Si se le acabo el tiempo o la vida, o apretó "Q" if (finDeJuego) { //corta la música al salir TgcMp3Player player = GuiController.Instance.Mp3Player; player.closeFile(); GuiController.Instance.UserVars.clearVars(); //saca el blur EjemploAlumno.instance.activar_efecto = false; //reinicia los valores de las cosas del juego auto.reiniciar(); nivel.reiniciar(); this.reiniciar(); //reinicia la camara GuiController.Instance.ThirdPersonCamera.resetValues(); if (muerte) { EjemploAlu.setPantalla(EjemploAlu.getPantalla(1)); } else if (salirConQ) { EjemploAlumno.getInstance().setPantalla(new PantallaInicio()); } else { EjemploAlu.setPantalla(EjemploAlu.getPantalla(2)); } } if (comienzoNivel) { if (DateTime.Now.Subtract(this.horaInicio).TotalSeconds < 3) { if (auto.nombre == "Luigi") { misionLuigi.render(); } else { misionMario.render(); } } else { comienzoNivel = false; } } else { //Dibujo barrita if (auto.nombre == "Luigi") { barra2.render(); } else { barra.render(); } vida.render(); } //renderizo utilidades del debugMode if (Shared.debugMode) { Vector2 vectorModifier = (Vector2)GuiController.Instance.Modifiers["PosicionFlechaDebug"]; Vector3 vectorPosicion = new Vector3(vectorModifier.X, 10, vectorModifier.Y); debugArrow.PStart = vectorPosicion + new Vector3(0, 400f, 0); debugArrow.PEnd = vectorPosicion; debugArrow.updateValues(); debugArrow.render(); //renderizo normal al plano chocado if (obstaculoChocado != null) { collisionNormalArrow.PStart = obstaculoChocado.obb.Center; collisionNormalArrow.PEnd = obstaculoChocado.obb.Center + Vector3.Multiply(new Vector3(caraChocada.A, caraChocada.B, caraChocada.C), 500f); collisionNormalArrow.updateValues(); collisionNormalArrow.render(); } } }
public EscenaJuego(TgcCamera Camera, string MediaDir, string ShadersDir, TgcText2D DrawText, float TimeBetweenUpdates, TgcD3dInput Input, List <Jugador> jugadores, Jugador jugadorActivo, Jugador segundoJugador = null, bool dia = true) : base(Camera, MediaDir, ShadersDir, DrawText, TimeBetweenUpdates, Input) { this.dia = dia; screenQuad = new TgcScreenQuad(); initFisica(); initMeshes(); this.jugadores = jugadores; this.jugadorActivo = jugadorActivo; this.jugadorDos = segundoJugador; initJugadores(); sol = new Luz(Color.White, new TGCVector3(0, 70, -130)); sonido = new TgcMp3Player(); sonido.FileName = MediaDir + "Music\\Acelerando.wav"; sonido.play(true); pelota = new Pelota(escena.getMeshByName("Pelota"), new TGCVector3(0f, 50f, 0)); pelota.Mesh.Effect.SetValue("texPerlin", TextureLoader.FromFile(D3DDevice.Instance.Device, MediaDir + "Textures\\PerlinNoise.png")); dynamicsWorld.AddRigidBody(pelota.Cuerpo); paredes = new Paredes(escena.getMeshByName("Box_5")); dynamicsWorld.AddRigidBody(paredes.Cuerpo); arcos = new Arco[2]; arcos[0] = new Arco(escena.getMeshByName("Arco"), FastMath.PI); arcos[1] = new Arco(escena.getMeshByName("Arco"), 0); dynamicsWorld.AddRigidBody(arcos[0].Cuerpo); dynamicsWorld.AddRigidBody(arcos[1].Cuerpo); camara = new CamaraJugador(jugadorActivo, pelota, Camera, paredes.Mesh.createBoundingBox()); if (PantallaDividida) { camaraDos = new CamaraJugador(segundoJugador, pelota, Camera, paredes.Mesh.createBoundingBox()); } ui = new UIEscenaJuego(); ui.Init(MediaDir, drawer2D); animacionGol = new AnimacionGol(pelota); //Cargar shader con efectos de Post-Procesado effect = TGCShaders.Instance.LoadEffect(ShadersDir + "CustomShaders.fx"); //Configurar Technique dentro del shader effect.Technique = "PostProcess"; effect.SetValue("screenWidth", D3DDevice.Instance.Device.PresentationParameters.BackBufferWidth); effect.SetValue("screenHeight", D3DDevice.Instance.Device.PresentationParameters.BackBufferHeight); g_pCubeMap = new CubeTexture(D3DDevice.Instance.Device, 64, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); //Creamos un Render Targer sobre el cual se va a dibujar la pantalla renderTargetBloom = new Texture(D3DDevice.Instance.Device, D3DDevice.Instance.Device.PresentationParameters.BackBufferWidth / 2, D3DDevice.Instance.Device.PresentationParameters.BackBufferHeight / 2, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); depthStencil = D3DDevice.Instance.Device.CreateDepthStencilSurface(D3DDevice.Instance.Device.PresentationParameters.BackBufferWidth, D3DDevice.Instance.Device.PresentationParameters.BackBufferHeight, DepthFormat.D24S8, MultiSampleType.None, 0, true); }
public override void Init() { //Para la creacion de checkpoints, borrar en el futuro System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); customCulture.NumberFormat.NumberDecimalSeparator = "."; System.Threading.Thread.CurrentThread.CurrentCulture = customCulture; Clipboard.Clear(); this.inicializarCamara(); //Seteo el personaje seteoDePersonaje(); //Seteo del monsturo seteoDelMonstruo(); //Seteo el escenario escenario = new TgcSceneLoader().loadSceneFromFile(MediaDir + "Mapa\\mapaProjectMarble-TgcScene.xml"); //initPuertaGiratoria(); //Almacenar volumenes de colision del escenario objetosColisionables.Clear(); CollisionManager.obstaculos = new List <BoundingBoxCollider>(); foreach (var mesh in escenario.Meshes) { if (mesh.Name.Contains("Recarga")) { BoundingBoxCollider recarga = BoundingBoxCollider.fromBoundingBox(mesh.BoundingBox); string[] nombre = Regex.Split(mesh.Name, "-"); recarga.nombre = nombre[1]; recarga.mesh = mesh; objetosRecarga.Add(recarga); } else { if (mesh.Name.Contains("Puerta")) { mesh.AutoTransformEnable = true; BoundingBoxCollider puerta = BoundingBoxCollider.fromBoundingBox(mesh.BoundingBox); puertas.Add(puerta); } if (mesh.Name.Contains("Placard") || mesh.Name.Contains("Locker")) { armarios.Add(BoundingBoxCollider.fromBoundingBox(mesh.BoundingBox)); } BoundingBoxCollider obj = BoundingBoxCollider.fromBoundingBox(mesh.BoundingBox); obj.nombre = mesh.Name; objetosColisionables.Add(obj); CollisionManager.obstaculos.Add(BoundingBoxCollider.fromBoundingBox(mesh.BoundingBox)); } meshEscenario.Add(mesh); } CheckpointHelper.BuildCheckpoints(); DestinoMonstruo = CheckpointHelper.checkpoints[0]; //Crear manejador de colisiones collisionManager = new ElipsoidCollisionManager(); collisionManager.SlideFactor = 2; collisionManager.GravityEnabled = false; colisionadorMonstruo = new ElipsoidCollisionManager(); colisionadorMonstruo.SlideFactor = 2; colisionadorMonstruo.GravityEnabled = false; drawer2D = new Drawer2D(); this.incializarMenu(); inicializarPantallaNegra(); mp3Player = new TgcMp3Player(); inicializarBarra(); iniciliazarAlarma(); incializarVisionNoctura(); luz = new Linterna(); }
/// <summary> /// constructor principal /// </summary> /// <param name="directSound"></param> /// <param name="mediaDir"></param> public SoundPlayer(TgcDirectSound directSound, String mediaDir) { mp3Player = new TgcMp3Player(); SoundsPath = mediaDir + "Sounds\\"; //inicializo sonidos //materiales TgcStaticSound glassSound = new TgcStaticSound(); glassSound.loadSound(SoundsPath + "Materials\\glass.wav", directSound.DsDevice); TgcStaticSound metalSound = new TgcStaticSound(); metalSound.loadSound(SoundsPath + "Materials\\metal.wav", directSound.DsDevice); //TODO buscar un sonido de planta, por ahora uso default TgcStaticSound plantSound = new TgcStaticSound(); plantSound.loadSound(SoundsPath + "Materials\\default.wav", directSound.DsDevice); TgcStaticSound woodSound = new TgcStaticSound(); woodSound.loadSound(SoundsPath + "Materials\\wood.wav", directSound.DsDevice); TgcStaticSound noneSound = new TgcStaticSound(); noneSound.loadSound(SoundsPath + "Materials\\default.wav", directSound.DsDevice); TgcStaticSound rockSound = new TgcStaticSound(); rockSound.loadSound(SoundsPath + "Materials\\rock.wav", directSound.DsDevice); MaterialSounds = new Dictionary <InteractiveObject.Materials, TgcStaticSound>(); MaterialSounds.Add(InteractiveObject.Materials.Wood, woodSound); MaterialSounds.Add(InteractiveObject.Materials.Glass, glassSound); MaterialSounds.Add(InteractiveObject.Materials.Metal, metalSound); MaterialSounds.Add(InteractiveObject.Materials.Plant, noneSound); MaterialSounds.Add(InteractiveObject.Materials.None, noneSound); MaterialSounds.Add(InteractiveObject.Materials.Rock, rockSound); //acciones TgcStaticSound drinkSound = new TgcStaticSound(); drinkSound.loadSound(SoundsPath + "Actions\\drink.wav", directSound.DsDevice); TgcStaticSound treeFallSound = new TgcStaticSound(); treeFallSound.loadSound(SoundsPath + "Actions\\tree_fall.wav", directSound.DsDevice); TgcStaticSound chestOpenSound = new TgcStaticSound(); chestOpenSound.loadSound(SoundsPath + "Actions\\chest_open.wav", directSound.DsDevice); TgcStaticSound successSound = new TgcStaticSound(); successSound.loadSound(SoundsPath + "Actions\\success.wav", directSound.DsDevice); TgcStaticSound hurtSound = new TgcStaticSound(); hurtSound.loadSound(SoundsPath + "Actions\\hurt.wav", directSound.DsDevice); TgcStaticSound dieSound = new TgcStaticSound(); dieSound.loadSound(SoundsPath + "Actions\\die.wav", directSound.DsDevice); TgcStaticSound jumpSound = new TgcStaticSound(); jumpSound.loadSound(SoundsPath + "Actions\\jump.wav", directSound.DsDevice); //menu TgcStaticSound menuWrongSound = new TgcStaticSound(); menuWrongSound.loadSound(SoundsPath + "Actions\\menu_wrong.wav", directSound.DsDevice); TgcStaticSound menuNextSound = new TgcStaticSound(); menuNextSound.loadSound(SoundsPath + "Actions\\menu_next.wav", directSound.DsDevice); TgcStaticSound menuSelectSound = new TgcStaticSound(); menuSelectSound.loadSound(SoundsPath + "Actions\\menu_select.wav", directSound.DsDevice); TgcStaticSound menuDiscardSound = new TgcStaticSound(); menuDiscardSound.loadSound(SoundsPath + "Actions\\menu_discard.wav", directSound.DsDevice); ActionSounds = new Dictionary <Actions, TgcStaticSound>(); ActionSounds.Add(Actions.Drink, drinkSound); ActionSounds.Add(Actions.TreeFall, treeFallSound); ActionSounds.Add(Actions.OpenChest, chestOpenSound); ActionSounds.Add(Actions.Success, successSound); ActionSounds.Add(Actions.Hurt, hurtSound); ActionSounds.Add(Actions.Die, dieSound); ActionSounds.Add(Actions.Jump, jumpSound); ActionSounds.Add(Actions.Menu_Discard, menuDiscardSound); ActionSounds.Add(Actions.Menu_Wrong, menuWrongSound); ActionSounds.Add(Actions.Menu_Next, menuNextSound); ActionSounds.Add(Actions.Menu_Select, menuSelectSound); //environment TgcStaticSound rainSound = new TgcStaticSound(); rainSound.loadSound(SoundsPath + "Environment\\rain.wav", directSound.DsDevice); TgcStaticSound windSound = new TgcStaticSound(); windSound.loadSound(SoundsPath + "Environment\\wind.wav", directSound.DsDevice); EnvironmentSounds = new Dictionary <EnvironmentConditions, TgcStaticSound>(); EnvironmentSounds.Add(EnvironmentConditions.Rain, rainSound); EnvironmentSounds.Add(EnvironmentConditions.Wind, windSound); mp3Player.FileName = SoundsPath + "Environment\\ambient.mp3"; }
public override void Init() { var d3dDevice = D3DDevice.Instance.Device; moto = new Moto(MediaDir, new Vector3(0, 0, 0)); moto.init(); texturaPiso = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "SkyBoxTron\\bottom.png"); pisoPlane = new TgcPlane(); pisoPlane.Origin = new Vector3(-5000, 0, -5000); pisoPlane.Size = new Vector3(10000, 0, 10000); pisoPlane.Orientation = TgcPlane.Orientations.XZplane; pisoPlane.setTexture(texturaPiso); pisoPlane.updateValues(); piso = pisoPlane.toMesh("piso"); piso.AutoTransformEnable = true; camaraInterna = new camara(moto); Camara = camaraInterna; camaraInterna.rotateY(FastMath.ToRad(180)); skyBoxTron = new SkyBox(MediaDir); skyBoxTron.init(); texto = new TgcText2D(); texto.Color = Color.Red; texto.Align = TgcText2D.TextAlign.LEFT; texto.Text = "Perdiste, toca la tecla R para reiniciar"; texto.Size = new Size(700, 400); texto.Position = new Point(550, 150); textoModoDios = new TgcText2D(); textoModoDios.Color = Color.Red; textoModoDios.Text = "Modo Dios Activado"; textoModoDios.Position = new Point(0, 30); textoModoDios.Size = new Size(500, 200); controladorIA = new ControladorIA(); this.generarOponentes(); perdido = false; cajas = new List <TgcMesh>(); cajaConLuz = new TgcSceneLoader().loadSceneFromFile(MediaDir + Game.Default.pathCajaMetalica).Meshes[0]; cajaConLuz.Position = new Vector3(0, 0, -200); cajaConLuz.Scale = new Vector3(0.8f, 0.8f, 0.8f); efectoLuz = TgcShaders.loadEffect(ShadersDir + "MultiDiffuseLights.fx"); this.generarCajas(100); controladorIA.setObstaculosEscenario(cajas); gestorPowerUps = new GestorPowerUps(); mp3Player = new TgcMp3Player(); mp3Player.closeFile(); mp3Player.FileName = MediaDir + Game.Default.pathMusica; mp3Player.play(true); }
public void Init(GameModel gameModel) { GModel = gameModel; var pisoTextura = TgcTexture.createTexture(D3DDevice.Instance.Device, GModel.MediaDir + "Texturas\\largerblock3b3dim.jpg"); var planeSize = new TGCVector3(500, 0, 500); var pisoOrientacion = TgcPlane.Orientations.XZplane; var texturaTipo1 = TgcTexture.createTexture(D3DDevice.Instance.Device, GModel.MediaDir + "\\Texturas\\blocks9.jpg"); var boxSize = new TGCVector3(20, 150, 500); var boxSize2 = new TGCVector3(500, 150, 20); pared1 = new List <TGCBox>(); pared2 = new List <TGCBox>(); piso = new List <TgcPlane>(); aabbDelEscenario = new List <TgcBoundingAxisAlignBox>(); plataformasDelEscenario = new List <TgcBoundingAxisAlignBox>(); desplazamientosDePlataformasDelEscenario = new List <TGCVector3>(); pilares = new List <TgcMesh>(); muebles = new List <TgcMesh>(); //--------------piso for (var i = 0; i < 8; i++) { var plane = new TgcPlane(new TGCVector3(0, 0, planeSize.Z * i), planeSize, pisoOrientacion, pisoTextura); piso.Add(plane); } for (var i = 9; i < 12; i++) { var plane = new TgcPlane(new TGCVector3(0, 0, planeSize.Z * i), planeSize, pisoOrientacion, pisoTextura); piso.Add(plane); } for (var i = 13; i < 16; i++) { var plane = new TgcPlane(new TGCVector3(0, 0, planeSize.Z * i), planeSize, pisoOrientacion, pisoTextura); piso.Add(plane); } for (var i = 2; i < 4; i++) { var plane = new TgcPlane(new TGCVector3(planeSize.X * i, 0, /*planeSize.Z * i*/ 8000), planeSize, pisoOrientacion, pisoTextura); piso.Add(plane); } //---------pared1 for (var i = 0; i < 8; i++) { var center = new TGCVector3(0, boxSize.Y / 2, (boxSize.Z / 2) + boxSize.Z * i); var box = TGCBox.fromSize(center, boxSize, texturaTipo1); box.AutoTransform = true; pared1.Add(box); aabbDelEscenario.Add(box.BoundingBox); } for (var i = 9; i < 12; i++) { var center = new TGCVector3(0, boxSize.Y / 2, (boxSize.Z / 2) + boxSize.Z * i); var box = TGCBox.fromSize(center, boxSize, texturaTipo1); box.AutoTransform = true; pared1.Add(box); aabbDelEscenario.Add(box.BoundingBox); } for (var i = 12; i < 17; i++) { var center = new TGCVector3(0, boxSize.Y / 2, (boxSize.Z / 2) + boxSize.Z * i); var box = TGCBox.fromSize(center, boxSize, texturaTipo1); box.AutoTransform = true; pared1.Add(box); aabbDelEscenario.Add(box.BoundingBox); } for (var i = 0; i < 4; i++) { var center = new TGCVector3((planeSize.X / 2) + boxSize2.X * i, boxSize2.Y / 2, 8500 /*(boxSize.Z / 2) + boxSize.Z * i*/); var box = TGCBox.fromSize(center, boxSize2, texturaTipo1); box.AutoTransform = true; pared1.Add(box); aabbDelEscenario.Add(box.BoundingBox); } //------pared2 for (var i = 0; i < 8; i++) { var center = new TGCVector3(planeSize.X, boxSize.Y / 2, (boxSize.Z / 2) + boxSize.Z * i); var box = TGCBox.fromSize(center, boxSize, texturaTipo1); box.AutoTransform = true; pared2.Add(box); aabbDelEscenario.Add(box.BoundingBox); } for (var i = 8; i < 12; i++) { var center = new TGCVector3(planeSize.X, boxSize.Y / 2, (boxSize.Z / 2) + boxSize.Z * i); var box = TGCBox.fromSize(center, boxSize, texturaTipo1); box.AutoTransform = true; pared2.Add(box); aabbDelEscenario.Add(box.BoundingBox); } for (var i = 12; i < 16; i++) { var center = new TGCVector3(planeSize.X, boxSize.Y / 2, (boxSize.Z / 2) + boxSize.Z * i); var box = TGCBox.fromSize(center, boxSize, texturaTipo1); box.AutoTransform = true; pared2.Add(box); aabbDelEscenario.Add(box.BoundingBox); } for (var i = 1; i < 4; i++) { var center = new TGCVector3((planeSize.X / 2) + boxSize2.X * i, boxSize2.Y / 2, 8000 /*(boxSize.Z / 2) + boxSize.Z * i*/); var box = TGCBox.fromSize(center, boxSize2, texturaTipo1); box.AutoTransform = true; pared1.Add(box); aabbDelEscenario.Add(box.BoundingBox); } //------------objetos estaticos---------------------------- //---------- var texturaCaja = TgcTexture.createTexture(D3DDevice.Instance.Device, GModel.MediaDir + "\\Texturas\\cajaMadera4.jpg"); var sizeCaja = new TGCVector3(50, 50, 50); caja1 = TGCBox.fromSize(new TGCVector3(35, sizeCaja.Y / 2, 150), sizeCaja, texturaCaja); caja1.AutoTransform = true; aabbDelEscenario.Add(caja1.BoundingBox); caja2 = TGCBox.fromSize(new TGCVector3(465, sizeCaja.Y / 2, 2300), sizeCaja, texturaCaja); caja2.AutoTransform = true; aabbDelEscenario.Add(caja2.BoundingBox); //------------objetos con matrices de movimiento---------------------------- var centro = new TGCVector3(0f, 0f, 0f); var tamanio = new TGCVector3(5f, 5f, 5f); //Caja con movimiento en Y caja3 = TGCBox.fromSize(centro, tamanio, texturaCaja); caja3.AutoTransform = false; plataformasDelEscenario.Add(caja3.BoundingBox); //Caja con movimiento en X caja4 = TGCBox.fromSize(centro, tamanio, texturaCaja); caja4.AutoTransform = false; plataformasDelEscenario.Add(caja4.BoundingBox); //Caja con movimiento circular sobre el eje Y caja5 = TGCBox.fromSize(centro, tamanio, texturaCaja); caja5.AutoTransform = false; plataformasDelEscenario.Add(caja5.BoundingBox); //---------------------Otros objetos var loader = new TgcSceneLoader(); var sceneBarril = loader.loadSceneFromFile(GModel.MediaDir + "\\MeshCreator\\Meshes\\Objetos\\BarrilPolvora\\BarrilPolvora-TgcScene.xml"); barril1 = sceneBarril.Meshes[0]; barril1.AutoTransform = true; barril1.Position = new TGCVector3(100, 0, 300); aabbDelEscenario.Add(barril1.BoundingBox); var sceneCalabera = loader.loadSceneFromFile(GModel.MediaDir + "\\MeshCreator\\Meshes\\Esqueletos\\Calabera\\Calabera-TgcScene.xml"); var sceneEsqueleto = loader.loadSceneFromFile(GModel.MediaDir + "\\MeshCreator\\Meshes\\Esqueletos\\EsqueletoHumano\\Esqueleto-TgcScene.xml"); calabera = sceneCalabera.Meshes[0]; calabera.AutoTransform = true; calabera.Position = new TGCVector3(400, 0, 1000); aabbDelEscenario.Add(calabera.BoundingBox); esqueleto = sceneEsqueleto.Meshes[0]; esqueleto.AutoTransform = true; esqueleto.Position = new TGCVector3(25, 0, 1600); aabbDelEscenario.Add(esqueleto.BoundingBox); for (var i = 1; i < 8; i++) { var scenePilar = loader.loadSceneFromFile(GModel.MediaDir + "\\MeshCreator\\Meshes\\Cimientos\\PilarEgipcio\\PilarEgipcio-TgcScene.xml"); pilar = scenePilar.Meshes[0]; pilar.Position = new TGCVector3(35, 0, planeSize.Z * i); pilar.Scale = new TGCVector3(2f, 2f, 2f); pilar.AutoTransform = true; pilares.Add(pilar); aabbDelEscenario.Add(pilar.BoundingBox); } for (var i = 1; i < 8; i++) { var scenePilar = loader.loadSceneFromFile(GModel.MediaDir + "\\MeshCreator\\Meshes\\Cimientos\\PilarEgipcio\\PilarEgipcio-TgcScene.xml"); pilar = scenePilar.Meshes[0]; pilar.Position = new TGCVector3(465, 0, planeSize.Z * i); pilar.Scale = new TGCVector3(2f, 2f, 2f); pilar.AutoTransform = true; pilares.Add(pilar); aabbDelEscenario.Add(pilar.BoundingBox); } for (var i = 1; i < 7; i++) { var sceneMesaLuz = loader.loadSceneFromFile(GModel.MediaDir + "\\MeshCreator\\Meshes\\Muebles\\MesaDeLuz\\MesaDeLuz-TgcScene.xml"); mueble1 = sceneMesaLuz.Meshes[0]; if ((i % 2) == 0) { mueble1.Position = new TGCVector3(465, 0, 575 * i); mueble1.RotateY(FastMath.PI_HALF); } else { mueble1.Position = new TGCVector3(35, 0, 575 * i); mueble1.RotateY(-FastMath.PI_HALF); } mueble1.AutoTransform = true; muebles.Add(mueble1); aabbDelEscenario.Add(mueble1.BoundingBox); } var scenePilar2 = loader.loadSceneFromFile(GModel.MediaDir + "\\MeshCreator\\Meshes\\Cimientos\\PilarEgipcio\\PilarEgipcio-TgcScene.xml"); pilarCaido1 = scenePilar2.Meshes[0]; pilarCaido1.AutoTransform = false; aabbDelEscenario.Add(pilarCaido1.BoundingBox); pilarCaido1.Transform = TGCMatrix.RotationYawPitchRoll(0f, 0f, 1.5f) * TGCMatrix.Translation(120f, 10f, 1330f) * TGCMatrix.Scaling(3f, 1.2f, 1.2f); pilarCaido1.BoundingBox.transform(TGCMatrix.RotationYawPitchRoll(0f, 0f, 1.5f) * TGCMatrix.Translation(120f, 10f, 1330f) * TGCMatrix.Scaling(3f, 1.2f, 1.2f));//TGCMatrix.Scaling(6f, 0.5f, 1f)); //* TGCMatrix.RotationYawPitchRoll(0f, 0f, 1f)); var scenePilar3 = loader.loadSceneFromFile(GModel.MediaDir + "\\MeshCreator\\Meshes\\Cimientos\\PilarEgipcio\\PilarEgipcio-TgcScene.xml"); pilarCaido2 = scenePilar3.Meshes[0]; pilarCaido2.AutoTransform = false; aabbDelEscenario.Add(pilarCaido2.BoundingBox); pilarCaido2.Transform = TGCMatrix.RotationYawPitchRoll(0f, 0f, 1.5f) * TGCMatrix.Translation(120f, 10f, 2330f) * TGCMatrix.Scaling(3f, 1.2f, 1.2f); pilarCaido2.BoundingBox.transform(TGCMatrix.RotationYawPitchRoll(0f, 0f, 1.5f) * TGCMatrix.Translation(120f, 10f, 2330f) * TGCMatrix.Scaling(3f, 1.2f, 1.2f));//TGCMatrix.Scaling(6f, 0.5f, 1f)); //* TGCMatrix.RotationYawPitchRoll(0f, 0f, 1f)); //-------------------------------------------------- //---------plataformas var texturaPlataforma = TgcTexture.createTexture(D3DDevice.Instance.Device, GModel.MediaDir + "Texturas\\BM_DiffuseMap_pared.jpg"); var plataformaSize = new TGCVector3(100f, 20f, 100f); plaFija1 = TGCBox.fromSize(new TGCVector3(0, 0, 0), plataformaSize, texturaPlataforma); aabbDelEscenario.Add(plaFija1.BoundingBox); plaFija2 = TGCBox.fromSize(new TGCVector3(0, 0, 0), plataformaSize, texturaPlataforma); aabbDelEscenario.Add(plaFija2.BoundingBox); plaFija3 = TGCBox.fromSize(new TGCVector3(0, 0, 0), plataformaSize, texturaPlataforma); aabbDelEscenario.Add(plaFija3.BoundingBox); plaFija4 = TGCBox.fromSize(new TGCVector3(0, 0, 0), plataformaSize, texturaPlataforma); aabbDelEscenario.Add(plaFija4.BoundingBox); plaFija5 = TGCBox.fromSize(new TGCVector3(0, 0, 0), plataformaSize, texturaPlataforma); aabbDelEscenario.Add(plaFija5.BoundingBox); plaMovil1 = TGCBox.fromSize(new TGCVector3(0f, 0f, 0f), plataformaSize, texturaPlataforma); plaMovil1.AutoTransform = false; aabbDelEscenario.Add(plaMovil1.BoundingBox); //Matrices para el manejo de cajas escalaBaseParaCajas = TGCMatrix.Scaling(10f, 10f, 10f); var ajusteAlturaDelCentro = caja3.Size.Y / 2; posicionamientoCaja3 = TGCMatrix.Translation(20, ajusteAlturaDelCentro, 20); posicionamientoCaja4 = TGCMatrix.Translation(30, ajusteAlturaDelCentro, 30); pivoteCaja5 = TGCMatrix.Translation(30, ajusteAlturaDelCentro, 60); radioCaja5 = TGCMatrix.Translation(0, 0, 5); //Matrices para el manejo de plataformas posicionamientoPla1 = TGCMatrix.Translation(250, -10, 500 * 8 + 500 / 2); posicionamientoPla2 = TGCMatrix.Translation(150, -10, 500 * 16 + 500 / 2); posicionamientoPla3 = TGCMatrix.Translation(400, -10, 500 * 16 + 300); posicionamientoPla4 = TGCMatrix.Translation(650, -10, 500 * 16 + 500 / 2); posicionamientoPla5 = TGCMatrix.Translation(900, -10, 500 * 16 + 500 / 2); posPlaMovil1 = TGCMatrix.Translation(250, -10, 500 * 12 + plaMovil1.Size.Z / 2); //Asumo el orden en el que fueron agregadas desplazamientoCaja3 = new TGCVector3(0, 1, 0); desplazamientoCaja4 = new TGCVector3(1, 0, 0); desplazamientoCaja5 = new TGCVector3(0, 1, 0); //En principio pensamos en tener una lista de matricesDePlataformasDelEscenario pero //Al pasar las matrices no logramos lo esperado desplazamientosDePlataformasDelEscenario.Add(desplazamientoCaja3); //caja3 desplazamientosDePlataformasDelEscenario.Add(desplazamientoCaja4); //caja4 desplazamientosDePlataformasDelEscenario.Add(desplazamientoCaja5); //caja5 tiempoDeSubida = 5f; //Equivalente a 5 segundos? tiempoDeMovLateral = 10f; subir = true; //La caja empieza subiendo movLateral = true; rotacionTotal = 0f; //----------musica musicaFondo = new TgcMp3Player(); musicaFondo.FileName = GModel.MediaDir + "\\Sound\\LavTown.mp3"; musicaFondo.play(true); }
public override void init() { Device d3dDevice = GuiController.Instance.D3dDevice; time = new DateTime(); //GuiController.Instance.D3dDevice.RenderState.ReferenceAlpha =255; TgcTexture texe = TgcTexture.createTexture(d3dDevice, "mitex1", GuiController.Instance.AlumnoEjemplosMediaDir + "Grupo18\\granito00.jpg"); TgcTexture texe1 = TgcTexture.createTexture(d3dDevice, "mitex1", GuiController.Instance.AlumnoEjemplosMediaDir + "Grupo18\\nubes.jpg"); Vector3 cen = new Vector3(1, 1, 220); Vector3 boxSi = new Vector3(2000, 2000, 2000); cajaporon = BoundingBoxExtendida.fromSize(cen, boxSi, texe1); TgcSceneLoader loader = new TgcSceneLoader(); boxes = new List <BoundingBoxExtendida>(); int a = 0; Vector3 boxSize = new Vector3(25, 25, 25); //Genera la aleatoriedad this.generarAleatorio(); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { if (!((k == 1 || k == 2) && ((i > 0 && i < 3) && (j > 0 && j < 3)))) { TgcTexture texture = TgcTexture.createTexture(d3dDevice, "mitex" + i + j + k, GuiController.Instance.AlumnoEjemplosMediaDir + "Grupo18\\granito00.jpg"); Vector3 center = new Vector3((boxSize.X + boxSize.X / 2) * i, (boxSize.Y + boxSize.Y / 2) * j, (k * 35) + 220); BoundingBoxExtendida box1 = BoundingBoxExtendida.fromSize(center, boxSize, texture); box1.setName("imagen" + imagenes[a]); a++; boxes.Add(box1); } } } } //Iniciarlizar PickingRay pickingRay = new TgcPickingRay(); GuiController.Instance.RotCamera.CameraDistance = 250; GuiController.Instance.RotCamera.CameraCenter = new Vector3(56.25f, 56.25f, 272.2f); //Crear caja para marcar en que lugar hubo colision collisionPointMesh = TgcBox.fromSize(new Vector3(25, 25, 25), Color.Red); selected = false; //Crear caja para indicar ubicacion de la luz ligtBox = TgcBox.fromSize(new Vector3(10, 10, 10), Color.Yellow); aciertosText = new TgcText2d(); aciertosText.Text = "Aciertos:"; aciertosText.Position = new Point(340, 10); aciertosText.Color = Color.Red; aciertosText.changeFont(new System.Drawing.Font(FontFamily.GenericMonospace, 20, FontStyle.Bold)); fracazosText = new TgcText2d(); fracazosText.Text = "Fracasos:"; fracazosText.Position = new Point(340, 90); fracazosText.Color = Color.Red; fracazosText.changeFont(new System.Drawing.Font(FontFamily.GenericMonospace, 20, FontStyle.Bold)); puntuacionAciertosText = new TgcText2d(); puntuacionAciertosText.Text = "0"; puntuacionAciertosText.Position = new Point(340, 40); puntuacionAciertosText.Color = Color.Red; puntuacionAciertosText.changeFont(new System.Drawing.Font(FontFamily.GenericMonospace, 40, FontStyle.Bold)); puntuacionFracazosText = new TgcText2d(); puntuacionFracazosText.Text = "0"; puntuacionFracazosText.Position = new Point(340, 110); puntuacionFracazosText.Color = Color.Red; puntuacionFracazosText.changeFont(new System.Drawing.Font(FontFamily.GenericMonospace, 40, FontStyle.Bold)); finalText = new TgcText2d(); finalText.Text = "FIN DEL JUEGO"; finalText.Position = new Point(0, 30); finalText.Color = Color.Red; finalText.changeFont(new System.Drawing.Font(FontFamily.GenericMonospace, 70, FontStyle.Bold)); finalText1 = new TgcText2d(); finalText1.Position = new Point(0, 120); finalText1.Color = Color.Red; finalText1.changeFont(new System.Drawing.Font(FontFamily.GenericMonospace, 60, FontStyle.Bold)); tiempoTranscurrido = new TgcText2d(); tiempoTranscurrido.Position = new Point(0, 360); tiempoTranscurrido.Color = Color.Red; tiempoTranscurrido.changeFont(new System.Drawing.Font(FontFamily.GenericMonospace, 60, FontStyle.Bold)); this.loadMp3(GuiController.Instance.AlumnoEjemplosMediaDir + "Grupo18\\dalePlay.mp3"); TgcMp3Player player = GuiController.Instance.Mp3Player; TgcMp3Player.States currentState = player.getStatus(); player.play(true); GuiController.Instance.Modifiers.addButton("Reload", "Reload", new EventHandler(Reload_ButtonClick)); //Crear Sprite animado animatedSprite = new MySprite( GuiController.Instance.AlumnoEjemplosMediaDir + "Grupo18\\prueba2.png", //Textura de 256x256 new Size(128, 128), //Tamaño de un frame (64x64px en este caso) 16, //Cantidad de frames, (son 16 de 64x64px) 6 //Velocidad de animacion, en cuadros x segundo ); //Ubicarlo centrado en la pantalla Size screenSize = GuiController.Instance.Panel3d.Size; Size textureSize = animatedSprite.Sprite.Texture.Size; animatedSprite.Scaling = new Vector2(4f, 4f); animatedSprite.Position = new Vector2(screenSize.Width / 2 - textureSize.Width / 2, screenSize.Height / 2 - textureSize.Height / 2); animatedSprite.positionBkp = animatedSprite.Position; //Crear Sprite animado animatedSpriteTriste = new MySprite( GuiController.Instance.AlumnoEjemplosMediaDir + "Grupo18\\caritaTiste.png", //Textura de 256x256 new Size(128, 128), //Tamaño de un frame (64x64px en este caso) 16, //Cantidad de frames, (son 16 de 64x64px) 6 //Velocidad de animacion, en cuadros x segundo ); animatedSpriteTriste.Scaling = new Vector2(2f, 2f); animatedSpriteTriste.Position = new Vector2(8, 5); animatedSpriteTriste.positionBkp = animatedSpriteTriste.Position; }
public static void stop(TgcMp3Player music) { music?.stop(); music?.closeFile(); }
// <param name="elapsedTime">Tiempo en segundos transcurridos desde el último frame</param> public override void render(float elapsedTime) { Device d3dDevice = GuiController.Instance.D3dDevice; axisRotation += AXIS_ROTATION_SPEED * elapsedTime; float camaraY = (float)GuiController.Instance.Modifiers["camaraY"]; float camaraZ = (float)GuiController.Instance.Modifiers["camaraZ"]; camaraTerceraPersona.CambiarCamara(camaraY, camaraZ); //Obtener valor de UserVar (hay que castear) int valor = (int)GuiController.Instance.UserVars.getValue("variablePrueba"); #region //Radio de la nave string filePath = (string)GuiController.Instance.Modifiers["MP3-File"]; LoadMp3(filePath); TgcMp3Player player = GuiController.Instance.Mp3Player; TgcMp3Player.States currentState = player.getStatus(); if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.Y)) { if (currentState == TgcMp3Player.States.Open) { //Reproducir MP3 player.play(true); } if (currentState == TgcMp3Player.States.Stopped) { //Parar y reproducir MP3 player.closeFile(); player.play(true); } } else if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.O)) { if (currentState == TgcMp3Player.States.Playing) { //Parar el MP3 player.stop(); } } #endregion //Cargamos el Render Targer al cual se va a dibujar la escena 3D. Antes nos guardamos el surface original //En vez de dibujar a la pantalla, dibujamos a un buffer auxiliar, nuestro Render Target. pOldRT = d3dDevice.GetRenderTarget(0); Surface pSurf = renderTarget2D.GetSurfaceLevel(0); d3dDevice.SetRenderTarget(0, pSurf); d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); //Dibujamos la escena comun, pero en vez de a la pantalla al Render Target drawSceneToRenderTarget(d3dDevice, elapsedTime); //Liberar memoria de surface de Render Target pSurf.Dispose(); //Si quisieramos ver que se dibujo, podemos guardar el resultado a una textura en un archivo para debugear su resultado (ojo, es lento) //TextureLoader.Save(GuiController.Instance.ExamplesMediaDir + "Shaders\\render_target.bmp", ImageFileFormat.Bmp, renderTarget2D); //Ahora volvemos a restaurar el Render Target original (osea dibujar a la pantalla) d3dDevice.SetRenderTarget(0, pOldRT); //Luego tomamos lo dibujado antes y lo combinamos con una textura con efecto de alarma drawPostProcess(d3dDevice); nave.Renderizar(elapsedTime, obstaculos); NaveEnemiga1.MoverHaciaObjetivo(elapsedTime, nave.Modelo.Position); NaveEnemiga1.Renderizar(elapsedTime, obstaculos); #region Detectar Colisiones ColisionNave(elapsedTime); ColisionDisparos(elapsedTime); #endregion sol.BoundingBox.transform(sol.Transform); sol.Transform = TransformarSol(elapsedTime); GuiController.Instance.ThirdPersonCamera.Target = nave.Modelo.Position; //Limpiamos todas las transformaciones con la Matrix identidad sol.render(); d3dDevice.Transform.World = Matrix.Identity; Universo.renderAll(); }
private void Player() { TgcMp3Player player = new TgcMp3Player(); //if ((bool)GuiController.Instance.Modifiers["Musica"]) { if (player.getStatus() == TgcMp3Player.States.Open) { //Reproducir MP3 //FIXME //player.play(true); } if (player.getStatus() == TgcMp3Player.States.Stopped) { //Parar y reproducir MP3 player.closeFile(); player.play(true); } } /*else { if (player.getStatus() == TgcMp3Player.States.Playing) { //Parar el MP3 player.stop(); } }*/ }