Description:
Add basic TileMap.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -9,7 +9,7 | |||||
|
9 | using SpriteFontPlus; |
|
9 | using SpriteFontPlus; |
|
10 | using isometricparkfna; |
|
10 | using isometricparkfna; |
|
11 | using System.Diagnostics; |
|
11 | using System.Diagnostics; |
|
12 |
|
12 | using System.Collections.Generic; | |
|
13 |
|
13 | ||
|
14 | class FNAGame : Game |
|
14 | class FNAGame : Game |
|
15 | { |
|
15 | { |
@@ -45,13 +45,15 | |||||
|
45 |
|
45 | ||
|
46 | //new tile stuff |
|
46 | //new tile stuff |
|
47 | TileMap myMap = new TileMap(); |
|
47 | TileMap myMap = new TileMap(); |
|
48 |
int squaresAcross = |
|
48 | int squaresAcross = 50; |
|
49 |
int squaresDown = |
|
49 | int squaresDown = 50; |
|
50 | int baseOffsetX = -14; |
|
50 | int baseOffsetX = -14; |
|
51 | int baseOffsetY = -14; |
|
51 | int baseOffsetY = -14; |
|
52 |
|
52 | ||
|
53 | GraphicsDevice device; |
|
53 | GraphicsDevice device; |
|
54 |
|
54 | ||
|
|
55 | TileMap map; | ||
|
|
56 | |||
|
55 |
|
57 | ||
|
56 | private static void Main(string[] args) |
|
58 | private static void Main(string[] args) |
|
57 | { |
|
59 | { |
@@ -78,6 +80,21 | |||||
|
78 | //gdm.SynchronizeWithVerticalRetrace = false; |
|
80 | //gdm.SynchronizeWithVerticalRetrace = false; |
|
79 | IsFixedTimeStep = false; |
|
81 | IsFixedTimeStep = false; |
|
80 |
|
82 | ||
|
|
83 | this.map = new TileMap(this.squaresAcross, this.squaresDown); | ||
|
|
84 | |||
|
|
85 | foreach (List<Cell> row in this.map.cells) | ||
|
|
86 | { | ||
|
|
87 | foreach (Cell cell in row) | ||
|
|
88 | { | ||
|
|
89 | if (this.random_generator.NextDouble() > 0.75) | ||
|
|
90 | { | ||
|
|
91 | cell.hasTree = true; | ||
|
|
92 | } | ||
|
|
93 | |||
|
|
94 | |||
|
|
95 | } | ||
|
|
96 | } | ||
|
|
97 | |||
|
81 | Content.RootDirectory = "Content"; |
|
98 | Content.RootDirectory = "Content"; |
|
82 |
|
99 | ||
|
83 |
|
100 | ||
@@ -262,7 +279,7 | |||||
|
262 | Tile.TileSetTexture, |
|
279 | Tile.TileSetTexture, |
|
263 | new Rectangle( |
|
280 | new Rectangle( |
|
264 | (x * Tile.TileStepX) - offsetX + rowOffset + baseOffsetX, |
|
281 | (x * Tile.TileStepX) - offsetX + rowOffset + baseOffsetX, |
|
265 | (y * Tile.TileStepY) - offsetY + baseOffsetY, |
|
282 | (y * Tile.TileStepY) - offsetY + baseOffsetY-(Tile.TileHeight*(height-1)), |
|
266 | Tile.TileWidth, Tile.TileHeight*height), |
|
283 | Tile.TileWidth, Tile.TileHeight*height), |
|
267 | Tile.GetExtendedSourceRectangle(tileIndex, height), |
|
284 | Tile.GetExtendedSourceRectangle(tileIndex, height), |
|
268 | Color.White, |
|
285 | Color.White, |
@@ -315,9 +332,9 | |||||
|
315 | batch.Draw( |
|
332 | batch.Draw( |
|
316 | Tile.TileSetTexture, |
|
333 | Tile.TileSetTexture, |
|
317 | new Rectangle( |
|
334 | new Rectangle( |
|
318 |
|
|
335 | ((x * Tile.TileStepX) - offsetX + rowOffset + baseOffsetX), |
|
319 |
|
|
336 | ((y * Tile.TileStepY) - offsetY + baseOffsetY), |
|
320 |
|
|
337 | Tile.TileWidth, Tile.TileHeight), |
|
321 | Tile.GetSourceRectangle(1), |
|
338 | Tile.GetSourceRectangle(1), |
|
322 | Color.White, |
|
339 | Color.White, |
|
323 | 0.0f, |
|
340 | 0.0f, |
@@ -395,6 +412,22 | |||||
|
395 | }//*/ |
|
412 | }//*/ |
|
396 |
|
413 | ||
|
397 |
|
414 | ||
|
|
415 | for (int i = 0; i < this.map.MapHeight; i++) | ||
|
|
416 | { | ||
|
|
417 | for (int j = 0; j < this.map.MapWidth; j += 1) | ||
|
|
418 | { | ||
|
|
419 | //Warning: creates a flashing effect because tree positions update every 1/60th of a second | ||
|
|
420 | |||
|
|
421 | if (this.map.cells[i][j].hasTree) | ||
|
|
422 | { | ||
|
|
423 | drawTileAt(i, j, 142, 2); | ||
|
|
424 | } | ||
|
|
425 | |||
|
|
426 | |||
|
|
427 | } | ||
|
|
428 | } | ||
|
|
429 | |||
|
|
430 | |||
|
398 | batch.End(); |
|
431 | batch.End(); |
|
399 |
|
432 | ||
|
400 | batch.Begin(SpriteSortMode.BackToFront, |
|
433 | batch.Begin(SpriteSortMode.BackToFront, |
@@ -412,6 +445,9 | |||||
|
412 | batch.DrawString(font, camera.position.ToString(), new Vector2(190, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); |
|
445 | batch.DrawString(font, camera.position.ToString(), new Vector2(190, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); |
|
413 | batch.DrawString(font, camera.position.ToString(), new Vector2(189, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f); |
|
446 | batch.DrawString(font, camera.position.ToString(), new Vector2(189, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f); |
|
414 |
|
447 | ||
|
|
448 | batch.DrawString(font, this.map.trees.ToString(), new Vector2(330, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); | ||
|
|
449 | batch.DrawString(font, this.map.trees.ToString(), new Vector2(329, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f); | ||
|
|
450 | |||
|
415 | batch.End(); |
|
451 | batch.End(); |
|
416 |
|
452 | ||
|
417 |
|
453 |
@@ -11,13 +11,59 | |||||
|
11 |
|
11 | ||
|
12 | public class TileMap |
|
12 | public class TileMap |
|
13 | { |
|
13 | { |
|
14 |
|
|
14 | public List<List<Cell>> cells; |
|
15 | public int MapWidth = 50; |
|
15 | public int MapWidth = 50; |
|
16 | public int MapHeight = 50; |
|
16 | public int MapHeight = 50; |
|
17 |
|
17 | ||
|
|
18 | public int trees | ||
|
|
19 | { | ||
|
|
20 | get | ||
|
|
21 | { | ||
|
|
22 | int count = 0; | ||
|
|
23 | foreach (List<Cell> row in cells) | ||
|
|
24 | { | ||
|
|
25 | foreach (Cell cell in row) | ||
|
|
26 | { | ||
|
|
27 | if (cell.hasTree) | ||
|
|
28 | { | ||
|
|
29 | count++; | ||
|
|
30 | } | ||
|
|
31 | } | ||
|
|
32 | } | ||
|
|
33 | return count; | ||
|
|
34 | } | ||
|
|
35 | } | ||
|
|
36 | |||
|
18 | public TileMap() |
|
37 | public TileMap() |
|
19 | { |
|
38 | { |
|
|
39 | //TileMap(MapWidth, MapHeight); | ||
|
|
40 | } | ||
|
|
41 | |||
|
|
42 | public TileMap(int width, int height) | ||
|
|
43 | { | ||
|
|
44 | this.MapWidth = width; | ||
|
|
45 | this.MapHeight = height; | ||
|
|
46 | |||
|
|
47 | this.cells = new List<List<Cell>>(); | ||
|
|
48 | |||
|
|
49 | for (int i = 0; i < height; i++) | ||
|
|
50 | { | ||
|
|
51 | List<Cell> newRow = new List<Cell>(); | ||
|
|
52 | for (int j = 0; j < width; j++) | ||
|
|
53 | { | ||
|
|
54 | newRow.Add(new Cell()); | ||
|
|
55 | } | ||
|
|
56 | |||
|
|
57 | this.cells.Add(newRow); | ||
|
|
58 | } | ||
|
20 |
|
59 | ||
|
21 | } |
|
60 | } |
|
|
61 | |||
|
|
62 | |||
|
|
63 | } | ||
|
|
64 | |||
|
|
65 | public class Cell | ||
|
|
66 | { | ||
|
|
67 | public Boolean hasTree = false; | ||
|
22 | } |
|
68 | } |
|
23 | } |
|
69 | } |
You need to be logged in to leave comments.
Login now