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 @@ -315,9 +315,9 @@ batch.Draw( Tile.TileSetTexture, new Rectangle( - ((x * Tile.TileStepX) - offsetX + rowOffset + baseOffsetX), - ((y * Tile.TileStepY) - offsetY + baseOffsetY), - Tile.TileWidth, Tile.TileHeight), + (4*((x * Tile.TileStepX)) - offsetX + 4*rowOffset + 4*baseOffsetX), + (4*((y * Tile.TileStepY)) - offsetY + 4*baseOffsetY), + 4 * Tile.TileWidth, 4 * Tile.TileHeight), Tile.GetSourceRectangle(1), Color.White, 0.0f, @@ -331,7 +331,7 @@ //Gridlines //Lines going down and to the right: - for (int x = (-this.squaresAcross); x < this.squaresAcross; x++) + for (int x = (int)(-this.squaresAcross/2); x < this.squaresAcross; x++) { int rowOffset = 0; @@ -341,11 +341,16 @@ Vector2 stop = new Vector2(startX + this.squaresAcross* Tile.TileStepX/2, this.squaresDown*Tile.TileStepY- baseOffsetY+4); - Line.drawLine(batch, start, stop, Color.White, 0.8f); + + + Line.drawLine(batch, + Line.departurePoint(stop, start, this.squaresAcross * Tile.TileWidth, this.squaresDown * Tile.TileHeight), + Line.departurePoint(start, stop, this.squaresAcross * Tile.TileWidth, this.squaresDown * Tile.TileHeight), + Color.White, 0.8f); } //Lines going down and to the left: - for (int x = 0; x < (2*this.squaresAcross); x++) + for (int x = 0; x < (int)(1.5*this.squaresAcross); x++) { float startX = (x * Tile.TileStepX) + baseOffsetX - (Tile.TileStepX / 2); @@ -354,7 +359,10 @@ Vector2 stop_reverse = new Vector2(startX + -(this.squaresAcross * Tile.TileStepX / 2), (this.squaresDown * Tile.TileStepY) - baseOffsetY + 4); - Line.drawLine(batch, start_reverse, stop_reverse, Color.White, 0.8f); + Line.drawLine(batch, + Line.departurePoint(stop_reverse, start_reverse, this.squaresAcross * Tile.TileWidth, this.squaresDown * Tile.TileHeight), + Line.departurePoint(start_reverse, stop_reverse, this.squaresAcross * Tile.TileWidth, this.squaresDown * Tile.TileHeight), + Color.White, 0.8f); } @@ -365,21 +373,18 @@ drawTileAt(0, 0, 22, 1); - //* - + /* - for (int i = 0; i< 80; i++) { for (int j = 0; j < 50; j += 1) { //Warning: creates a flashing effect because tree positions update every 1/60th of a second - /* if (this.random_generator.NextDouble() > 0.75) { drawTileAt(i, j, 142, 2); - }//*/ + } if ((i + j) % 3 == 0) { diff --git a/isometric-park-fna/Line.cs b/isometric-park-fna/Line.cs --- a/isometric-park-fna/Line.cs +++ b/isometric-park-fna/Line.cs @@ -40,6 +40,43 @@ Line.PixelTexture.SetData (new Color[] { Color.White}); } + + public static Vector2 departurePoint(Vector2 start, Vector2 stop, float width, float height) + { + if (MathUtils.Between(stop.X, 0, width ) && MathUtils.Between(stop.Y, 0, height)) { + return stop; + } + + float slope = (start.Y - stop.Y) / (start.X - stop.X); + + float intercept = (start.Y - (slope * start.X)); + + if (stop.X < 0) { + float newY = slope * 0 + intercept; + return new Vector2(0, newY); + } + else if (stop.Y < 0) + { + float newX = intercept / slope; + return new Vector2(newX, 0); + + } + + else if (stop.Y > height) + { + float newX = (intercept + height) / slope; + return new Vector2(newX, height); + } + else if (stop.X > width) + { + float newY = slope * width + intercept; + return new Vector2(width, newY); + } + + return stop;//TODO + + + } }