Description:
Switch to drawing from top middle rather than upper-right corner.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r12:5bbfda434f15 -

@@ -55,6 +55,8
55 55
56 56 Vector2 mouseGrid;
57 57 Vector2 original_point;
58 Vector2 mousePos;
59
58 60
59 61
60 62 private static void Main(string[] args)
@@ -159,19 +161,31
159 161
160 162 Vector2 calculateMousegrid(Vector2 normalizedMousePos)
161 163 {
162 int gridx = (int)((normalizedMousePos.X ) / Tile.TileWidth);
163 int gridy = (int)((normalizedMousePos.Y + (2*baseOffsetY)) / (Tile.TileStepY));
164
165 //int gridx = (int)(normalizedMousePos.X / Tile.TileSpriteWidth);
166 //int gridy = (int)(normalizedMousePos.Y / Tile.TileSpriteHeight);
167 Vector2 adjust = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight);
168 Vector2 adjustedMousePos = normalizedMousePos - adjust;
169
170 float boardx = ((adjustedMousePos.X/ Tile.TileSpriteWidth) + (adjustedMousePos.Y / Tile.TileSpriteHeight));
171 float boardy = ((adjustedMousePos.Y / Tile.TileSpriteHeight) - (adjustedMousePos.X / Tile.TileSpriteWidth));
172
173
174 return new Vector2(boardx, boardy);
175 /*
176 int gridx = (int)((normalizedMousePos.X + (this.baseOffsetX + 4)) / Tile.TileWidth) ;
177 int gridy = (int)((normalizedMousePos.Y + (this.baseOffsetX + 4) + (2*baseOffsetY)) / (Tile.TileStepY));
164 178
165 179
166 180
167 181
168 int within_gridx = (int)(normalizedMousePos.X % Tile.TileWidth) - (Tile.TileWidth/2);
169 int within_gridy = (int)(normalizedMousePos.Y % Tile.TileHeight) - (Tile.TileHeight / 2);
182 int within_gridx = (int)((normalizedMousePos.X) % Tile.TileWidth) - (Tile.TileWidth/2);
183 int within_gridy = (int)((normalizedMousePos.Y) % Tile.TileHeight) - (Tile.TileHeight / 2);
170 184
171 185 int middle_distance = Math.Abs(within_gridx) + Math.Abs(within_gridx);
172 186 Vector2 adjustment_vector;
173 187
174 //return new Vector2(gridx, gridy);
188 return new Vector2(gridx, gridy);
175 189 if (middle_distance < (Tile.TileWidth / 2))
176 190 {
177 191 return new Vector2(gridx, gridy);
@@ -200,6 +214,9
200 214 else {
201 215 return new Vector2(gridx, gridy);
202 216 }
217 */
218
219
203 220
204 221 }
205 222
@@ -287,6 +304,7
287 304 this.camera.Move(new Vector2(0, 4));
288 305 }
289 306
307
290 308
291 309
292 310 this.original_point = Vector2.Transform(new Vector2(mouseCur.X, mouseCur.Y), Matrix.Invert(camera.get_transformation(GraphicsDevice)));
@@ -317,6 +335,7
317 335
318 336 protected void drawTileAt(int x, int y, int tileIndex, int height)
319 337 {
338 /*
320 339 Vector2 firstSquare = Vector2.Zero;
321 340 Vector2 squareOffset = Vector2.Zero;
322 341
@@ -347,6 +366,27
347 366 Vector2.Zero,
348 367 SpriteEffects.None,
349 368 depthOffset);
369 */
370
371
372 int screenx = (x - y) * Tile.TileSpriteWidth / 2;
373 int screeny = (x + y) * Tile.TileSpriteHeight / 2;
374 float maxdepth = ((this.squaresAcross + 1) + ((this.squaresDown + 1) * Tile.TileWidth)) * 10;
375
376 float depthOffset = 0.7f - ((0 + (0 * Tile.TileWidth)) / maxdepth);
377
378 batch.Draw(
379 Tile.TileSetTexture,
380 new Rectangle(
381 screenx,
382 screeny,
383 Tile.TileWidth, Tile.TileHeight * height),
384 Tile.GetExtendedSourceRectangle(tileIndex, height),
385 Color.White,
386 0.0f,
387 Vector2.Zero,
388 SpriteEffects.None,
389 depthOffset);
350 390 }
351 391
352 392 protected override void Draw(GameTime gameTime)
@@ -371,6 +411,7
371 411 camera.get_transformation(GraphicsDevice));
372 412
373 413 //New tile stuff
414 /*
374 415 Vector2 firstSquare = Vector2.Zero;
375 416 int firstX = (int)firstSquare.X;
376 417 int firstY = (int)firstSquare.Y;
@@ -380,6 +421,7
380 421 int offsetX = (int)squareOffset.X;
381 422 int offsetY = (int)squareOffset.Y;
382 423
424
383 425 for (int y = 0; y < this.squaresDown; y++)
384 426 {
385 427 int rowOffset = 0;
@@ -404,23 +446,76
404 446
405 447
406 448 }
407 }
408
449 }*/
450
451
452 for (int y = 0; y < this.squaresDown; y++)
453 {
454
455 for (int x = 0; x < this.squaresAcross; x++)
456 {
457
458 int screenx = (x - y) * Tile.TileSpriteWidth/2;
459
460 int screeny = (x + y) * Tile.TileSpriteHeight / 2;
461
462 batch.Draw(
463 Tile.TileSetTexture,
464 new Rectangle(
465 screenx,
466 screeny,
467 Tile.TileWidth, Tile.TileHeight),
468 Tile.GetSourceRectangle(1),
469 Color.White,
470 0.0f,
471 Vector2.Zero,
472 SpriteEffects.None,
473 0.9f);
474 }
475
476 }
477
478 for (int y = 0; y < this.squaresDown; y++)
479 {
480
481 Vector2 adjust = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); //TODO figure out why this second value shouldn't be halved
482
483 Line.drawLine(batch,
484 new Vector2(((0-y) * Tile.TileSpriteWidth/2), (0+y)*Tile.TileSpriteHeight/2) + adjust,
485 //new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight),
486 new Vector2((this.squaresAcross - (y)) * Tile.TileSpriteWidth / 2, (this.squaresAcross + (y )) * Tile.TileSpriteHeight / 2) + adjust,
487 Color.White, 0.8f);
488
489 }
490
491 for (int x = 0; x < this.squaresAcross; x++)
492 {
493
494 Vector2 adjust = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); //TODO figure out why this second value shouldn't be halved
495
496 Line.drawLine(batch,
497 new Vector2(((x - 0) * Tile.TileSpriteWidth / 2), (x + 0) * Tile.TileSpriteHeight / 2) + adjust,
498 //new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight),
499 new Vector2((x - this.squaresDown) * Tile.TileSpriteWidth / 2, (x + this.squaresDown) * Tile.TileSpriteHeight / 2) + adjust,
500 Color.White, 0.8f);
501
502 }
409 503
410 504
411 505 //Gridlines
412 506 //Lines going down and to the right:
413 for (int x = (int)(-this.squaresAcross/2); x < this.squaresAcross; x++)
507 /*
508 for (int x = (int)(-this.squaresAcross/2); x < this.squaresAcross; x++)
414 509 {
415 510 int rowOffset = 0;
416
511
417 512 float startX = (x * Tile.TileStepX) + baseOffsetX - (Tile.TileStepX / 2);
418 513
419 514 Vector2 start = new Vector2(startX, -baseOffsetY+4);
420 515 Vector2 stop = new Vector2(startX + this.squaresAcross* Tile.TileStepX/2,
421 516 this.squaresDown*Tile.TileStepY- baseOffsetY+4);
422 517
423
518
424 519
425 520 Line.drawLine(batch,
426 521 Line.departurePoint(stop, start, this.squaresAcross * Tile.TileWidth, this.squaresDown * Tile.TileHeight),
@@ -431,7 +526,7
431 526 //Lines going down and to the left:
432 527 for (int x = 0; x < (int)(1.5*this.squaresAcross); x++)
433 528 {
434
529
435 530 float startX = (x * Tile.TileStepX) + baseOffsetX - (Tile.TileStepX / 2);
436 531
437 532 Vector2 start_reverse = new Vector2(startX, -baseOffsetY + 4);
@@ -444,12 +539,13
444 539 Color.White, 0.8f);
445 540
446 541 }
542 */
447 543
448 544 drawTileAt(4, 4, 140, 3);
449 545 drawTileAt(6, 4, 141, 3);
450 546 drawTileAt(8, 4, 142, 2);
451 547 drawTileAt(10, 4, 142, 3);
452 drawTileAt(0, 0, 22, 1);
548 //drawTileAt(0, 0, 22, 1);
453 549
454 550
455 551 drawTileAt((int)this.mouseGrid.X, (int)this.mouseGrid.Y, 2, 1);
@@ -485,7 +581,7
485 581
486 582 if (this.map.cells[i][j].hasTree)
487 583 {
488 //drawTileAt(i, j, 142, 2);
584 drawTileAt(i, j, 142, 2);
489 585 }
490 586
491 587
@@ -517,10 +613,10
517 613
518 614 batch.DrawString(font, this.mouseGrid.ToString(), new Vector2(360, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f);
519 615 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 */
616
617 batch.DrawString(font, this.original_point.ToString(), new Vector2(460, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f);
618 batch.DrawString(font, this.original_point.ToString(), new Vector2(459, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f);
619 //*/
524 620 //Matrix.Multiply()
525 621 batch.End();
526 622
@@ -15,6 +15,9
15 15 static public int OddRowXOffset = 32;
16 16 static public int HeightTileOffset = 32;
17 17
18 static public int TileSpriteWidth = 64;
19 static public int TileSpriteHeight = 32;
20
18 21 static public Texture2D TileSetTexture;
19 22
20 23 public Tile()
You need to be logged in to leave comments. Login now