# HG changeset patch # User alys # Date 2020-12-08 06:47:57 # Node ID 9ebc00f85ae37406b8b6391221ea1c4a21ac731f # Parent 3169ee75a7e3c590df7b9ab557f74ee3f17ffecd Add rudimentary tree drawing. 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 @@ -288,6 +288,24 @@ } + protected void drawTileAt(int x, int y, int tileIndex, int height) + { + Vector2 squareOffset = new Vector2(Camera.Location.X % 32, + Camera.Location.Y % 32); + + int offsetX = (int)squareOffset.X; + int offsetY = (int)squareOffset.Y; + + batch.Draw( + Tile.TileSetTexture, + new Rectangle( + (x * Tile.TileStepX) - offsetX + 0 + baseOffsetX, + (y * Tile.TileStepY) - offsetY + baseOffsetY, + Tile.TileWidth, Tile.TileHeight*height), + Tile.GetExtendedSourceRectangle(tileIndex, height), + Color.White); + } + protected override void Draw(GameTime gameTime) { // Render stuff in here. Do NOT run game logic in here! @@ -339,6 +357,8 @@ } } + + //Gridlines //Lines going down and to the right: for (int x = (-this.squaresAcross); x < this.squaresAcross; x++) @@ -368,6 +388,24 @@ } + //int startpos = 140; + //for (int i = startpos; i < startpos + 4; i++) + //{ + // batch.Draw( + // Tile.TileSetTexture, + // new Rectangle( + // ((i - startpos+2) * 2 * Tile.TileStepX) - offsetX + 0 + baseOffsetX, + // (4 * Tile.TileStepY) - offsetY + baseOffsetY, + // Tile.TileWidth, Tile.TileHeight), + // Tile.GetExtendedSourceRectangle(i, 2), + // Color.White); + //} + + drawTileAt(4, 4, 140, 3); + drawTileAt(6, 4, 141, 3); + drawTileAt(8, 4, 142, 2); + drawTileAt(10, 4, 142, 3); + batch.DrawString(font, fps, new Vector2(33, 33), Color.Black); batch.DrawString(font, fps, new Vector2(32, 32), Color.White); batch.End(); 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 @@ -15,15 +15,21 @@ public static void drawLine(SpriteBatch batch, Vector2 start, Vector2 stop, Color color) { - drawLine(batch, start, stop, color, 1); + drawLine(batch, start, stop, color, 0, 1); } - public static void drawLine(SpriteBatch batch, Vector2 start, Vector2 stop, Color color, int width) + public static void drawLine(SpriteBatch batch, Vector2 start, Vector2 stop, Color color, float depth) + { + drawLine(batch, start, stop, color, depth, 1); + + } + + public static void drawLine(SpriteBatch batch, Vector2 start, Vector2 stop, Color color, float depth, int width) { Vector2 line = stop - start; float angle = (float)Math.Atan2((double)line.Y, (double) line.X); Rectangle rect = new Rectangle((int)start.X, (int)start.Y, (int)Math.Round(line.Length()), width); - batch.Draw(Line.PixelTexture, rect, null, color, angle, new Vector2(0,0), SpriteEffects.None, 0); + batch.Draw(Line.PixelTexture, rect, null, color, angle, new Vector2(0,0), SpriteEffects.None, depth); } 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 @@ -20,9 +20,6 @@ public Tile() { } - - - static public Rectangle GetSourceRectangle(int tileIndex) { @@ -32,5 +29,13 @@ return new Rectangle(tileX * TileWidth, tileY * TileHeight, TileWidth, TileHeight); } + static public Rectangle GetExtendedSourceRectangle(int tileIndex, int height) + { + int tileY = tileIndex / (TileSetTexture.Width / TileWidth); + int tileX = tileIndex % (TileSetTexture.Width / TileWidth); + + return new Rectangle(tileX * TileWidth, tileY * TileHeight, TileWidth, TileHeight*height); + } + } }