Description:
Add (broken) tile picker.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r11:4704dd9e682e -

@@ -44,7 +44,6
44 private int aiScore = 0;
44 private int aiScore = 0;
45
45
46 //new tile stuff
46 //new tile stuff
47 TileMap myMap = new TileMap();
48 int squaresAcross = 50;
47 int squaresAcross = 50;
49 int squaresDown = 50;
48 int squaresDown = 50;
50 int baseOffsetX = -14;
49 int baseOffsetX = -14;
@@ -54,6 +53,9
54
53
55 TileMap map;
54 TileMap map;
56
55
56 Vector2 mouseGrid;
57 Vector2 original_point;
58
57
59
58 private static void Main(string[] args)
60 private static void Main(string[] args)
59 {
61 {
@@ -155,6 +157,52
155 music.Dispose();
157 music.Dispose();
156 }
158 }
157
159
160 Vector2 calculateMousegrid(Vector2 normalizedMousePos)
161 {
162 int gridx = (int)((normalizedMousePos.X ) / Tile.TileWidth);
163 int gridy = (int)((normalizedMousePos.Y + (2*baseOffsetY)) / (Tile.TileStepY));
164
165
166
167
168 int within_gridx = (int)(normalizedMousePos.X % Tile.TileWidth) - (Tile.TileWidth/2);
169 int within_gridy = (int)(normalizedMousePos.Y % Tile.TileHeight) - (Tile.TileHeight / 2);
170
171 int middle_distance = Math.Abs(within_gridx) + Math.Abs(within_gridx);
172 Vector2 adjustment_vector;
173
174 //return new Vector2(gridx, gridy);
175 if (middle_distance < (Tile.TileWidth / 2))
176 {
177 return new Vector2(gridx, gridy);
178 }
179
180 else if ((Math.Sign(within_gridx) == -1) && (Math.Sign(within_gridy) == 1))
181 {
182 adjustment_vector = new Vector2(-1, -1);
183 return new Vector2(gridx, gridy) + adjustment_vector;
184 }
185 else if ((Math.Sign(within_gridx) == -1) && (Math.Sign(within_gridy) == -1))
186 {
187 adjustment_vector = new Vector2(-1, 1);
188 return new Vector2(gridx, gridy) + adjustment_vector;
189 }
190 else if ((Math.Sign(within_gridx) == 1) && (Math.Sign(within_gridy) == 1))
191 {
192 adjustment_vector = new Vector2(0, -1);
193 return new Vector2(gridx, gridy) + adjustment_vector;
194 }
195 else if ((Math.Sign(within_gridx) == 1) && (Math.Sign(within_gridy) == -1))
196 {
197 adjustment_vector = new Vector2(0, 1);
198 return new Vector2(gridx, gridy) + adjustment_vector;
199 }
200 else {
201 return new Vector2(gridx, gridy);
202 }
203
204 }
205
158
206
159
207
160 protected override void Update(GameTime gameTime)
208 protected override void Update(GameTime gameTime)
@@ -239,6 +287,18
239 this.camera.Move(new Vector2(0, 4));
287 this.camera.Move(new Vector2(0, 4));
240 }
288 }
241
289
290
291
292 this.original_point = Vector2.Transform(new Vector2(mouseCur.X, mouseCur.Y), Matrix.Invert(camera.get_transformation(GraphicsDevice)));
293
294 //int gridx = (int)((this.original_point.X-baseOffsetX) / Tile.TileStepX);
295 /* int gridx = (int)(this.original_point.Y / Tile.TileHeight + this.original_point.X / Tile.TileWidth); */
296 //int gridy = (int)((this.original_point.Y-baseOffsetY) / (Tile.TileStepY*2));
297 /* int gridy = (int)(this.original_point.Y / Tile.TileHeight - this.original_point.X / Tile.TileWidth); */
298
299 //this.mouseGrid = new Vector2(gridx, gridy);
300 this.mouseGrid = this.calculateMousegrid(this.original_point);
301
242 elapsedTime += gameTime.ElapsedGameTime;
302 elapsedTime += gameTime.ElapsedGameTime;
243
303
244 if (elapsedTime > TimeSpan.FromSeconds(1))
304 if (elapsedTime > TimeSpan.FromSeconds(1))
@@ -341,6 +401,8
341 Vector2.Zero,
401 Vector2.Zero,
342 SpriteEffects.None,
402 SpriteEffects.None,
343 0.9f);
403 0.9f);
404
405
344 }
406 }
345 }
407 }
346
408
@@ -390,6 +452,9
390 drawTileAt(0, 0, 22, 1);
452 drawTileAt(0, 0, 22, 1);
391
453
392
454
455 drawTileAt((int)this.mouseGrid.X, (int)this.mouseGrid.Y, 2, 1);
456
457
393 /*
458 /*
394
459
395 for (int i = 0; i< 80; i++)
460 for (int i = 0; i< 80; i++)
@@ -420,7 +485,7
420
485
421 if (this.map.cells[i][j].hasTree)
486 if (this.map.cells[i][j].hasTree)
422 {
487 {
423 drawTileAt(i, j, 142, 2);
488 //drawTileAt(i, j, 142, 2);
424 }
489 }
425
490
426
491
@@ -448,6 +513,15
448 batch.DrawString(font, this.map.tree_count.ToString(), new Vector2(330, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f);
513 batch.DrawString(font, this.map.tree_count.ToString(), new Vector2(330, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f);
449 batch.DrawString(font, this.map.tree_count.ToString(), new Vector2(329, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f);
514 batch.DrawString(font, this.map.tree_count.ToString(), new Vector2(329, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f);
450
515
516
517
518 batch.DrawString(font, this.mouseGrid.ToString(), new Vector2(360, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f);
519 batch.DrawString(font, this.mouseGrid.ToString(), new Vector2(359, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f);
520 /*
521 batch.DrawString(font, this.original_point.ToString(), new Vector2(360, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f);
522 batch.DrawString(font, this.original_point.ToString(), new Vector2(359, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f);
523 */
524 //Matrix.Multiply()
451 batch.End();
525 batch.End();
452
526
453
527
@@ -458,4 +532,4
458 }
532 }
459
533
460
534
461 } No newline at end of file
535 }
@@ -15,6 +15,9
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 ZoneWidth = 10;
19 public int ZoneHeight = 10;
20
18 public int tree_count
21 public int tree_count
19 {
22 {
20 get
23 get
@@ -67,6 +70,20
67 }
70 }
68 }
71 }
69
72
73 public System.Collections.IEnumerable tree_cells(int zone)
74 {
75 foreach (List<Cell> row in cells)
76 {
77 foreach (Cell cell in row)
78 {
79 if (cell.hasTree)
80 {
81 yield return cell;
82 }
83 }
84 }
85 }
86
70 public System.Collections.IEnumerable iterate_cells()
87 public System.Collections.IEnumerable iterate_cells()
71 {
88 {
72 foreach (List<Cell> row in cells)
89 foreach (List<Cell> row in cells)
You need to be logged in to leave comments. Login now