Description:
Factor out some of the tile drawing code.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r68:a2fcaf2ceffc -

@@ -429,6 +429,10
429 429
430 430 }
431 431
432 protected float calculateDepth() {
433 return ((this.squaresAcross + 1) + ((this.squaresDown + 1) * Tile.TileWidth)) * 10;
434 }
435
432 436 protected Boolean cull(int gridX, int gridY)
433 437 {
434 438 int screenX = (gridX - gridY) * Tile.TileSpriteWidth / 2;
@@ -441,83 +445,17
441 445 && MathUtils.Between(original.Y, -Tile.TileSpriteHeight, FNAGame.height)));
442 446 }
443 447
444
445 protected void drawTileAt(int x, int y, int tileIndex, int height)
448 //Convenience method I'm not super sure about anymore.
449 protected void drawTileAt(int x, int y, int tileIndex, int height)
446 450 {
447 451 float maxdepth = ((this.squaresAcross + 1) + ((this.squaresDown + 1) * Tile.TileWidth)) * 10;
448 452
449 453 float depthOffset = 0.7f - ((0 + (0 * Tile.TileWidth)) / maxdepth);
450 454
451 drawTileAt(x, y, tileIndex, height, depthOffset);
455 Tile.drawTileAt(this.batch, x, y, tileIndex, height, depthOffset);
452 456 }
453 457
454
455
456 protected void drawTileAt(int x, int y, int tileIndex, int height, float depth)
457 {
458 /*
459 Vector2 firstSquare = Vector2.Zero;
460 Vector2 squareOffset = Vector2.Zero;
461
462 int offsetX = (int)squareOffset.X;
463 int offsetY = (int)squareOffset.Y;
464 int firstX = (int)firstSquare.X;
465 int firstY = (int)firstSquare.Y;
466 int rowOffset = 0;
467 float maxdepth = ((this.squaresAcross + 1) + ((this.squaresDown + 1) * Tile.TileWidth)) * 10;
468
469 458
470 int mapx = (firstX + x);
471 int mapy = (firstY + y);
472 float depthOffset = 0.7f - ((mapx + (mapy * Tile.TileWidth)) / maxdepth);
473
474 if ((firstY + y) % 2 == 1)
475 rowOffset = Tile.OddRowXOffset;
476
477 batch.Draw(
478 Tile.TileSetTexture,
479 new Rectangle(
480 (x * Tile.TileStepX) - offsetX + rowOffset + baseOffsetX,
481 (y * Tile.TileStepY) - offsetY + baseOffsetY-(Tile.TileHeight*(height-1)),
482 Tile.TileWidth, Tile.TileHeight*height),
483 Tile.GetExtendedSourceRectangle(tileIndex, height),
484 Color.White,
485 0.0f,
486 Vector2.Zero,
487 SpriteEffects.None,
488 depthOffset);
489 */
490
491 int height_adjust = 0;
492
493 if (height > 1) //not sure why this is necessary :/
494 {
495 height_adjust = height;
496 }
497
498 int adjustedx = x - height_adjust;
499 int adjustedy = y - height_adjust;
500
501 int screenx = (adjustedx - adjustedy) * Tile.TileSpriteWidth / 2;
502 int screeny = (adjustedx + adjustedy) * Tile.TileSpriteHeight / 2;
503
504 if (this.cull(x, y))
505 {
506 batch.Draw(
507 Tile.TileSetTexture,
508 new Rectangle(
509 screenx,
510 screeny,
511 Tile.TileWidth, Tile.TileHeight * height),
512 Tile.GetExtendedSourceRectangle(tileIndex, height),
513 Color.White,
514 0.0f,
515 Vector2.Zero,
516 SpriteEffects.None,
517 depth);
518 }
519
520 }
521 459
522 460 protected override void Draw(GameTime gameTime)
523 461 {
@@ -607,10 +545,7
607 545
608 546 this.tilesDrawn++;
609 547 }
610
611
612 548 }
613
614 549 }
615 550 #endregion draw_tiles
616 551
@@ -687,16 +622,18
687 622 }
688 623 */
689 624
625 #if DEBUG
690 626 drawTileAt(4, 4, 140, 3);
691 627 drawTileAt(6, 4, 141, 3);
692 628 drawTileAt(8, 4, 142, 2);
693 629 drawTileAt(10, 4, 142, 3);
630 #endif
694 631
695 632 #region draw_cursor
696 633 //drawTileAt((int)this.mouseGrid.X, (int)this.mouseGrid.Y, 2, 1, 0.85f); //between tiles and gridlines
697 634
698 //TODO figure out why it has to be -1
699 if (MathUtils.Between(this.mouseGrid.X, -1, this.simulation.map.MapWidth)
635 //TODO figure out why it has to be -1
636 if (MathUtils.Between(this.mouseGrid.X, -1, this.simulation.map.MapWidth)
700 637 && MathUtils.Between(this.mouseGrid.Y, -1, this.simulation.map.MapHeight))
701 638 {
702 639 Tile.OutlineSquare(batch, this.mouseGrid.X, this.mouseGrid.Y, Color.Yellow, 1);
@@ -81,5 +81,85
81 81 color, 0.79f);
82 82 }
83 83
84
85
86 // protected void drawTileAt(int x, int y, int tileIndex, int height)
87 // {
88 // float maxdepth = ((this.squaresAcross + 1) + ((this.squaresDown + 1) * Tile.TileWidth)) * 10;
89
90 // float depthOffset = 0.7f - ((0 + (0 * Tile.TileWidth)) / maxdepth);
91
92 // Tile.drawTileAt(x, y, tileIndex, height, depthOffset);
93 // }
94
95
96
97 public static void drawTileAt(SpriteBatch batch, int x, int y, int tileIndex, int height, float depth)
98 {
99 /*
100 Vector2 firstSquare = Vector2.Zero;
101 Vector2 squareOffset = Vector2.Zero;
102
103 int offsetX = (int)squareOffset.X;
104 int offsetY = (int)squareOffset.Y;
105 int firstX = (int)firstSquare.X;
106 int firstY = (int)firstSquare.Y;
107 int rowOffset = 0;
108 float maxdepth = ((this.squaresAcross + 1) + ((this.squaresDown + 1) * Tile.TileWidth)) * 10;
109
110
111 int mapx = (firstX + x);
112 int mapy = (firstY + y);
113 float depthOffset = 0.7f - ((mapx + (mapy * Tile.TileWidth)) / maxdepth);
114
115 if ((firstY + y) % 2 == 1)
116 rowOffset = Tile.OddRowXOffset;
117
118 batch.Draw(
119 Tile.TileSetTexture,
120 new Rectangle(
121 (x * Tile.TileStepX) - offsetX + rowOffset + baseOffsetX,
122 (y * Tile.TileStepY) - offsetY + baseOffsetY-(Tile.TileHeight*(height-1)),
123 Tile.TileWidth, Tile.TileHeight*height),
124 Tile.GetExtendedSourceRectangle(tileIndex, height),
125 Color.White,
126 0.0f,
127 Vector2.Zero,
128 SpriteEffects.None,
129 depthOffset);
130 */
131
132 int height_adjust = 0;
133
134 if (height > 1) //not sure why this is necessary :/
135 {
136 height_adjust = height;
137 }
138
139 int adjustedx = x - height_adjust;
140 int adjustedy = y - height_adjust;
141
142 int screenx = (adjustedx - adjustedy) * Tile.TileSpriteWidth / 2;
143 int screeny = (adjustedx + adjustedy) * Tile.TileSpriteHeight / 2;
144
145 // if (this.cull(x, y))
146 // {
147 batch.Draw(
148 Tile.TileSetTexture,
149 new Rectangle(
150 screenx,
151 screeny,
152 Tile.TileWidth, Tile.TileHeight * height),
153 Tile.GetExtendedSourceRectangle(tileIndex, height),
154 Color.White,
155 0.0f,
156 Vector2.Zero,
157 SpriteEffects.None,
158 depth);
159 // }
160
161 }
162
163
84 164 }
85 165 }
You need to be logged in to leave comments. Login now