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 @@ -55,6 +55,8 @@ Vector2 mouseGrid; Vector2 original_point; + Vector2 mousePos; + private static void Main(string[] args) @@ -159,19 +161,31 @@ Vector2 calculateMousegrid(Vector2 normalizedMousePos) { - int gridx = (int)((normalizedMousePos.X ) / Tile.TileWidth); - int gridy = (int)((normalizedMousePos.Y + (2*baseOffsetY)) / (Tile.TileStepY)); + + //int gridx = (int)(normalizedMousePos.X / Tile.TileSpriteWidth); + //int gridy = (int)(normalizedMousePos.Y / Tile.TileSpriteHeight); + Vector2 adjust = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); + Vector2 adjustedMousePos = normalizedMousePos - adjust; + + float boardx = ((adjustedMousePos.X/ Tile.TileSpriteWidth) + (adjustedMousePos.Y / Tile.TileSpriteHeight)); + float boardy = ((adjustedMousePos.Y / Tile.TileSpriteHeight) - (adjustedMousePos.X / Tile.TileSpriteWidth)); + + + return new Vector2(boardx, boardy); + /* + int gridx = (int)((normalizedMousePos.X + (this.baseOffsetX + 4)) / Tile.TileWidth) ; + int gridy = (int)((normalizedMousePos.Y + (this.baseOffsetX + 4) + (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 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); + return new Vector2(gridx, gridy); if (middle_distance < (Tile.TileWidth / 2)) { return new Vector2(gridx, gridy); @@ -200,6 +214,9 @@ else { return new Vector2(gridx, gridy); } + */ + + } @@ -287,6 +304,7 @@ this.camera.Move(new Vector2(0, 4)); } + this.original_point = Vector2.Transform(new Vector2(mouseCur.X, mouseCur.Y), Matrix.Invert(camera.get_transformation(GraphicsDevice))); @@ -317,6 +335,7 @@ protected void drawTileAt(int x, int y, int tileIndex, int height) { + /* Vector2 firstSquare = Vector2.Zero; Vector2 squareOffset = Vector2.Zero; @@ -347,6 +366,27 @@ Vector2.Zero, SpriteEffects.None, depthOffset); + */ + + + int screenx = (x - y) * Tile.TileSpriteWidth / 2; + int screeny = (x + y) * Tile.TileSpriteHeight / 2; + float maxdepth = ((this.squaresAcross + 1) + ((this.squaresDown + 1) * Tile.TileWidth)) * 10; + + float depthOffset = 0.7f - ((0 + (0 * Tile.TileWidth)) / maxdepth); + + batch.Draw( + Tile.TileSetTexture, + new Rectangle( + screenx, + screeny, + Tile.TileWidth, Tile.TileHeight * height), + Tile.GetExtendedSourceRectangle(tileIndex, height), + Color.White, + 0.0f, + Vector2.Zero, + SpriteEffects.None, + depthOffset); } protected override void Draw(GameTime gameTime) @@ -371,6 +411,7 @@ camera.get_transformation(GraphicsDevice)); //New tile stuff + /* Vector2 firstSquare = Vector2.Zero; int firstX = (int)firstSquare.X; int firstY = (int)firstSquare.Y; @@ -380,6 +421,7 @@ int offsetX = (int)squareOffset.X; int offsetY = (int)squareOffset.Y; + for (int y = 0; y < this.squaresDown; y++) { int rowOffset = 0; @@ -404,23 +446,76 @@ } - } - + }*/ + + + for (int y = 0; y < this.squaresDown; y++) + { + + for (int x = 0; x < this.squaresAcross; x++) + { + + int screenx = (x - y) * Tile.TileSpriteWidth/2; + + int screeny = (x + y) * Tile.TileSpriteHeight / 2; + + batch.Draw( + Tile.TileSetTexture, + new Rectangle( + screenx, + screeny, + Tile.TileWidth, Tile.TileHeight), + Tile.GetSourceRectangle(1), + Color.White, + 0.0f, + Vector2.Zero, + SpriteEffects.None, + 0.9f); + } + + } + + for (int y = 0; y < this.squaresDown; y++) + { + + Vector2 adjust = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); //TODO figure out why this second value shouldn't be halved + + Line.drawLine(batch, + new Vector2(((0-y) * Tile.TileSpriteWidth/2), (0+y)*Tile.TileSpriteHeight/2) + adjust, + //new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight), + new Vector2((this.squaresAcross - (y)) * Tile.TileSpriteWidth / 2, (this.squaresAcross + (y )) * Tile.TileSpriteHeight / 2) + adjust, + Color.White, 0.8f); + + } + + for (int x = 0; x < this.squaresAcross; x++) + { + + Vector2 adjust = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); //TODO figure out why this second value shouldn't be halved + + Line.drawLine(batch, + new Vector2(((x - 0) * Tile.TileSpriteWidth / 2), (x + 0) * Tile.TileSpriteHeight / 2) + adjust, + //new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight), + new Vector2((x - this.squaresDown) * Tile.TileSpriteWidth / 2, (x + this.squaresDown) * Tile.TileSpriteHeight / 2) + adjust, + Color.White, 0.8f); + + } //Gridlines //Lines going down and to the right: - for (int x = (int)(-this.squaresAcross/2); x < this.squaresAcross; x++) + /* + for (int x = (int)(-this.squaresAcross/2); x < this.squaresAcross; x++) { int rowOffset = 0; - + float startX = (x * Tile.TileStepX) + baseOffsetX - (Tile.TileStepX / 2); Vector2 start = new Vector2(startX, -baseOffsetY+4); Vector2 stop = new Vector2(startX + this.squaresAcross* Tile.TileStepX/2, this.squaresDown*Tile.TileStepY- baseOffsetY+4); - + Line.drawLine(batch, Line.departurePoint(stop, start, this.squaresAcross * Tile.TileWidth, this.squaresDown * Tile.TileHeight), @@ -431,7 +526,7 @@ //Lines going down and to the left: for (int x = 0; x < (int)(1.5*this.squaresAcross); x++) { - + float startX = (x * Tile.TileStepX) + baseOffsetX - (Tile.TileStepX / 2); Vector2 start_reverse = new Vector2(startX, -baseOffsetY + 4); @@ -444,12 +539,13 @@ Color.White, 0.8f); } + */ drawTileAt(4, 4, 140, 3); drawTileAt(6, 4, 141, 3); drawTileAt(8, 4, 142, 2); drawTileAt(10, 4, 142, 3); - drawTileAt(0, 0, 22, 1); + //drawTileAt(0, 0, 22, 1); drawTileAt((int)this.mouseGrid.X, (int)this.mouseGrid.Y, 2, 1); @@ -485,7 +581,7 @@ if (this.map.cells[i][j].hasTree) { - //drawTileAt(i, j, 142, 2); + drawTileAt(i, j, 142, 2); } @@ -517,10 +613,10 @@ 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); - */ + + batch.DrawString(font, this.original_point.ToString(), new Vector2(460, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); + batch.DrawString(font, this.original_point.ToString(), new Vector2(459, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f); + //*/ //Matrix.Multiply() batch.End(); diff --git a/isometric-park-fna/Tile.cs b/isometric-park-fna/Tile.cs --- a/isometric-park-fna/Tile.cs +++ b/isometric-park-fna/Tile.cs @@ -15,6 +15,9 @@ static public int OddRowXOffset = 32; static public int HeightTileOffset = 32; + static public int TileSpriteWidth = 64; + static public int TileSpriteHeight = 32; + static public Texture2D TileSetTexture; public Tile()