diff --git a/isometric-park-fna/FNAGame.cs b/isometric-park-fna/FNAGame.cs --- a/isometric-park-fna/FNAGame.cs +++ b/isometric-park-fna/FNAGame.cs @@ -9,7 +9,7 @@ using SpriteFontPlus; using isometricparkfna; using System.Diagnostics; - +using System.Collections.Generic; class FNAGame : Game { @@ -45,13 +45,15 @@ //new tile stuff TileMap myMap = new TileMap(); - int squaresAcross = 25; - int squaresDown = 25; + int squaresAcross = 50; + int squaresDown = 50; int baseOffsetX = -14; int baseOffsetY = -14; GraphicsDevice device; + TileMap map; + private static void Main(string[] args) { @@ -78,6 +80,21 @@ //gdm.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = false; + this.map = new TileMap(this.squaresAcross, this.squaresDown); + + foreach (List row in this.map.cells) + { + foreach (Cell cell in row) + { + if (this.random_generator.NextDouble() > 0.75) + { + cell.hasTree = true; + } + + + } + } + Content.RootDirectory = "Content"; @@ -262,7 +279,7 @@ Tile.TileSetTexture, new Rectangle( (x * Tile.TileStepX) - offsetX + rowOffset + baseOffsetX, - (y * Tile.TileStepY) - offsetY + baseOffsetY, + (y * Tile.TileStepY) - offsetY + baseOffsetY-(Tile.TileHeight*(height-1)), Tile.TileWidth, Tile.TileHeight*height), Tile.GetExtendedSourceRectangle(tileIndex, height), Color.White, @@ -315,9 +332,9 @@ batch.Draw( Tile.TileSetTexture, new Rectangle( - (4*((x * Tile.TileStepX)) - offsetX + 4*rowOffset + 4*baseOffsetX), - (4*((y * Tile.TileStepY)) - offsetY + 4*baseOffsetY), - 4 * Tile.TileWidth, 4 * Tile.TileHeight), + ((x * Tile.TileStepX) - offsetX + rowOffset + baseOffsetX), + ((y * Tile.TileStepY) - offsetY + baseOffsetY), + Tile.TileWidth, Tile.TileHeight), Tile.GetSourceRectangle(1), Color.White, 0.0f, @@ -395,6 +412,22 @@ }//*/ + for (int i = 0; i < this.map.MapHeight; i++) + { + for (int j = 0; j < this.map.MapWidth; j += 1) + { + //Warning: creates a flashing effect because tree positions update every 1/60th of a second + + if (this.map.cells[i][j].hasTree) + { + drawTileAt(i, j, 142, 2); + } + + + } + } + + batch.End(); batch.Begin(SpriteSortMode.BackToFront, @@ -412,6 +445,9 @@ batch.DrawString(font, camera.position.ToString(), new Vector2(190, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); batch.DrawString(font, camera.position.ToString(), new Vector2(189, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f); + batch.DrawString(font, this.map.trees.ToString(), new Vector2(330, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); + batch.DrawString(font, this.map.trees.ToString(), new Vector2(329, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f); + batch.End(); diff --git a/isometric-park-fna/TileMap.cs b/isometric-park-fna/TileMap.cs --- a/isometric-park-fna/TileMap.cs +++ b/isometric-park-fna/TileMap.cs @@ -11,13 +11,59 @@ public class TileMap { - //public List> Tiles; + public List> cells; public int MapWidth = 50; public int MapHeight = 50; + public int trees + { + get + { + int count = 0; + foreach (List row in cells) + { + foreach (Cell cell in row) + { + if (cell.hasTree) + { + count++; + } + } + } + return count; + } + } + public TileMap() { + //TileMap(MapWidth, MapHeight); + } + + public TileMap(int width, int height) + { + this.MapWidth = width; + this.MapHeight = height; + + this.cells = new List>(); + + for (int i = 0; i < height; i++) + { + List newRow = new List(); + for (int j = 0; j < width; j++) + { + newRow.Add(new Cell()); + } + + this.cells.Add(newRow); + } } + + + } + + public class Cell + { + public Boolean hasTree = false; } }