Description:
Limit lines to grid.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r8:b7098c882d8e -

@@ -315,9 +315,9
315 315 batch.Draw(
316 316 Tile.TileSetTexture,
317 317 new Rectangle(
318 ((x * Tile.TileStepX) - offsetX + rowOffset + baseOffsetX),
319 ((y * Tile.TileStepY) - offsetY + baseOffsetY),
320 Tile.TileWidth, Tile.TileHeight),
318 (4*((x * Tile.TileStepX)) - offsetX + 4*rowOffset + 4*baseOffsetX),
319 (4*((y * Tile.TileStepY)) - offsetY + 4*baseOffsetY),
320 4 * Tile.TileWidth, 4 * Tile.TileHeight),
321 321 Tile.GetSourceRectangle(1),
322 322 Color.White,
323 323 0.0f,
@@ -331,7 +331,7
331 331
332 332 //Gridlines
333 333 //Lines going down and to the right:
334 for (int x = (-this.squaresAcross); x < this.squaresAcross; x++)
334 for (int x = (int)(-this.squaresAcross/2); x < this.squaresAcross; x++)
335 335 {
336 336 int rowOffset = 0;
337 337
@@ -341,11 +341,16
341 341 Vector2 stop = new Vector2(startX + this.squaresAcross* Tile.TileStepX/2,
342 342 this.squaresDown*Tile.TileStepY- baseOffsetY+4);
343 343
344 Line.drawLine(batch, start, stop, Color.White, 0.8f);
344
345
346 Line.drawLine(batch,
347 Line.departurePoint(stop, start, this.squaresAcross * Tile.TileWidth, this.squaresDown * Tile.TileHeight),
348 Line.departurePoint(start, stop, this.squaresAcross * Tile.TileWidth, this.squaresDown * Tile.TileHeight),
349 Color.White, 0.8f);
345 350
346 351 }
347 352 //Lines going down and to the left:
348 for (int x = 0; x < (2*this.squaresAcross); x++)
353 for (int x = 0; x < (int)(1.5*this.squaresAcross); x++)
349 354 {
350 355
351 356 float startX = (x * Tile.TileStepX) + baseOffsetX - (Tile.TileStepX / 2);
@@ -354,7 +359,10
354 359 Vector2 stop_reverse = new Vector2(startX + -(this.squaresAcross * Tile.TileStepX / 2),
355 360 (this.squaresDown * Tile.TileStepY) - baseOffsetY + 4);
356 361
357 Line.drawLine(batch, start_reverse, stop_reverse, Color.White, 0.8f);
362 Line.drawLine(batch,
363 Line.departurePoint(stop_reverse, start_reverse, this.squaresAcross * Tile.TileWidth, this.squaresDown * Tile.TileHeight),
364 Line.departurePoint(start_reverse, stop_reverse, this.squaresAcross * Tile.TileWidth, this.squaresDown * Tile.TileHeight),
365 Color.White, 0.8f);
358 366
359 367 }
360 368
@@ -365,21 +373,18
365 373 drawTileAt(0, 0, 22, 1);
366 374
367 375
368 //*
369
376 /*
370 377
371
372 378 for (int i = 0; i< 80; i++)
373 379 {
374 380 for (int j = 0; j < 50; j += 1)
375 381 {
376 382 //Warning: creates a flashing effect because tree positions update every 1/60th of a second
377 383
378 /*
379 384 if (this.random_generator.NextDouble() > 0.75)
380 385 {
381 386 drawTileAt(i, j, 142, 2);
382 }//*/
387 }
383 388
384 389 if ((i + j) % 3 == 0)
385 390 {
@@ -40,6 +40,43
40 40
41 41 Line.PixelTexture.SetData<Color> (new Color[] { Color.White});
42 42 }
43
44 public static Vector2 departurePoint(Vector2 start, Vector2 stop, float width, float height)
45 {
46 if (MathUtils.Between(stop.X, 0, width ) && MathUtils.Between(stop.Y, 0, height)) {
47 return stop;
48 }
49
50 float slope = (start.Y - stop.Y) / (start.X - stop.X);
51
52 float intercept = (start.Y - (slope * start.X));
53
54 if (stop.X < 0) {
55 float newY = slope * 0 + intercept;
56 return new Vector2(0, newY);
57 }
58 else if (stop.Y < 0)
59 {
60 float newX = intercept / slope;
61 return new Vector2(newX, 0);
62
63 }
64
65 else if (stop.Y > height)
66 {
67 float newX = (intercept + height) / slope;
68 return new Vector2(newX, height);
69 }
70 else if (stop.X > width)
71 {
72 float newY = slope * width + intercept;
73 return new Vector2(width, newY);
74 }
75
76 return stop;//TODO
77
78
79 }
43 80 }
44 81
45 82
You need to be logged in to leave comments. Login now