QB64.org Forum

Active Forums => Programs => Topic started by: SierraKen on May 17, 2020, 07:43:32 pm

Title: 3D Land Grid
Post by: SierraKen on May 17, 2020, 07:43:32 pm
Finally, I've made a 3D land grid that lets you move forward, back, and side to side, that WORKS! LOL I been wanting to make this since the 90's or possibly the 80's but could never figure it out. LOL
I've been close sooo many times lol. 
I know it doesn't have turning or jumping (or flying), but I'm not at that level of math. So feel free to do what you wish with it. Use the arrow keys to move forward, back, left side, right side. And press the space bar to stop. I might make this into a game in the future.

Code: QB64: [Select]
  1. 'This is SierraKen's first 3D Land Grid Example.
  2. 'Use the arrow keys to move and press space bar to stop.
  3. 'Made on May 17, 2020.
  4.  
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6. xs = 10
  7. GOSUB grid:
  8.  
  9.  
  10.     _LIMIT 100
  11.     a$ = INKEY$
  12.     IF a$ = CHR$(0) + CHR$(72) THEN d = 1
  13.     IF a$ = CHR$(0) + CHR$(80) THEN d = 2
  14.     IF a$ = CHR$(0) + CHR$(77) THEN d = 3
  15.     IF a$ = CHR$(0) + CHR$(75) THEN d = 4
  16.     IF a$ = " " THEN d = 0
  17.     if a$ = CHR$(27) THEN END
  18.     IF d = 1 THEN speed = speed + 1
  19.     IF d = 2 THEN speed = speed - 1
  20.     IF d = 3 THEN v = v - 1
  21.     IF d = 4 THEN v = v + 1
  22.     GOSUB grid:
  23.  
  24.  
  25. grid:
  26. 'Left vertical lines.
  27. FOR x = 395 TO 0 STEP -xs - xx
  28.     xx = xx + 5
  29.     IF v > 7 THEN v = -7
  30.     IF v < -7 THEN v = 7
  31.     LINE (x + v, 300)-(x - xx + v, 600), _RGB32(255, 255, 255)
  32.  
  33. 'Right vertical lines.
  34. FOR x = 405 TO 800 STEP xs + xx2
  35.     xx2 = xx2 + 5
  36.     IF v > 7 THEN v = -7
  37.     IF v < -7 THEN v = 7
  38.     LINE (x + v, 300)-(x + xx2 + v, 600), _RGB32(255, 255, 255)
  39.  
  40. 'Horizontal lines.
  41. LINE (0, 300)-(800, 300), _RGB32(255, 255, 255)
  42. FOR hy = 305 TO 600 STEP xs + xx3
  43.     xx3 = xx3 + 5
  44.     IF speed > 7 THEN speed = -7
  45.     IF speed < -7 THEN speed = 7
  46.     LINE (0, hy + xx3 + speed)-(800, hy + xx3 + speed), _RGB32(255, 255, 255)
  47. NEXT hy
  48. xx = 0: xx2 = 0: xx3 = 0
  49.  
  50.  
Title: Re: 3D Land Grid
Post by: Ashish on May 18, 2020, 02:58:15 am
Nice! It really creates 3D Illusion
Title: Re: 3D Land Grid
Post by: SierraKen on May 18, 2020, 12:47:46 pm
Thanks Ashish. :)
Title: Re: 3D Land Grid
Post by: SierraKen on May 18, 2020, 03:36:46 pm
Today I added the ability to turn. It doesn't tilt like a plane, but it turns to around a 45 degree turn on the grid. I also added some color to make it look better. I also added an updated picture to this post.

