/// <summary> /// Draws the visibility of a tile /// </summary> /// <param name="spriteBatch">Sprite batch being used to draw</param> /// <param name="tileTexture">Sprite sheet for tiles</param> /// <param name="destination">Where to draw tile</param> /// <param name="tiles">What tile to draw</param> public void DrawTileVisibility(SpriteBatch spriteBatch, Texture2D tileTexture, Vector2 destination, TileDictionary tiles) { if (!this._visible && this._seen) { Rectangle visRect = new Rectangle((int)tiles.GetTile("mesh").X * 32, (int)tiles.GetTile("mesh").Y * 32, tileTexture.Width / 30, tileTexture.Height / 32); spriteBatch.Draw(tileTexture, destination, visRect, Color.White); } else if (!this._visible) { Rectangle visRect = new Rectangle((int)tiles.GetTile("dngn_unseen").X * 32, (int)tiles.GetTile("dngn_unseen").Y * 32, tileTexture.Width / 30, tileTexture.Height / 32); spriteBatch.Draw(tileTexture, destination, visRect, Color.White); } }
public void DrawViewport(SpriteBatch spriteBatch, Dungeon dungeon, Player player, Texture2D tileTexture, TileDictionary tileDictionary) { if (player.location.X < 13) { minXPos = 0; maxXPos = 24; } else if (player.location.X > 37) { //viewport draws map.x of 25 to map.x length - 1 minXPos = 25; maxXPos = dungeon.grid.GetLength(0) - 1; } else { //viewport draws map.x of p - 12 to map.x of p + 12 minXPos = (int)player.location.X - 12; maxXPos = (int)player.location.X + 12; } if (player.location.Y < 13) { minYPos = 0; maxYPos = 24; } else if (player.location.Y > 37) { //viewport draws map.y of 25 to map.y length - 1 minYPos = 25; maxYPos = dungeon.grid.GetLength(1) - 1; } else { //viewport draws map.y of p - 12 to map.y of p + 12 minYPos = (int)player.location.Y - 12; maxYPos = (int)player.location.Y + 12; } for (int x = minXPos; x <= maxXPos; x++) { for (int y = minYPos; y <= maxYPos; y++) { viewGrid[gridCounterX, gridCounterY] = dungeon.grid[x, y]; dungeon.grid[x, y].DrawTile(spriteBatch, tileTexture, new Vector2(gridCounterX * 32, gridCounterY * 32), tileDictionary); if (dungeon.grid[x, y].npc != null) { dungeon.grid[x, y].npc.DrawNPC(spriteBatch, tileTexture); } dungeon.grid[x, y].DrawTileVisibility(spriteBatch, tileTexture, new Vector2(gridCounterX * 32, gridCounterY * 32), tileDictionary); gridCounterY++; } gridCounterX++; gridCounterY = 0; } gridCounterX = 0; minXPos = 0; minYPos = 0; maxXPos = 24; maxYPos = 24; }
/// <summary> /// Draws tile /// </summary> /// <param name="spriteBatch">Sprite batch being used to draw</param> /// <param name="tileTexture">Sprite sheet for tiles</param> /// <param name="destination">Where to draw it on screen</param> /// <param name="tiles">What tile to draw</param> public void DrawTile(SpriteBatch spriteBatch, Texture2D tileTexture, Vector2 destination, TileDictionary tiles) { Rectangle tileRect = new Rectangle((int)tiles.GetTile(_tileName).X * 32, (int)tiles.GetTile(_tileName).Y * 32, tileTexture.Width / 30, tileTexture.Height / 32); spriteBatch.Draw(tileTexture, destination, tileRect, Color.White); foreach (String entity in _entities) { Rectangle entityRect = new Rectangle((int)tiles.GetTile(entity).X * 32, (int)tiles.GetTile(entity).Y * 32, tileTexture.Width / 30, tileTexture.Height / 32); spriteBatch.Draw(tileTexture, destination, entityRect, Color.White); } }