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 @@ -44,7 +44,6 @@ private int aiScore = 0; //new tile stuff - TileMap myMap = new TileMap(); int squaresAcross = 50; int squaresDown = 50; int baseOffsetX = -14; @@ -54,6 +53,9 @@ TileMap map; + Vector2 mouseGrid; + Vector2 original_point; + private static void Main(string[] args) { @@ -155,6 +157,52 @@ music.Dispose(); } + Vector2 calculateMousegrid(Vector2 normalizedMousePos) + { + int gridx = (int)((normalizedMousePos.X ) / Tile.TileWidth); + int gridy = (int)((normalizedMousePos.Y + (2*baseOffsetY)) / (Tile.TileStepY)); + + + + + int within_gridx = (int)(normalizedMousePos.X % Tile.TileWidth) - (Tile.TileWidth/2); + int within_gridy = (int)(normalizedMousePos.Y % Tile.TileHeight) - (Tile.TileHeight / 2); + + int middle_distance = Math.Abs(within_gridx) + Math.Abs(within_gridx); + Vector2 adjustment_vector; + + //return new Vector2(gridx, gridy); + if (middle_distance < (Tile.TileWidth / 2)) + { + return new Vector2(gridx, gridy); + } + + else if ((Math.Sign(within_gridx) == -1) && (Math.Sign(within_gridy) == 1)) + { + adjustment_vector = new Vector2(-1, -1); + return new Vector2(gridx, gridy) + adjustment_vector; + } + else if ((Math.Sign(within_gridx) == -1) && (Math.Sign(within_gridy) == -1)) + { + adjustment_vector = new Vector2(-1, 1); + return new Vector2(gridx, gridy) + adjustment_vector; + } + else if ((Math.Sign(within_gridx) == 1) && (Math.Sign(within_gridy) == 1)) + { + adjustment_vector = new Vector2(0, -1); + return new Vector2(gridx, gridy) + adjustment_vector; + } + else if ((Math.Sign(within_gridx) == 1) && (Math.Sign(within_gridy) == -1)) + { + adjustment_vector = new Vector2(0, 1); + return new Vector2(gridx, gridy) + adjustment_vector; + } + else { + return new Vector2(gridx, gridy); + } + + } + protected override void Update(GameTime gameTime) @@ -239,6 +287,18 @@ this.camera.Move(new Vector2(0, 4)); } + + + this.original_point = Vector2.Transform(new Vector2(mouseCur.X, mouseCur.Y), Matrix.Invert(camera.get_transformation(GraphicsDevice))); + + //int gridx = (int)((this.original_point.X-baseOffsetX) / Tile.TileStepX); + /* int gridx = (int)(this.original_point.Y / Tile.TileHeight + this.original_point.X / Tile.TileWidth); */ + //int gridy = (int)((this.original_point.Y-baseOffsetY) / (Tile.TileStepY*2)); + /* int gridy = (int)(this.original_point.Y / Tile.TileHeight - this.original_point.X / Tile.TileWidth); */ + + //this.mouseGrid = new Vector2(gridx, gridy); + this.mouseGrid = this.calculateMousegrid(this.original_point); + elapsedTime += gameTime.ElapsedGameTime; if (elapsedTime > TimeSpan.FromSeconds(1)) @@ -341,6 +401,8 @@ Vector2.Zero, SpriteEffects.None, 0.9f); + + } } @@ -390,6 +452,9 @@ drawTileAt(0, 0, 22, 1); + drawTileAt((int)this.mouseGrid.X, (int)this.mouseGrid.Y, 2, 1); + + /* for (int i = 0; i< 80; i++) @@ -420,7 +485,7 @@ if (this.map.cells[i][j].hasTree) { - drawTileAt(i, j, 142, 2); + //drawTileAt(i, j, 142, 2); } @@ -448,6 +513,15 @@ batch.DrawString(font, this.map.tree_count.ToString(), new Vector2(330, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); batch.DrawString(font, this.map.tree_count.ToString(), new Vector2(329, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f); + + + batch.DrawString(font, this.mouseGrid.ToString(), new Vector2(360, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); + batch.DrawString(font, this.mouseGrid.ToString(), new Vector2(359, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f); + /* + batch.DrawString(font, this.original_point.ToString(), new Vector2(360, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); + batch.DrawString(font, this.original_point.ToString(), new Vector2(359, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f); + */ + //Matrix.Multiply() batch.End(); @@ -458,4 +532,4 @@ } -} \ No newline at end of file +} 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 @@ -15,6 +15,9 @@ public int MapWidth = 50; public int MapHeight = 50; + public int ZoneWidth = 10; + public int ZoneHeight = 10; + public int tree_count { get @@ -67,6 +70,20 @@ } } + public System.Collections.IEnumerable tree_cells(int zone) + { + foreach (List row in cells) + { + foreach (Cell cell in row) + { + if (cell.hasTree) + { + yield return cell; + } + } + } + } + public System.Collections.IEnumerable iterate_cells() { foreach (List row in cells)