Code: QB64: [Select]
  1. 'This is SierraKen's first 3D Land Grid Example.
  2. 'Use the arrow keys to move and turn and press space bar to stop.
  3. 'Made on May 18, 2020.
  4. 'V. 0.2
  5.  
  6. SCREEN _NEWIMAGE(800, 600, 32)
  7. xs = 10
  8. GOSUB grid:
  9.  
  10.  
  11.     _LIMIT 100
  12.     a$ = INKEY$
  13.     IF a$ = CHR$(0) + CHR$(72) THEN d = 1
  14.     IF a$ = CHR$(0) + CHR$(80) THEN d = 2
  15.     IF a$ = CHR$(0) + CHR$(77) THEN d = 3
  16.     IF a$ = CHR$(0) + CHR$(75) THEN d = 4
  17.     IF a$ = " " THEN d = 0
  18.     IF a$ = CHR$(27) THEN END
  19.     IF d = 1 THEN speed = speed + 1
  20.     IF d = 2 THEN speed = speed - 1
  21.     IF d = 3 AND speed > 0 THEN
  22.         v = v - 1
  23.         vv = vv - 2
  24.         speed = speed + 2
  25.     END IF
  26.     IF d = 4 AND speed > 0 THEN
  27.         v = v + 1
  28.         vv = vv + 2
  29.         speed = speed + 2
  30.     END IF
  31.     IF d = 3 AND speed <= 0 THEN
  32.         v = v - 1
  33.         vv = vv - 2
  34.         speed = speed - 2
  35.     END IF
  36.     IF d = 4 AND speed <= 0 THEN
  37.         v = v + 1
  38.         vv = vv + 2
  39.         speed = speed - 2
  40.     END IF
  41.     GOSUB grid:
  42.  
  43. grid:
  44. PAINT (2, 2), _RGB32(0, 0, 150)
  45. LINE (0, 300)-(800, 600), _RGB32(0, 155, 0), BF
  46. 'Left vertical lines.
  47. FOR x = 395 TO -300 STEP -xs - xx
  48.     xx = xx + 5
  49.     IF v > 7 THEN v = -7
  50.     IF v < -7 THEN v = 7
  51.     IF vv > 300 THEN vv = 300
  52.     IF vv < -300 THEN vv = -300
  53.     LINE (x + v - vv, 300)-(x - xx + v + vv, 600), _RGB32(255, 255, 255)
  54.  
  55. 'Right vertical lines.
  56. FOR x = 405 TO 1100 STEP xs + xx2
  57.     xx2 = xx2 + 5
  58.     IF v > 7 THEN v = -7
  59.     IF v < -7 THEN v = 7
  60.     IF vv > 300 THEN vv = 300
  61.     IF vv < -300 THEN vv = -300
  62.     LINE (x + v - vv, 300)-(x + xx2 + v + vv, 600), _RGB32(255, 255, 255)
  63.  
  64. 'Horizontal lines.
  65. LINE (0, 300)-(800, 300), _RGB32(127, 172, 255)
  66. FOR hy = 305 TO 600 STEP xs + xx3
  67.     xx3 = xx3 + 5
  68.     IF speed > 7 THEN speed = -7
  69.     IF speed < -7 THEN speed = 7
  70.     LINE (0, hy + xx3 + speed)-(800, hy + xx3 + speed), _RGB32(255, 255, 255)
  71. NEXT hy
  72.  
  73. xx = 0: xx2 = 0: xx3 = 0
  74.  
  75.  
  76.  
Title: Re: 3D Land Grid
Post by: SierraKen on May 19, 2020, 04:04:15 pm
I just added curved turns, both forward and backward. That way you don't stop on a dime every time you turn. :)

Here is the update:

Code: QB64: [Select]
  1. 'This is SierraKen's first 3D Land Grid Example.
  2. 'Use the arrow keys to move and turn and press space bar to stop.
  3. 'Made on May 19, 2020.
  4. 'V. 0.3 - Added curved turns both forward and backward.
  5.  
  6. SCREEN _NEWIMAGE(800, 600, 32)
  7. xs = 10
  8. GOSUB grid:
  9.  
  10.  
  11.     _LIMIT 100
  12.     a$ = INKEY$
  13.     IF a$ = CHR$(0) + CHR$(72) THEN d = 1
  14.     IF a$ = CHR$(0) + CHR$(80) THEN d = 2
  15.     IF a$ = CHR$(0) + CHR$(77) THEN d = 3
  16.     IF a$ = CHR$(0) + CHR$(75) THEN d = 4
  17.     IF a$ = " " THEN d = 0
  18.     IF a$ = CHR$(27) THEN END
  19.     IF d = 1 THEN speed = speed + 1: b = 0
  20.     IF d = 2 THEN speed = speed - 1: b = 1
  21.     IF d = 3 AND speed > 0 THEN
  22.         v = v - 1
  23.         vv = vv - 2
  24.     END IF
  25.     IF d = 4 AND speed > 0 THEN
  26.         v = v + 1
  27.         vv = vv + 2
  28.     END IF
  29.     IF d = 3 AND speed <= 0 THEN
  30.         v = v - 1
  31.         vv = vv - 2
  32.     END IF
  33.     IF d = 4 AND speed <= 0 THEN
  34.         v = v + 1
  35.         vv = vv + 2
  36.     END IF
  37.     IF (d = 3 OR d = 4) AND b = 0 THEN speed = speed + 1
  38.     IF (d = 3 OR d = 4) AND b = 1 THEN speed = speed - 1
  39.     GOSUB grid:
  40.  
  41. grid:
  42. PAINT (2, 2), _RGB32(0, 0, 150)
  43. LINE (0, 300)-(800, 600), _RGB32(0, 155, 0), BF
  44. 'Left vertical lines.
  45. FOR x = 395 TO -300 STEP -xs - xx
  46.     xx = xx + 5
  47.     IF v > 7 THEN v = -7
  48.     IF v < -7 THEN v = 7
  49.     IF vv > 300 THEN vv = 300
  50.     IF vv < -300 THEN vv = -300
  51.     LINE (x + v - vv, 300)-(x - xx + v + vv, 600), _RGB32(255, 255, 255)
  52.  
  53. 'Right vertical lines.
  54. FOR x = 405 TO 1100 STEP xs + xx2
  55.     xx2 = xx2 + 5
  56.     IF v > 7 THEN v = -7
  57.     IF v < -7 THEN v = 7
  58.     IF vv > 300 THEN vv = 300
  59.     IF vv < -300 THEN vv = -300
  60.     LINE (x + v - vv, 300)-(x + xx2 + v + vv, 600), _RGB32(255, 255, 255)
  61.  
  62. 'Horizontal lines.
  63. LINE (0, 300)-(800, 300), _RGB32(127, 172, 255)
  64. FOR hy = 305 TO 600 STEP xs + xx3
  65.     xx3 = xx3 + 5
  66.     IF speed > 7 THEN speed = -7
  67.     IF speed < -7 THEN speed = 7
  68.     LINE (0, hy + xx3 + speed)-(800, hy + xx3 + speed), _RGB32(255, 255, 255)
  69. NEXT hy
  70.  
  71. xx = 0: xx2 = 0: xx3 = 0
  72.  
  73.  
  74.  
