using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; using OrpheusDemons.FrameWork; using OrpheusDemons.FrameWork.Animaciones; using OrpheusDemons.FrameWork.Monstruos; namespace OrpheusDemons { /// /// This is the main type for your game /// public class OrpheusGame : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; AdministracionTeclado teclado; int TiempoLimite; int elapsedTime; // Score de Orfeo int score; public TileMap escenario { get; set; } Orfeo orfeo; public OrpheusDemonsFactory factory { get; set; } AdministradorAparicion spawnManager; public LectorAnimacion lectorAnimacion { get; set; } public Boolean pausa { get; set; } public Song musicaFondo { get; set; } public SpriteFont fuente { get; set; } public OrpheusGame() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } /// /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// protected override void Initialize() { Texture2D fondo = Content.Load("backgrounds/bg_level2"); //Texture2D fondo = Content.Load("backgrounds/cathedralboss"); lectorAnimacion = new LectorAnimacion(); teclado = AdministracionTeclado.TecladoGlobal; if (lectorAnimacion.ArchivoAnimacionesExiste()) { lectorAnimacion.CargarAnimaciones(); } factory = new OrpheusDemonsFactory(this, lectorAnimacion); escenario = new TileMap(this, "Content/mapa2.csv"); //Asigna el spriteFactory al TileMap escenario.spriteFactory = factory; escenario.HorizontalScrolling = TileMap.Scrolling.Sprite; escenario.VerticalScrolling = TileMap.Scrolling.Sprite; //Establecer un fondo al escenario escenario.ParallaxBackground = fondo; //Configurar el fondo del escenario escenario.ParallaxBackgroundHorizontalScrolling = TileMap.ParallaxBackgroundScrolling.Normal; escenario.ParallaxBackgroundVerticalScrolling = TileMap.ParallaxBackgroundScrolling.Normal; orfeo = new Orfeo(this, lectorAnimacion); escenario.spriteScrolling = orfeo; escenario.spriteScrolling.x = TileMap.tilesAPixels(10); escenario.spriteScrolling.y = TileMap.tilesAPixels(10); escenario.sprites.Add(orfeo); escenario.regenerarMapa(); TiempoLimite = 60; elapsedTime = 0; spawnManager = new AdministradorAparicion(this); score = 0; //Musica de fondo musicaFondo = Content.Load("sounds/RE2 OST 1"); if (musicaFondo != null) { try { // Play the music MediaPlayer.Play(musicaFondo); // Loop the currently playing song MediaPlayer.IsRepeating = true; // Cambio de Volumen MediaPlayer.Volume = 0.6f; } catch { } } base.Initialize(); } /// /// LoadContent will be called once per game and is the place to load /// all of your content. /// protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); fuente = Content.Load("gameFont"); } /// /// UnloadContent will be called once per game and is the place to unload /// all content. /// protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } /// /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// /// Provides a snapshot of timing values. protected override void Update(GameTime gameTime) { // Allows the game to exit if (teclado.PresionadoUnaVez(Keys.Escape)) this.Exit(); elapsedTime += gameTime.ElapsedGameTime.Milliseconds; if (elapsedTime >= 1000) { elapsedTime = 0; TiempoLimite--; } teclado.actualizar(gameTime); if (teclado.PresionadoUnaVez(Keys.P)) { pausa = !pausa; } if (!pausa) { escenario.actualizar(gameTime.ElapsedGameTime.Milliseconds); } spawnManager.Actualizar(gameTime); base.Update(gameTime); } /// /// This is called when the game should draw itself. /// /// Provides a snapshot of timing values. protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); escenario.dibujar(spriteBatch, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); spriteBatch.DrawString(fuente, "Tiempo Restante: " + TiempoLimite, new Vector2(10, 10), Color.White); spriteBatch.DrawString(fuente, "Vidas: " + orfeo.Vida, new Vector2(10, 50), Color.White); spriteBatch.End(); base.Draw(gameTime); } } }