private void levelRead(string levelName, ContentManager content) { string line; int countY = 0; // Read the file and display it line by line. System.IO.StreamReader file = new System.IO.StreamReader(@"C:\Users\Nerviosillo\lvl.txt"); while ((line = file.ReadLine()) != null) { int countX = 0; foreach (char i in line) { if (i == '0') { Tile0 air = new Tile0(content.Load <Texture2D>(@"images\void"), new Vector2(countX, countY), new Point(75, 75), 0, new Vector2(0, 0)); _tileList.Add(air); } if (i == '1') { Tile1 block = new Tile1(content.Load <Texture2D>(@"images\block"), new Vector2(countX, countY), new Point(75, 75), 0, new Vector2(0, 0)); _tileList.Add(block); } if (i == '2') { Tile2 fire = new Tile2(content.Load <Texture2D>(@"images\fire"), new Vector2(countX, countY), new Point(75, 75), 0, new Vector2(0, 0)); _tileList.Add(fire); } if (i == 'I') { Tile0 air = new Tile0(content.Load <Texture2D>(@"images\void"), new Vector2(countX, countY), new Point(75, 75), 0, new Vector2(0, 0)); _tileList.Add(air); MainCharacter dragon = new MainCharacter(content.Load <Texture2D>(@"images\dragon2"), new Vector2(countX, countY), new Point(75, 75)); _individualList.Add(dragon); } countX = countX + 75; } countY = countY + 75; } _xTiles = 21; _yTiles = 15; file.Close(); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Transparent); MainCharacter MC = null; spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, cam.get_transformation(GraphicsDevice)); foreach (Tile t in actualLevel._tileList) { t.Draw(gameTime, spriteBatch); } foreach (Individual i in actualLevel._individualList) { if (i.isMC) { MC = (MainCharacter)i; } i.Draw(gameTime, spriteBatch, Content); } // TODO: Add your drawing code here Vector2 fontPosLeft1 = new Vector2(cam.Pos.X - GraphicsDevice.Viewport.Width / 2 + 50, cam.Pos.Y - GraphicsDevice.Viewport.Height / 2 + 50); Vector2 fontPosRight1 = new Vector2(cam.Pos.X + GraphicsDevice.Viewport.Width / 4, cam.Pos.Y - GraphicsDevice.Viewport.Height / 2 + 50); spriteBatch.DrawString(hudFont, "Vida: " + Math.Round(MC.HealthPoints, 0).ToString(), fontPosLeft1, Color.White); spriteBatch.DrawString(hudFont, "Vidas: " + MC.Lifes.ToString(), fontPosRight1, Color.White); base.Draw(gameTime); spriteBatch.End(); }