Title: Re: 3D Land Grid
Post by: OldMoses on May 19, 2020, 06:10:26 pm
That's a nice grid effect that inspired me to tackle a grid I've always wanted to do, hex grid. Mine doesn't move, ...yet ....I'm thinkin' about it. ;)

Code: QB64: [Select]
  1. 'Hex grid
  2. SCREEN _NEWIMAGE(480, 640, 32)
  3. s = 35
  4. sb = s / 2
  5. ho = s + (s * COS(_D2R(60)))
  6. vo = 2 * (s * SIN(_D2R(60)))
  7. FOR x = 0 TO 9
  8.     FOR y = 0 TO 11
  9.         IF x MOD 2 = 0 THEN b = vo / 2 ELSE b = 0
  10.         LINE (x * ho - sb, y * vo + b)-(x * ho + s - sb, y * vo + b)
  11.         LINE (x * ho + s - sb, y * vo + b)-(x * ho + s + ho - s - sb, y * vo + b - (vo / 2))
  12.         LINE (x * ho + s - sb, y * vo + b)-(x * ho + s + ho - s - sb, y * vo + b + (vo / 2))
  13.     NEXT y
  14.  
Title: Re: 3D Land Grid
Post by: SierraKen on May 19, 2020, 06:45:28 pm
Thanks OldMoses! Wow yours is pretty cool! Hexagonal Grid is what a lot of games used to use or just a way to print out maps for games.
I'm not sure where I am going with mine, I don't have a plan yet. I might make a giant map using a data file or DATA lines using something with coordinates and plotting in shapes and maybe some simple designs. Not sure if am able to do it but I might look into it soon. If I can't do that, I can always make no map and just use random shapes that appear. So we'll see. :)
Title: Re: 3D Land Grid
Post by: OldMoses on May 19, 2020, 07:40:44 pm
Hmmm... it turned out not too difficult to get it moving after all. If I could run a two dimensional array along with it, it might make a half assed game. Maybe some dude running along dodging boulders or something...

Code: QB64: [Select]
  1. 'Moving hex grid
  2. SCREEN _NEWIMAGE(480, 640, 32)
  3. s = 35
  4. sb = s / 2
  5. ho = s + (s * COS(_D2R(60)))
  6. vo = 2 * (s * SIN(_D2R(60)))
  7.     CLS
  8.     k = k + 1
  9.     IF k MOD vo = 0 THEN k = 0
  10.     FOR x = 0 TO 9
  11.         FOR y = -1 TO 11
  12.             IF x MOD 2 = 0 THEN b = vo / 2 ELSE b = 0
  13.             LINE (x * ho - sb, y * vo + b + k)-(x * ho + s - sb, y * vo + b + k)
  14.             LINE (x * ho + s - sb, y * vo + b + k)-(x * ho + s + ho - s - sb, y * vo + b - (vo / 2) + k)
  15.             LINE (x * ho + s - sb, y * vo + b + k)-(x * ho + s + ho - s - sb, y * vo + b + (vo / 2) + k)
  16.         NEXT y
  17.     NEXT x
  18.     _LIMIT 100
  19.     _DISPLAY
Title: Re: 3D Land Grid
Post by: SierraKen on May 19, 2020, 09:00:49 pm
That came out great! Your overhead view would be pretty fun. Just add a character in the center. :)
With my 3D perspective I have to make every object start out small and get larger as they approach. It shouldn't be too hard from what I have now. Of course my grid that I have now is only for looks, it won't have anything to do with coordinates, etc.
Title: Re: 3D Land Grid
Post by: _vince on May 19, 2020, 11:51:36 pm
Hmmm... it turned out not too difficult to get it moving after all. If I could run a two dimensional array along with it, it might make a half assed game. Maybe some dude running along dodging boulders or something...

I've converted your program into a 3D projection, hope you like it ;-)

