# HG changeset patch # User alys # Date 2021-02-04 03:45:37 # Node ID a2fcaf2ceffcbfce64362717f90e7ffc368da844 # Parent 28316c75d1ccd1f0f22274fdf1b8aa3025ed2b7a Factor out some of the tile drawing code. 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 @@ -429,6 +429,10 @@ } + protected float calculateDepth() { + return ((this.squaresAcross + 1) + ((this.squaresDown + 1) * Tile.TileWidth)) * 10; + } + protected Boolean cull(int gridX, int gridY) { int screenX = (gridX - gridY) * Tile.TileSpriteWidth / 2; @@ -441,83 +445,17 @@ && MathUtils.Between(original.Y, -Tile.TileSpriteHeight, FNAGame.height))); } - - protected void drawTileAt(int x, int y, int tileIndex, int height) + //Convenience method I'm not super sure about anymore. + protected void drawTileAt(int x, int y, int tileIndex, int height) { float maxdepth = ((this.squaresAcross + 1) + ((this.squaresDown + 1) * Tile.TileWidth)) * 10; float depthOffset = 0.7f - ((0 + (0 * Tile.TileWidth)) / maxdepth); - drawTileAt(x, y, tileIndex, height, depthOffset); + Tile.drawTileAt(this.batch, x, y, tileIndex, height, depthOffset); } - - - protected void drawTileAt(int x, int y, int tileIndex, int height, float depth) - { - /* - Vector2 firstSquare = Vector2.Zero; - Vector2 squareOffset = Vector2.Zero; - - int offsetX = (int)squareOffset.X; - int offsetY = (int)squareOffset.Y; - int firstX = (int)firstSquare.X; - int firstY = (int)firstSquare.Y; - int rowOffset = 0; - float maxdepth = ((this.squaresAcross + 1) + ((this.squaresDown + 1) * Tile.TileWidth)) * 10; - - int mapx = (firstX + x); - int mapy = (firstY + y); - float depthOffset = 0.7f - ((mapx + (mapy * Tile.TileWidth)) / maxdepth); - - if ((firstY + y) % 2 == 1) - rowOffset = Tile.OddRowXOffset; - - batch.Draw( - Tile.TileSetTexture, - new Rectangle( - (x * Tile.TileStepX) - offsetX + rowOffset + baseOffsetX, - (y * Tile.TileStepY) - offsetY + baseOffsetY-(Tile.TileHeight*(height-1)), - Tile.TileWidth, Tile.TileHeight*height), - Tile.GetExtendedSourceRectangle(tileIndex, height), - Color.White, - 0.0f, - Vector2.Zero, - SpriteEffects.None, - depthOffset); - */ - - int height_adjust = 0; - - if (height > 1) //not sure why this is necessary :/ - { - height_adjust = height; - } - - int adjustedx = x - height_adjust; - int adjustedy = y - height_adjust; - - int screenx = (adjustedx - adjustedy) * Tile.TileSpriteWidth / 2; - int screeny = (adjustedx + adjustedy) * Tile.TileSpriteHeight / 2; - - if (this.cull(x, y)) - { - 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, - depth); - } - - } protected override void Draw(GameTime gameTime) { @@ -607,10 +545,7 @@ this.tilesDrawn++; } - - } - } #endregion draw_tiles @@ -687,16 +622,18 @@ } */ +#if DEBUG drawTileAt(4, 4, 140, 3); drawTileAt(6, 4, 141, 3); drawTileAt(8, 4, 142, 2); drawTileAt(10, 4, 142, 3); +#endif #region draw_cursor //drawTileAt((int)this.mouseGrid.X, (int)this.mouseGrid.Y, 2, 1, 0.85f); //between tiles and gridlines - //TODO figure out why it has to be -1 - if (MathUtils.Between(this.mouseGrid.X, -1, this.simulation.map.MapWidth) + //TODO figure out why it has to be -1 + if (MathUtils.Between(this.mouseGrid.X, -1, this.simulation.map.MapWidth) && MathUtils.Between(this.mouseGrid.Y, -1, this.simulation.map.MapHeight)) { Tile.OutlineSquare(batch, this.mouseGrid.X, this.mouseGrid.Y, Color.Yellow, 1); 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 @@ -81,5 +81,85 @@ color, 0.79f); } + + + // protected void drawTileAt(int x, int y, int tileIndex, int height) + // { + // float maxdepth = ((this.squaresAcross + 1) + ((this.squaresDown + 1) * Tile.TileWidth)) * 10; + + // float depthOffset = 0.7f - ((0 + (0 * Tile.TileWidth)) / maxdepth); + + // Tile.drawTileAt(x, y, tileIndex, height, depthOffset); + // } + + + + public static void drawTileAt(SpriteBatch batch, int x, int y, int tileIndex, int height, float depth) + { + /* + Vector2 firstSquare = Vector2.Zero; + Vector2 squareOffset = Vector2.Zero; + + int offsetX = (int)squareOffset.X; + int offsetY = (int)squareOffset.Y; + int firstX = (int)firstSquare.X; + int firstY = (int)firstSquare.Y; + int rowOffset = 0; + float maxdepth = ((this.squaresAcross + 1) + ((this.squaresDown + 1) * Tile.TileWidth)) * 10; + + + int mapx = (firstX + x); + int mapy = (firstY + y); + float depthOffset = 0.7f - ((mapx + (mapy * Tile.TileWidth)) / maxdepth); + + if ((firstY + y) % 2 == 1) + rowOffset = Tile.OddRowXOffset; + + batch.Draw( + Tile.TileSetTexture, + new Rectangle( + (x * Tile.TileStepX) - offsetX + rowOffset + baseOffsetX, + (y * Tile.TileStepY) - offsetY + baseOffsetY-(Tile.TileHeight*(height-1)), + Tile.TileWidth, Tile.TileHeight*height), + Tile.GetExtendedSourceRectangle(tileIndex, height), + Color.White, + 0.0f, + Vector2.Zero, + SpriteEffects.None, + depthOffset); + */ + + int height_adjust = 0; + + if (height > 1) //not sure why this is necessary :/ + { + height_adjust = height; + } + + int adjustedx = x - height_adjust; + int adjustedy = y - height_adjust; + + int screenx = (adjustedx - adjustedy) * Tile.TileSpriteWidth / 2; + int screeny = (adjustedx + adjustedy) * Tile.TileSpriteHeight / 2; + + // if (this.cull(x, y)) + // { + 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, + depth); + // } + + } + + } }