Description:
Add rudimentary tree drawing.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -288,6 +288,24 | |||
|
288 | 288 | |
|
289 | 289 | } |
|
290 | 290 | |
|
291 | protected void drawTileAt(int x, int y, int tileIndex, int height) | |
|
292 | { | |
|
293 | Vector2 squareOffset = new Vector2(Camera.Location.X % 32, | |
|
294 | Camera.Location.Y % 32); | |
|
295 | ||
|
296 | int offsetX = (int)squareOffset.X; | |
|
297 | int offsetY = (int)squareOffset.Y; | |
|
298 | ||
|
299 | batch.Draw( | |
|
300 | Tile.TileSetTexture, | |
|
301 | new Rectangle( | |
|
302 | (x * Tile.TileStepX) - offsetX + 0 + baseOffsetX, | |
|
303 | (y * Tile.TileStepY) - offsetY + baseOffsetY, | |
|
304 | Tile.TileWidth, Tile.TileHeight*height), | |
|
305 | Tile.GetExtendedSourceRectangle(tileIndex, height), | |
|
306 | Color.White); | |
|
307 | } | |
|
308 | ||
|
291 | 309 | protected override void Draw(GameTime gameTime) |
|
292 | 310 | { |
|
293 | 311 | // Render stuff in here. Do NOT run game logic in here! |
@@ -339,6 +357,8 | |||
|
339 | 357 | } |
|
340 | 358 | } |
|
341 | 359 | |
|
360 | ||
|
361 | ||
|
342 | 362 | //Gridlines |
|
343 | 363 | //Lines going down and to the right: |
|
344 | 364 | for (int x = (-this.squaresAcross); x < this.squaresAcross; x++) |
@@ -368,6 +388,24 | |||
|
368 | 388 | |
|
369 | 389 | } |
|
370 | 390 | |
|
391 | //int startpos = 140; | |
|
392 | //for (int i = startpos; i < startpos + 4; i++) | |
|
393 | //{ | |
|
394 | // batch.Draw( | |
|
395 | // Tile.TileSetTexture, | |
|
396 | // new Rectangle( | |
|
397 | // ((i - startpos+2) * 2 * Tile.TileStepX) - offsetX + 0 + baseOffsetX, | |
|
398 | // (4 * Tile.TileStepY) - offsetY + baseOffsetY, | |
|
399 | // Tile.TileWidth, Tile.TileHeight), | |
|
400 | // Tile.GetExtendedSourceRectangle(i, 2), | |
|
401 | // Color.White); | |
|
402 | //} | |
|
403 | ||
|
404 | drawTileAt(4, 4, 140, 3); | |
|
405 | drawTileAt(6, 4, 141, 3); | |
|
406 | drawTileAt(8, 4, 142, 2); | |
|
407 | drawTileAt(10, 4, 142, 3); | |
|
408 | ||
|
371 | 409 | batch.DrawString(font, fps, new Vector2(33, 33), Color.Black); |
|
372 | 410 | batch.DrawString(font, fps, new Vector2(32, 32), Color.White); |
|
373 | 411 | batch.End(); |
@@ -15,15 +15,21 | |||
|
15 | 15 | |
|
16 | 16 | public static void drawLine(SpriteBatch batch, Vector2 start, Vector2 stop, Color color) |
|
17 | 17 | { |
|
18 | drawLine(batch, start, stop, color, 1); | |
|
18 | drawLine(batch, start, stop, color, 0, 1); | |
|
19 | 19 | } |
|
20 | 20 | |
|
21 |
public static void drawLine(SpriteBatch batch, Vector2 start, Vector2 stop, Color color, |
|
|
21 | public static void drawLine(SpriteBatch batch, Vector2 start, Vector2 stop, Color color, float depth) | |
|
22 | { | |
|
23 | drawLine(batch, start, stop, color, depth, 1); | |
|
24 | ||
|
25 | } | |
|
26 | ||
|
27 | public static void drawLine(SpriteBatch batch, Vector2 start, Vector2 stop, Color color, float depth, int width) | |
|
22 | 28 | { |
|
23 | 29 | Vector2 line = stop - start; |
|
24 | 30 | float angle = (float)Math.Atan2((double)line.Y, (double) line.X); |
|
25 | 31 | Rectangle rect = new Rectangle((int)start.X, (int)start.Y, (int)Math.Round(line.Length()), width); |
|
26 |
batch.Draw(Line.PixelTexture, rect, null, color, angle, new Vector2(0,0), SpriteEffects.None, |
|
|
32 | batch.Draw(Line.PixelTexture, rect, null, color, angle, new Vector2(0,0), SpriteEffects.None, depth); | |
|
27 | 33 | |
|
28 | 34 | } |
|
29 | 35 |
@@ -20,9 +20,6 | |||
|
20 | 20 | public Tile() |
|
21 | 21 | { |
|
22 | 22 | } |
|
23 | ||
|
24 | ||
|
25 | ||
|
26 | 23 | |
|
27 | 24 | static public Rectangle GetSourceRectangle(int tileIndex) |
|
28 | 25 | { |
@@ -32,5 +29,13 | |||
|
32 | 29 | return new Rectangle(tileX * TileWidth, tileY * TileHeight, TileWidth, TileHeight); |
|
33 | 30 | } |
|
34 | 31 | |
|
32 | static public Rectangle GetExtendedSourceRectangle(int tileIndex, int height) | |
|
33 | { | |
|
34 | int tileY = tileIndex / (TileSetTexture.Width / TileWidth); | |
|
35 | int tileX = tileIndex % (TileSetTexture.Width / TileWidth); | |
|
36 | ||
|
37 | return new Rectangle(tileX * TileWidth, tileY * TileHeight, TileWidth, TileHeight*height); | |
|
38 | } | |
|
39 | ||
|
35 | 40 | } |
|
36 | 41 | } |
You need to be logged in to leave comments.
Login now