Code: QB64: [Select]
  1. 'Moving hex grid
  2. SCREEN _NEWIMAGE(480, 480, 32)
  3. s = 35
  4. sb = s / 2
  5. ho = s + (s * COS(_D2R(60)))
  6. vo = 2 * (s * SIN(_D2R(60)))
  7.  
  8. ymax = 20
  9.     CLS
  10.     k = k - 1
  11.     IF k MOD vo = 0 THEN k = 0
  12.     FOR x = -10 TO 10
  13.         FOR y = 0 TO ymax
  14.             IF x MOD 2 = 0 THEN b = vo / 2 ELSE b = 0
  15.             x11 = x * ho - sb
  16.             y11 = y * vo + b + k
  17.             x12 = x * ho + s - sb
  18.             y12 = y * vo + b + k
  19.             p1 = 240 + x11 * 700 / (y11 + 250)
  20.             q1 = 200 * 700 / (y11 + 250)
  21.             p2 = 240 + x12 * 700 / (y12 + 250)
  22.             q2 = 200 * 700 / (y12 + 250)
  23.             'LINE (x11, y11)-(x12, y12)
  24.             LINE (p1, q1)-(p2, q2)
  25.  
  26.             x21 = x * ho + s - sb
  27.             y21 = y * vo + b + k
  28.             x22 = x * ho + s + ho - s - sb
  29.             y22 = y * vo + b - (vo / 2) + k
  30.             p1 = 240 + x21 * 700 / (y21 + 250)
  31.             q1 = 200 * 700 / (y21 + 250)
  32.             p2 = 240 + x22 * 700 / (y22 + 250)
  33.             q2 = 200 * 700 / (y22 + 250)
  34.             'LINE (x21, y21)-(x22, y22)
  35.             LINE (p1, q1)-(p2, q2)
  36.  
  37.             x31 = x * ho + s - sb
  38.             y31 = y * vo + b + k
  39.             x32 = x * ho + s + ho - s - sb
  40.             y32 = y * vo + b + (vo / 2) + k
  41.             p1 = 240 + x31 * 700 / (y31 + 250)
  42.             q1 = 200 * 700 / (y31 + 250)
  43.             p2 = 240 + x32 * 700 / (y32 + 250)
  44.             q2 = 200 * 700 / (y32 + 250)
  45.             'LINE (x31, y31)-(x32, y32)
  46.             LINE (p1, q1)-(p2, q2)
  47.         NEXT y
  48.     NEXT x
  49.  
  50.     LINE (0, 0)-(480, 100), _RGB(0, 0, 0), BF
  51.     LINE (0, 101)-(480, 101)
  52.     _LIMIT 50
  53.     _DISPLAY
  54.  
  55.  
  56.  
Title: Re: 3D Land Grid
Post by: OldMoses on May 20, 2020, 12:03:18 am
That's incredible, Vince.
Title: Re: 3D Land Grid
Post by: Ashish on May 20, 2020, 12:14:11 am
@vince Amazing! Can you also fill the color in the hexagon tile?
Title: Re: 3D Land Grid
Post by: Dav on May 20, 2020, 12:57:54 pm
These are great! 

- Dav
Title: Re: 3D Land Grid
Post by: SierraKen on May 21, 2020, 12:31:07 am
I just added flying! Whew, it's harder than I thought, spent all day and evening on it.
Use the + and - keys for the accelerator. Use the down arrow to go up and up arrow to go down (like a plane has). Use the right and left arrows to turn.
Please tell me what you think of it. Comments are often inspirational to keep me programming. :)

Code: QB64: [Select]
  1. 'Flying - By SierraKen
  2. 'Made on May 20, 2020.
  3. 'V. 0.4 - Added Flying
  4.  
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6. xs = 10
  7. GOSUB grid:
  8.  
  9. e = 100
  10. _TITLE "Down arrow goes up. Up arrow goes down. + and - number pad keys are the accelerator. Left and Right keys turn."
  11.     _LIMIT 1000
  12.     a$ = INKEY$
  13.  
  14.     IF a$ = CHR$(0) + CHR$(72) THEN d = 6: e = e + .5: b = 0 'Up arrow key flies down.
  15.     IF a$ = CHR$(0) + CHR$(80) THEN d = 5: e = e - .5: b = 0 'Down arrow key flies up.
  16.     IF a$ = "+" THEN d = 1: speed2 = speed2 + 10
  17.     IF a$ = "-" THEN
  18.         speed2 = speed2 - 10
  19.         IF speed2 < 0 THEN speed = speed - 2: b = 1
  20.     END IF
  21.     IF a$ = CHR$(0) + CHR$(77) THEN d = 3 'Right
  22.     IF a$ = CHR$(0) + CHR$(75) THEN d = 4 'Left
  23.     IF a$ = " " THEN d = 0
  24.     IF a$ = CHR$(27) THEN END
  25.     IF d = 1 THEN speed = speed + 4: b = 0
  26.     IF d = 3 AND speed > 0 THEN
  27.         v = v - 1
  28.         vv = vv - 2
  29.         tilt = tilt - 2
  30.         speed = speed + 4
  31.     END IF
  32.     IF d = 4 AND speed > 0 THEN
  33.         v = v + 1
  34.         vv = vv + 2
  35.         tilt = tilt + 2
  36.         speed = speed + 4
  37.     END IF
  38.     IF d = 3 AND speed <= 0 THEN
  39.         v = v - 1
  40.         vv = vv - 2
  41.         tilt = tilt - 2
  42.         speed = speed + 4
  43.     END IF
  44.     IF d = 4 AND speed <= 0 THEN
  45.         v = v + 1
  46.         vv = vv + 2
  47.         tilt = tilt + 2
  48.         speed = speed + 4
  49.     END IF
  50.     IF d = 5 THEN speed = speed + 4: b = 0
  51.     IF d = 6 THEN speed = speed + 4: b = 0
  52.  
  53.     IF tilt > 200 THEN tilt = 200
  54.     IF tilt < -200 THEN tilt = -200
  55.     IF (d = 3 OR d = 4 OR d = 5 OR d = 6) AND b = 0 THEN speed = speed + 1
  56.     IF (d = 3 OR d = 4) AND b = 1 THEN speed = speed - 1
  57.     IF e > 100 THEN e = 100
  58.     IF e < 0 THEN e = 0
  59.     elevation = e - 100
  60.     elevation = -elevation
  61.     elevation = elevation * 100
  62.     GOSUB grid:
  63.     IF speed2 < 0 THEN speed2 = 0
  64.     IF speed2 > 2000 THEN speed2 = 2000
  65.     delay = 2 / speed2
  66.     IF delay < .002 THEN delay = .002
  67.     IF delay > .02 THEN delay = .02
  68.     _DELAY delay
  69.  
  70.  
  71. grid:
  72. LINE (0, 299 - e - tilt)-(800, 299 - e + tilt), _RGB32(0, 0, 150)
  73. PAINT (400, 2), _RGB32(0, 0, 150)
  74. LINE (0, 300 - e - tilt)-(800, 300 - e + tilt), _RGB32(0, 155, 0)
  75. PAINT (400, 599), _RGB32(0, 155, 0)
  76.  
  77. LOCATE 1, 1: PRINT elevation
  78. LOCATE 2, 1: PRINT speed2
  79. 'Left vertical lines.
  80. FOR x = 395 - e TO -300 STEP -xs - xx - e
  81.     xx = xx + 5
  82.     IF v > 7 + e THEN v = -7
  83.     IF v < -7 THEN v = 7 + e
  84.     IF vv > 300 THEN vv = 300
  85.     IF vv < -300 THEN vv = -300
  86.     FOR findy = 0 TO 600
  87.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy = findy: GOTO nex:
  88.     NEXT findy
  89.     nex:
  90.     IF POINT(x - xx + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy) = _RGB32(0, 0, 150) THEN GOTO skip:
  91.     LINE (x + v - vv, yy)-(x - xx + v + vv, 600), _RGB32(255, 255, 255)
  92.     skip:
  93.  
  94. 'Right vertical lines.
  95. FOR x = 405 + e TO 1100 STEP xs + xx2 + e
  96.     xx2 = xx2 + 5
  97.     IF v > 7 + e THEN v = -7
  98.     IF v < -7 THEN v = 7 + e
  99.     IF vv > 300 THEN vv = 300
  100.     IF vv < -300 THEN vv = -300
  101.     FOR findy = 0 TO 600
  102.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy2 = findy: GOTO nex2:
  103.     NEXT findy
  104.     nex2:
  105.     IF POINT(x - xx2 + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy2) = _RGB32(0, 0, 150) THEN GOTO skip2:
  106.     LINE (x + v - vv, yy2)-(x + xx2 + v + vv, 600), _RGB32(255, 255, 255)
  107.     skip2:
  108.  
  109. 'Horizontal lines.
  110. FOR hy = 0 TO 600 STEP xs + xx3 + e
  111.     xx3 = xx3 + 5
  112.     IF speed > 7 + e THEN speed = -7
  113.     IF speed < -7 THEN speed = 7 + e
  114.     FOR findx = 0 TO 800
  115.         IF POINT(findx, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  116.             xx4 = findx
  117.         END IF
  118.     NEXT findx
  119.     FOR findx2 = 0 TO 800
  120.         IF POINT(findx2, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  121.             xx5 = findx2
  122.             LINE (xx4, hy + xx3 + speed)-(xx5, hy + xx3 + speed), _RGB32(255, 255, 255)
  123.             GOTO nex3:
  124.         END IF
  125.     NEXT findx2
  126.     nex3:
  127. NEXT hy
  128. xx = 0: xx2 = 0: xx3 = 0
  129.  
Title: Re: 3D Land Grid
Post by: DANILIN on May 21, 2020, 08:20:27 am
use pseudo 3d relief qb64 my milli program:

https://www.qb64.org/forum/index.php?topic=702.msg103948#msg103948

 
Title: Re: 3D Land Grid
Post by: SierraKen on May 21, 2020, 06:13:10 pm
I now have a Sun and Compass for when you fly. The Sun is in the West and moves when you turn. I also moved the air speed and altitude numbers to the bottom as well as the compass reading.
I'm having lots of fun with this. :D

Code: QB64: [Select]
  1. 'Flying - By SierraKen
  2. 'Made on May 21, 2020.
  3. 'V. 0.5 - Added Sun and Compass.
  4.  
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6. xs = 10
  7. GOSUB grid:
  8. c = 0
  9. e = 100
  10. _TITLE "Down arrow goes up. Up arrow goes down. + and - number pad keys are the accelerator. Left and Right keys turn."
  11.     _LIMIT 1000
  12.     a$ = INKEY$
  13.  
  14.     IF a$ = CHR$(0) + CHR$(72) THEN d = 6: e = e + .5: b = 0 'Up arrow key flies down.
  15.     IF a$ = CHR$(0) + CHR$(80) THEN d = 5: e = e - .5: b = 0 'Down arrow key flies up.
  16.     IF a$ = "+" THEN d = 1: speed2 = speed2 + 10
  17.     IF a$ = "-" THEN
  18.         speed2 = speed2 - 10
  19.         IF speed2 < 0 THEN speed = 0: b = 1: d = 0
  20.     END IF
  21.     IF a$ = CHR$(0) + CHR$(77) THEN d = 3 'Right
  22.     IF a$ = CHR$(0) + CHR$(75) THEN d = 4 'Left
  23.     IF a$ = " " THEN d = 0
  24.     IF a$ = CHR$(27) THEN END
  25.     IF d = 1 THEN speed = speed + 4: b = 0
  26.     IF d = 3 AND speed > 0 THEN
  27.         v = v - 1
  28.         vv = vv - 2
  29.         tilt = tilt - 2
  30.     END IF
  31.     IF d = 4 AND speed > 0 THEN
  32.         v = v + 1
  33.         vv = vv + 2
  34.         tilt = tilt + 2
  35.     END IF
  36.     IF d = 3 AND speed <= 0 THEN
  37.         v = v - 1
  38.         vv = vv - 2
  39.         tilt = tilt - 2
  40.         speed = speed + 4
  41.     END IF
  42.     IF d = 4 AND speed <= 0 THEN
  43.         v = v + 1
  44.         vv = vv + 2
  45.         tilt = tilt + 2
  46.         speed = speed + 4
  47.     END IF
  48.     IF d = 5 THEN speed = speed + 4: b = 0
  49.     IF d = 6 THEN speed = speed + 4: b = 0
  50.  
  51.     IF tilt > 200 THEN tilt = 200
  52.     IF tilt < -200 THEN tilt = -200
  53.     IF (d = 3 OR d = 4 OR d = 5 OR d = 6) AND b = 0 THEN speed = speed + 1
  54.     IF (d = 3 OR d = 4) AND b = 1 THEN speed = speed - 1
  55.     IF e > 100 THEN e = 100
  56.     IF e < 0 THEN e = 0
  57.     elevation = e - 100
  58.     elevation = -elevation
  59.     elevation = elevation * 100
  60.     GOSUB grid:
  61.     IF speed2 < 0 THEN speed2 = 0
  62.     IF speed2 > 2000 THEN speed2 = 2000
  63.     delay = 2 / speed2
  64.     IF delay < .002 THEN delay = .002
  65.     IF delay > .02 THEN delay = .02
  66.     _DELAY delay
  67.  
  68.  
  69. grid:
  70. LINE (0, 299 - e - tilt)-(800, 299 - e + tilt), _RGB32(0, 0, 150)
  71. PAINT (400, 2), _RGB32(0, 0, 150)
  72. LINE (0, 300 - e - tilt)-(800, 300 - e + tilt), _RGB32(0, 155, 0)
  73. PAINT (400, 599), _RGB32(0, 155, 0)
  74.  
  75. 'Calculate Compass
  76. tilt2 = tilt
  77. IF tilt2 < 0 THEN tilt2 = -tilt2
  78.  
  79. IF tilt < 0 THEN c = c - tilt2 / 314
  80. IF tilt > 0 THEN c = c + tilt2 / 314
  81. IF c > 359 THEN c = 0
  82. IF c < 0 THEN c = 359
  83. cc = INT(c)
  84. LOCATE 35, 1: PRINT "Compass:"; cc
  85.  
  86. 'Sun
  87. IF cc < 225 OR cc > 315 THEN til = 0: GOTO nosun:
  88. tilt3 = tilt / 50
  89. IF cc = 315 THEN sunx = 800
  90. IF cc = 225 THEN sunx = 0
  91. IF cc < 315 AND tilt < 0 AND tilt3 = oldtilt3 THEN sunx = sunx - 10: til = til - tilt3
  92. IF cc > 225 AND tilt > 0 AND tilt3 = oldtilt3 THEN sunx = sunx + 10: til = til + tilt3
  93. oldtilt3 = tilt3
  94. FOR sz = .25 TO 10 STEP .25
  95.     CIRCLE (sunx, til), sz, _RGB32(255, 255, 127)
  96. NEXT sz
  97. nosun:
  98.  
  99.  
  100. 'Left vertical lines.
  101. FOR x = 395 - e TO -300 STEP -xs - xx - e
  102.     xx = xx + 5
  103.     IF v > 7 + e THEN v = -7
  104.     IF v < -7 THEN v = 7 + e
  105.     IF vv > 300 THEN vv = 300
  106.     IF vv < -300 THEN vv = -300
  107.     FOR findy = 0 TO 600
  108.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy = findy: GOTO nex:
  109.     NEXT findy
  110.     nex:
  111.     IF POINT(x - xx + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy) = _RGB32(0, 0, 150) THEN GOTO skip:
  112.     LINE (x + v - vv, yy)-(x - xx + v + vv, 600), _RGB32(255, 255, 255)
  113.     skip:
  114.  
  115. 'Right vertical lines.
  116. FOR x = 405 + e TO 1100 STEP xs + xx2 + e
  117.     xx2 = xx2 + 5
  118.     IF v > 7 + e THEN v = -7
  119.     IF v < -7 THEN v = 7 + e
  120.     IF vv > 300 THEN vv = 300
  121.     IF vv < -300 THEN vv = -300
  122.     FOR findy = 0 TO 600
  123.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy2 = findy: GOTO nex2:
  124.     NEXT findy
  125.     nex2:
  126.     IF POINT(x - xx2 + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy2) = _RGB32(0, 0, 150) THEN GOTO skip2:
  127.     LINE (x + v - vv, yy2)-(x + xx2 + v + vv, 600), _RGB32(255, 255, 255)
  128.     skip2:
  129.  
  130. 'Horizontal lines.
  131. FOR hy = 0 TO 600 STEP xs + xx3 + e
  132.     xx3 = xx3 + 5
  133.     IF speed > 7 + e THEN speed = -7
  134.     IF speed < -7 THEN speed = 7 + e
  135.     FOR findx = 0 TO 800
  136.         IF POINT(findx, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  137.             xx4 = findx
  138.         END IF
  139.     NEXT findx
  140.     FOR findx2 = 0 TO 800
  141.         IF POINT(findx2, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  142.             xx5 = findx2
  143.             LINE (xx4, hy + xx3 + speed)-(xx5, hy + xx3 + speed), _RGB32(255, 255, 255)
  144.             GOTO nex3:
  145.         END IF
  146.     NEXT findx2
  147.     nex3:
  148. NEXT hy
  149. LOCATE 33, 1: PRINT "Altitude:"; elevation
  150. LOCATE 34, 1: PRINT "Airspeed:"; speed2
  151.  
  152. xx = 0: xx2 = 0: xx3 = 0
  153.  
  154.  

Title: Re: 3D Land Grid
Post by: OldMoses on May 22, 2020, 09:27:58 am
Cool, I use something similar in my spacecraft vectoring ap. When one is zoomed in on a local planetary system, the display shows a yellow ball icon on a "protractor ring" to orient that user as to the relative bearing to the primary star.
Title: Re: 3D Land Grid
Post by: SierraKen on May 22, 2020, 11:31:27 am
That's neat OldMoses. :) Yeah I had to make a whole new system for the compass and Sun. 
Title: Re: 3D Land Grid
Post by: SierraKen on May 22, 2020, 03:11:48 pm
I made a better 3D perspective as you fly higher and fixed the grid to keep going as you turn. I also reduced the air speed to a 500 limit to make the grid look better.

Code: QB64: [Select]
  1. 'Flying - By SierraKen
  2. 'Made on May 21, 2020.
  3. 'V. 0.5 - Added Sun and Compass.
  4.  
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6. xs = 10
  7. GOSUB grid:
  8. c = 0
  9. e = 100
  10. _TITLE "Down arrow goes up. Up arrow goes down. + and - number pad keys are the accelerator. Left and Right keys turn."
  11.     _LIMIT 1000
  12.     a$ = INKEY$
  13.  
  14.     IF a$ = CHR$(0) + CHR$(72) THEN d = 6: e = e + .5: b = 0 'Up arrow key flies down.
  15.     IF a$ = CHR$(0) + CHR$(80) THEN d = 5: e = e - .5: b = 0 'Down arrow key flies up.
  16.     IF a$ = "+" THEN d = 1: speed2 = speed2 + 10
  17.     IF a$ = "-" THEN
  18.         speed2 = speed2 - 10
  19.         IF speed2 < 0 THEN speed = 0: b = 1: d = 0
  20.     END IF
  21.     IF a$ = CHR$(0) + CHR$(77) THEN d = 3: speed2 = speed2 + .2 'Right
  22.     IF a$ = CHR$(0) + CHR$(75) THEN d = 4: speed2 = speed2 + .2 'Left
  23.     IF a$ = CHR$(27) THEN END
  24.     IF d = 1 THEN speed = speed + 2: b = 0
  25.     IF d = 3 AND speed > 0 THEN
  26.         v = v - 1
  27.         vv = vv - 2
  28.         tilt = tilt - 2
  29.     END IF
  30.     IF d = 4 AND speed > 0 THEN
  31.         v = v + 1
  32.         vv = vv + 2
  33.         tilt = tilt + 2
  34.     END IF
  35.     IF d = 3 AND speed <= 0 THEN
  36.         v = v - 1
  37.         vv = vv - 2
  38.         tilt = tilt - 2
  39.         speed = speed + 4
  40.     END IF
  41.     IF d = 4 AND speed <= 0 THEN
  42.         v = v + 1
  43.         vv = vv + 2
  44.         tilt = tilt + 2
  45.         speed = speed + 4
  46.     END IF
  47.     IF d = 5 OR speed2 > 0 THEN speed = speed + 1: b = 0
  48.     IF d = 6 OR speed2 > 0 THEN speed = speed + 1: b = 0
  49.  
  50.     IF tilt > 200 THEN tilt = 200
  51.     IF tilt < -200 THEN tilt = -200
  52.     IF (d = 3 OR d = 4 OR d = 5 OR d = 6) AND b = 0 THEN speed = speed + 1
  53.     IF (d = 3 OR d = 4) AND b = 1 THEN speed = speed - 1
  54.     IF e > 100 THEN e = 100
  55.     IF e < 0 THEN e = 0
  56.     elevation = e - 100
  57.     elevation = -elevation
  58.     elevation = elevation * 100
  59.     GOSUB grid:
  60.     IF speed2 < 0 THEN speed2 = 0
  61.     IF speed2 > 500 THEN speed2 = 500
  62.     delay = 2 / speed2
  63.     IF delay < .002 THEN delay = .002
  64.     IF delay > .02 THEN delay = .02
  65.     _DELAY delay
  66.  
  67.  
  68. grid:
  69. LINE (0, 299 - e - tilt)-(800, 299 - e + tilt), _RGB32(0, 0, 150)
  70. PAINT (400, 2), _RGB32(0, 0, 150)
  71. LINE (0, 300 - e - tilt)-(800, 300 - e + tilt), _RGB32(0, 155, 0)
  72. PAINT (400, 599), _RGB32(0, 155, 0)
  73.  
  74. 'Calculate Compass
  75. tilt2 = tilt
  76. IF tilt2 < 0 THEN tilt2 = -tilt2
  77.  
  78. IF tilt < 0 THEN c = c - tilt2 / 314
  79. IF tilt > 0 THEN c = c + tilt2 / 314
  80. IF c > 359 THEN c = 0
  81. IF c < 0 THEN c = 359
  82. cc = INT(c)
  83. LOCATE 35, 1: PRINT "Compass:"; cc
  84.  
  85. 'Sun
  86. IF cc < 225 OR cc > 315 THEN til = 0: GOTO nosun:
  87. tilt3 = tilt / 50
  88. IF cc = 315 THEN sunx = 800
  89. IF cc = 225 THEN sunx = 0
  90. IF cc < 315 AND tilt < 0 AND tilt3 = oldtilt3 THEN sunx = sunx - 10: til = til - tilt3
  91. IF cc > 225 AND tilt > 0 AND tilt3 = oldtilt3 THEN sunx = sunx + 10: til = til + tilt3
  92. oldtilt3 = tilt3
  93. FOR sz = .25 TO 10 STEP .25
  94.     CIRCLE (sunx, til), sz, _RGB32(255, 255, 127)
  95. NEXT sz
  96. nosun:
  97.  
  98.  
  99. 'Left vertical lines.
  100. FOR x = 395 - e TO -300 STEP -xs - xx - e
  101.     xx = xx + 55
  102.     IF v > 7 + e THEN v = -7
  103.     IF v < -7 THEN v = 7 + e
  104.     IF vv > 300 THEN vv = 300
  105.     IF vv < -300 THEN vv = -300
  106.     FOR findy = 0 TO 600
  107.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy = findy: GOTO nex:
  108.     NEXT findy
  109.     nex:
  110.     IF POINT(x - xx + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy) = _RGB32(0, 0, 150) THEN GOTO skip:
  111.     LINE (x + v - vv, yy)-(x - xx + v + vv, 600), _RGB32(255, 255, 255)
  112.     skip:
  113.  
  114. 'Right vertical lines.
  115. FOR x = 405 + e TO 1100 STEP xs + xx2 + e
  116.     xx2 = xx2 + 55
  117.     IF v > 7 + e THEN v = -7
  118.     IF v < -7 THEN v = 7 + e
  119.     IF vv > 300 THEN vv = 300
  120.     IF vv < -300 THEN vv = -300
  121.     FOR findy = 0 TO 600
  122.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy2 = findy: GOTO nex2:
  123.     NEXT findy
  124.     nex2:
  125.     IF POINT(x - xx2 + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy2) = _RGB32(0, 0, 150) THEN GOTO skip2:
  126.     LINE (x + v - vv, yy2)-(x + xx2 + v + vv, 600), _RGB32(255, 255, 255)
  127.     skip2:
  128.  
  129. 'Horizontal lines.
  130. FOR hy = 0 TO 600 STEP xs + xx3 + e
  131.     xx3 = xx3 + 5
  132.     IF speed > 7 + e THEN speed = -7
  133.     IF speed < -7 THEN speed = 7 + e
  134.     FOR findx = 0 TO 800
  135.         IF POINT(findx, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  136.             xx4 = findx
  137.         END IF
  138.     NEXT findx
  139.     FOR findx2 = 0 TO 800
  140.         IF POINT(findx2, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  141.             xx5 = findx2
  142.             LINE (xx4, hy + xx3 + speed)-(xx5, hy + xx3 + speed), _RGB32(255, 255, 255)
  143.             GOTO nex3:
  144.         END IF
  145.     NEXT findx2
  146.     nex3:
  147. NEXT hy
  148. LOCATE 33, 1: PRINT "Altitude:"; elevation
  149. LOCATE 34, 1: PRINT "Airspeed:"; INT(speed2)
  150.  
  151. xx = 0: xx2 = 0: xx3 = 0
  152.  
  153.