Author Topic: Flight Simulator  (Read 2204 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Flight Simulator
« on: May 25, 2020, 12:55:19 am »
I know I have another forum topic called: 3D Land Grid which eventually turned into flying. But I made this new topic to catch people's eyes better and knowing that it is in fact now a flight simulator. If you wish to see how that developed into flying, go here:
https://www.qb64.org/forum/index.php?topic=2609.0

This new topic will start off having a newer look at the compass, speed, and altitude bearings. I also added water and a lot of hills. Some things aren't perfect like the Sun going underground if you keep turning while in-view. I can't figure that part out yet. And sometimes the hills will go a bit higher than the land if you turn sharp and look at an edge of the screen. Plus the white grid goes off the land if you turn sharp as well, which I also could never figure out, but I think it looks cool so I kept it. There's no buildings or runways because making a set-map would be a bit beyond what I can do. So the hills and water are randomly generated. Anyways, I hope you enjoy this. I made it as an honor to 1980's flight simulators. :)

Code: QB64: [Select]
  1. 'Flying - By SierraKen
  2. 'Made on May 24, 2020.
  3. 'V. 0.6 - Added Better Compass and Relocated Speed and Altitude. Added Hills and Water.
  4.  
  5. DIM waterx(500), watery(500), shape(500), watersz(500)
  6. DIM hillx(500), hilly(500), hshape(500), hillsz(500), hcolor(500)
  7. SCREEN _NEWIMAGE(800, 600, 32)
  8. xs = 10
  9. c = 0
  10. e = 100
  11. _TITLE "Down arrow goes up. Up arrow goes down. + and - number pad keys are the accelerator. Left and Right keys turn."
  12.     _LIMIT 2000
  13.     a$ = INKEY$
  14.  
  15.     IF a$ = CHR$(0) + CHR$(72) THEN d = 6: e = e + .5: b = 0 'Up arrow key flies down.
  16.     IF a$ = CHR$(0) + CHR$(80) THEN d = 5: e = e - .5: b = 0 'Down arrow key flies up.
  17.     IF a$ = "+" THEN d = 1: speed2 = speed2 + 10
  18.     IF a$ = "-" THEN
  19.         speed2 = speed2 - 10
  20.     END IF
  21.     IF speed2 <= 0 THEN speed = 0: b = 1: d = 0
  22.     IF a$ = CHR$(0) + CHR$(77) THEN d = 3: speed2 = speed2 + .2 'Right
  23.     IF a$ = CHR$(0) + CHR$(75) THEN d = 4: speed2 = speed2 + .2 'Left
  24.     IF a$ = CHR$(27) THEN END
  25.     IF d = 1 THEN speed = speed + 2: 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 OR speed2 > 0 THEN speed = speed + 1: b = 0
  49.     IF d = 6 OR speed2 > 0 THEN speed = speed + 1: 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 > 500 THEN speed2 = 500
  63.     delay = 2 / speed2
  64.     IF delay < .002 THEN delay = .002
  65.     IF delay > .02 THEN delay = .02
  66.     _DELAY delay
  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. IF cc >= 340 OR cc < 25 THEN comp$ = "North"
  84. IF cc >= 25 AND cc < 65 THEN comp$ = "Northeast"
  85. IF cc >= 65 AND cc < 115 THEN comp$ = "East"
  86. IF cc >= 115 AND cc < 160 THEN comp$ = "Southeast"
  87. IF cc >= 160 AND cc < 205 THEN comp$ = "South"
  88. IF cc >= 205 AND cc < 250 THEN comp$ = "Southwest"
  89. IF cc >= 250 AND cc < 295 THEN comp$ = "West"
  90. IF cc >= 295 AND cc < 340 THEN comp$ = "Northwest"
  91. _PRINTSTRING (390, 550), comp$
  92. cc$ = STR$(cc)
  93. _PRINTSTRING (395, 570), cc$
  94.  
  95. 'Sun
  96. IF cc < 225 OR cc > 315 THEN til = 0: GOTO nosun:
  97. tilt3 = tilt / 50
  98. IF cc = 315 THEN sunx = 800
  99. IF cc = 225 THEN sunx = 0
  100. IF cc < 315 AND tilt < 0 AND tilt3 = oldtilt3 THEN sunx = sunx - 10: til = til - tilt3
  101. IF cc > 225 AND tilt > 0 AND tilt3 = oldtilt3 THEN sunx = sunx + 10: til = til + tilt3
  102. oldtilt3 = tilt3
  103. FOR sz = .25 TO 10 STEP .25
  104.     CIRCLE (sunx, til), sz, _RGB32(255, 255, 127)
  105. NEXT sz
  106. nosun:
  107.  
  108. 'Water
  109. water = INT(RND * 200) + 1
  110. IF water > 197 THEN
  111.     w = w + 1
  112.     IF w > 100 THEN w = 1
  113.     waterx(w) = INT(RND * 799) + 1
  114.     watery(w) = 310
  115.     watersz(w) = INT(RND * 5) + 1 + e / 1.5
  116.     shape(w) = (RND - .35)
  117. IF w = 0 THEN GOTO skipwater2:
  118. FOR ww = 1 TO w
  119.     watery(ww) = watery(ww) + speed2 / 125
  120.     tilt4 = tilt / 5
  121.     IF tilt4 < 0 THEN tilt4 = -tilt4
  122.     watery(ww) = watery(ww) + tilt4 / 10
  123.     IF watery(ww) > 650 THEN GOTO skipwater:
  124.     ttilt = tilt / 10
  125.     IF ttilt > 6 THEN ttilt = 6
  126.     IF ttilt < -6 THEN ttilt = -6
  127.     waterx(ww) = waterx(ww) + ttilt
  128.     IF waterx(ww) < -50 OR waterx(ww) > 850 THEN GOTO skipwater:
  129.     IF POINT(waterx(ww), watery(ww)) = _RGB32(0, 0, 150) THEN GOTO skipwater:
  130.     FOR sz = .25 TO watersz(ww) STEP .25
  131.         CIRCLE (waterx(ww), watery(ww)), sz, _RGB32(100, 100, 255), , , shape(ww)
  132.     NEXT sz
  133.     skipwater:
  134. NEXT ww
  135. skipwater2:
  136.  
  137. 'Hills
  138. IF d = 0 THEN GOTO skiphill2:
  139. hills = INT(RND * 200) + 1
  140. IF hills > 150 THEN
  141.     h = h + 1
  142.     IF h > 300 THEN h = 1
  143.     hillx(h) = INT(RND * 799) + 1
  144.     hilly(h) = 310
  145.     hillsz(h) = INT(RND * 5) + 1 + e / 1.5
  146.     hshape(h) = (RND - .35)
  147.     hcolor(h) = INT(RND * 100) + 100
  148. IF h = 0 THEN GOTO skiphill2:
  149. l = l + 1
  150. FOR hh = 1 TO h
  151.     IF speed2 > 0 THEN hilly(hh) = hilly(hh) + speed2 / 125
  152.     tilt5 = tilt / 5
  153.     IF tilt5 < 0 THEN tilt5 = -tilt5
  154.     hilly(hh) = hilly(hh) + tilt5 / 10
  155.     IF hilly(hh) > 650 THEN GOTO skiphill:
  156.     tttilt = tilt / 10
  157.     IF tttilt > 6 THEN tttilt = 6
  158.     IF tttilt < -6 THEN tttilt = -6
  159.     hillx(hh) = hillx(hh) + tttilt
  160.     IF hillx(hh) < -50 OR hillx(hh) > 850 THEN GOTO skiphill:
  161.     IF POINT(hillx(hh), hilly(hh)) = _RGB32(0, 0, 150) THEN GOTO skiphill:
  162.     FOR sz = .25 TO hillsz(hh) STEP .25
  163.         CIRCLE (hillx(hh), hilly(hh)), sz, _RGB32(hcolor(hh) + 44, hcolor(hh), 0), , , hshape(hh)
  164.     NEXT sz
  165.     skiphill:
  166. NEXT hh
  167. skiphill2:
  168.  
  169. 'Left vertical lines.
  170. FOR x = 395 - e TO -300 STEP -xs - xx - e
  171.     xx = xx + 55
  172.     IF v > 7 + e THEN v = -7
  173.     IF v < -7 THEN v = 7 + e
  174.     IF vv > 300 THEN vv = 300
  175.     IF vv < -300 THEN vv = -300
  176.     FOR findy = 0 TO 600
  177.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy = findy: GOTO nex:
  178.     NEXT findy
  179.     nex:
  180.     IF POINT(x - xx + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy) = _RGB32(0, 0, 150) THEN GOTO skip:
  181.     LINE (x + v - vv, yy)-(x - xx + v + vv, 600), _RGB32(255, 255, 255)
  182.     skip:
  183.  
  184. 'Right vertical lines.
  185. FOR x = 405 + e TO 1100 STEP xs + xx2 + e
  186.     xx2 = xx2 + 55
  187.     IF v > 7 + e THEN v = -7
  188.     IF v < -7 THEN v = 7 + e
  189.     IF vv > 300 THEN vv = 300
  190.     IF vv < -300 THEN vv = -300
  191.     FOR findy = 0 TO 600
  192.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy2 = findy: GOTO nex2:
  193.     NEXT findy
  194.     nex2:
  195.     IF POINT(x - xx2 + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy2) = _RGB32(0, 0, 150) THEN GOTO skip2:
  196.     LINE (x + v - vv, yy2)-(x + xx2 + v + vv, 600), _RGB32(255, 255, 255)
  197.     skip2:
  198.  
  199. 'Horizontal lines.
  200. FOR hy = 0 TO 600 STEP xs + xx3 + e
  201.     xx3 = xx3 + 5
  202.     IF speed > 7 + e THEN speed = -7
  203.     IF speed < -7 THEN speed = 7 + e
  204.     FOR findx = 0 TO 800
  205.         IF POINT(findx, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  206.             xx4 = findx
  207.         END IF
  208.     NEXT findx
  209.     FOR findx2 = 0 TO 800
  210.         IF POINT(findx2, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  211.             xx5 = findx2
  212.             LINE (xx4, hy + xx3 + speed)-(xx5, hy + xx3 + speed), _RGB32(255, 255, 255)
  213.             GOTO nex3:
  214.         END IF
  215.     NEXT findx2
  216.     nex3:
  217. NEXT hy
  218. _PRINTSTRING (250, 550), "Altitude"
  219. elevation$ = STR$(elevation)
  220. _PRINTSTRING (255, 570), elevation$
  221.  
  222. _PRINTSTRING (530, 550), "Airspeed"
  223. speed2 = INT(speed2)
  224. speed2$ = STR$(speed2)
  225. _PRINTSTRING (535, 570), speed2$
  226.  
  227. xx = 0: xx2 = 0: xx3 = 0
  228. l = l + 1
  229.  

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Flight Simulator
« Reply #1 on: May 25, 2020, 08:17:08 am »
I put a couple _PRINTMODE _KEEPBACKGROUND just after lines 93 & 232 (before your _PRINTSTRINGs) to keep the data on top of things. The little black boxes and disappearing numbers tweak my OCD.... ;)

Offline 40wattstudio

  • Newbie
  • Posts: 82
    • View Profile
    • 40wattstudio
Re: Flight Simulator
« Reply #2 on: May 25, 2020, 10:00:01 am »
What, only 245 lines of code?! Wow, that's amazing! Banking left and right reminds me a little of playing F-15 Strike Eagle for the NES (and other similar games).

I'm curious how you figured out how to do all the math for all this, that's the part I'd get stuck on.

Good job SierraKen!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Flight Simulator
« Reply #3 on: May 25, 2020, 12:46:50 pm »
Thanks OldMoses! I had no idea that those commands existed! Here is the updated code with the those commands. :)

Code: QB64: [Select]
  1. 'Flying - By SierraKen
  2. 'Made on May 24, 2020.
  3. 'V. 0.6 - Added Better Compass and Relocated Speed and Altitude. Added Hills and Water.
  4.  
  5. DIM waterx(500), watery(500), shape(500), watersz(500)
  6. DIM hillx(500), hilly(500), hshape(500), hillsz(500), hcolor(500)
  7. SCREEN _NEWIMAGE(800, 600, 32)
  8. xs = 10
  9. c = 0
  10. e = 100
  11. _TITLE "Down arrow goes up. Up arrow goes down. + and - number pad keys are the accelerator. Left and Right keys turn."
  12.     _LIMIT 2000
  13.     a$ = INKEY$
  14.  
  15.     IF a$ = CHR$(0) + CHR$(72) THEN d = 6: e = e + .5: b = 0 'Up arrow key flies down.
  16.     IF a$ = CHR$(0) + CHR$(80) THEN d = 5: e = e - .5: b = 0 'Down arrow key flies up.
  17.     IF a$ = "+" THEN d = 1: speed2 = speed2 + 10
  18.     IF a$ = "-" THEN
  19.         speed2 = speed2 - 10
  20.     END IF
  21.     IF speed2 <= 0 THEN speed = 0: b = 1: d = 0
  22.     IF a$ = CHR$(0) + CHR$(77) THEN d = 3: speed2 = speed2 + .2 'Right
  23.     IF a$ = CHR$(0) + CHR$(75) THEN d = 4: speed2 = speed2 + .2 'Left
  24.     IF a$ = CHR$(27) THEN END
  25.     IF d = 1 THEN speed = speed + 2: 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 OR speed2 > 0 THEN speed = speed + 1: b = 0
  49.     IF d = 6 OR speed2 > 0 THEN speed = speed + 1: 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 > 500 THEN speed2 = 500
  63.     delay = 2 / speed2
  64.     IF delay < .002 THEN delay = .002
  65.     IF delay > .02 THEN delay = .02
  66.     _DELAY delay
  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. IF cc >= 340 OR cc < 25 THEN comp$ = "North"
  84. IF cc >= 25 AND cc < 65 THEN comp$ = "Northeast"
  85. IF cc >= 65 AND cc < 115 THEN comp$ = "East"
  86. IF cc >= 115 AND cc < 160 THEN comp$ = "Southeast"
  87. IF cc >= 160 AND cc < 205 THEN comp$ = "South"
  88. IF cc >= 205 AND cc < 250 THEN comp$ = "Southwest"
  89. IF cc >= 250 AND cc < 295 THEN comp$ = "West"
  90. IF cc >= 295 AND cc < 340 THEN comp$ = "Northwest"
  91. _PRINTSTRING (390, 550), comp$
  92. cc$ = STR$(cc)
  93. _PRINTSTRING (395, 570), cc$
  94.  
  95. 'Sun
  96. IF cc < 225 OR cc > 315 THEN til = 0: GOTO nosun:
  97. tilt3 = tilt / 50
  98. IF cc = 315 THEN sunx = 800
  99. IF cc = 225 THEN sunx = 0
  100. IF cc < 315 AND tilt < 0 AND tilt3 = oldtilt3 THEN sunx = sunx - 10: til = til - tilt3
  101. IF cc > 225 AND tilt > 0 AND tilt3 = oldtilt3 THEN sunx = sunx + 10: til = til + tilt3
  102. oldtilt3 = tilt3
  103. FOR sz = .25 TO 10 STEP .25
  104.     CIRCLE (sunx, til), sz, _RGB32(255, 255, 127)
  105. NEXT sz
  106. nosun:
  107.  
  108. 'Water
  109. water = INT(RND * 200) + 1
  110. IF water > 197 THEN
  111.     w = w + 1
  112.     IF w > 100 THEN w = 1
  113.     waterx(w) = INT(RND * 799) + 1
  114.     watery(w) = 310
  115.     watersz(w) = INT(RND * 5) + 1 + e / 1.5
  116.     shape(w) = (RND - .35)
  117. IF w = 0 THEN GOTO skipwater2:
  118. FOR ww = 1 TO w
  119.     watery(ww) = watery(ww) + speed2 / 125
  120.     tilt4 = tilt / 5
  121.     IF tilt4 < 0 THEN tilt4 = -tilt4
  122.     watery(ww) = watery(ww) + tilt4 / 10
  123.     IF watery(ww) > 650 THEN GOTO skipwater:
  124.     ttilt = tilt / 10
  125.     IF ttilt > 6 THEN ttilt = 6
  126.     IF ttilt < -6 THEN ttilt = -6
  127.     waterx(ww) = waterx(ww) + ttilt
  128.     IF waterx(ww) < -50 OR waterx(ww) > 850 THEN GOTO skipwater:
  129.     IF POINT(waterx(ww), watery(ww)) = _RGB32(0, 0, 150) THEN GOTO skipwater:
  130.     FOR sz = .25 TO watersz(ww) STEP .25
  131.         CIRCLE (waterx(ww), watery(ww)), sz, _RGB32(100, 100, 255), , , shape(ww)
  132.     NEXT sz
  133.     skipwater:
  134. NEXT ww
  135. skipwater2:
  136.  
  137. 'Hills
  138. IF d = 0 THEN GOTO skiphill2:
  139. hills = INT(RND * 200) + 1
  140. IF hills > 150 THEN
  141.     h = h + 1
  142.     IF h > 300 THEN h = 1
  143.     hillx(h) = INT(RND * 799) + 1
  144.     hilly(h) = 310
  145.     hillsz(h) = INT(RND * 5) + 1 + e / 1.5
  146.     hshape(h) = (RND - .35)
  147.     hcolor(h) = INT(RND * 100) + 100
  148. IF h = 0 THEN GOTO skiphill2:
  149. l = l + 1
  150. FOR hh = 1 TO h
  151.     IF speed2 > 0 THEN hilly(hh) = hilly(hh) + speed2 / 125
  152.     tilt5 = tilt / 5
  153.     IF tilt5 < 0 THEN tilt5 = -tilt5
  154.     hilly(hh) = hilly(hh) + tilt5 / 10
  155.     IF hilly(hh) > 650 THEN GOTO skiphill:
  156.     tttilt = tilt / 10
  157.     IF tttilt > 6 THEN tttilt = 6
  158.     IF tttilt < -6 THEN tttilt = -6
  159.     hillx(hh) = hillx(hh) + tttilt
  160.     IF hillx(hh) < -50 OR hillx(hh) > 850 THEN GOTO skiphill:
  161.     IF POINT(hillx(hh), hilly(hh)) = _RGB32(0, 0, 150) THEN GOTO skiphill:
  162.     FOR sz = .25 TO hillsz(hh) STEP .25
  163.         CIRCLE (hillx(hh), hilly(hh)), sz, _RGB32(hcolor(hh) + 44, hcolor(hh), 0), , , hshape(hh)
  164.     NEXT sz
  165.     skiphill:
  166. NEXT hh
  167. skiphill2:
  168.  
  169. 'Left vertical lines.
  170. FOR x = 395 - e TO -300 STEP -xs - xx - e
  171.     xx = xx + 55
  172.     IF v > 7 + e THEN v = -7
  173.     IF v < -7 THEN v = 7 + e
  174.     IF vv > 300 THEN vv = 300
  175.     IF vv < -300 THEN vv = -300
  176.     FOR findy = 0 TO 600
  177.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy = findy: GOTO nex:
  178.     NEXT findy
  179.     nex:
  180.     IF POINT(x - xx + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy) = _RGB32(0, 0, 150) THEN GOTO skip:
  181.     LINE (x + v - vv, yy)-(x - xx + v + vv, 600), _RGB32(255, 255, 255)
  182.     skip:
  183.  
  184. 'Right vertical lines.
  185. FOR x = 405 + e TO 1100 STEP xs + xx2 + e
  186.     xx2 = xx2 + 55
  187.     IF v > 7 + e THEN v = -7
  188.     IF v < -7 THEN v = 7 + e
  189.     IF vv > 300 THEN vv = 300
  190.     IF vv < -300 THEN vv = -300
  191.     FOR findy = 0 TO 600
  192.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy2 = findy: GOTO nex2:
  193.     NEXT findy
  194.     nex2:
  195.     IF POINT(x - xx2 + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy2) = _RGB32(0, 0, 150) THEN GOTO skip2:
  196.     LINE (x + v - vv, yy2)-(x + xx2 + v + vv, 600), _RGB32(255, 255, 255)
  197.     skip2:
  198.  
  199. 'Horizontal lines.
  200. FOR hy = 0 TO 600 STEP xs + xx3 + e
  201.     xx3 = xx3 + 5
  202.     IF speed > 7 + e THEN speed = -7
  203.     IF speed < -7 THEN speed = 7 + e
  204.     FOR findx = 0 TO 800
  205.         IF POINT(findx, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  206.             xx4 = findx
  207.         END IF
  208.     NEXT findx
  209.     FOR findx2 = 0 TO 800
  210.         IF POINT(findx2, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  211.             xx5 = findx2
  212.             LINE (xx4, hy + xx3 + speed)-(xx5, hy + xx3 + speed), _RGB32(255, 255, 255)
  213.             GOTO nex3:
  214.         END IF
  215.     NEXT findx2
  216.     nex3:
  217. NEXT hy
  218. _PRINTSTRING (250, 550), "Altitude"
  219. elevation$ = STR$(elevation)
  220. _PRINTSTRING (255, 570), elevation$
  221.  
  222. _PRINTSTRING (530, 550), "Airspeed"
  223. speed2 = INT(speed2)
  224. speed2$ = STR$(speed2)
  225. _PRINTSTRING (535, 570), speed2$
  226.  
  227. xx = 0: xx2 = 0: xx3 = 0
  228. l = l + 1
  229.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Flight Simulator
« Reply #4 on: May 25, 2020, 12:49:15 pm »
Thanks 40wattstudio. There isn't too much math involved with the grid as you might think. I used POINT commands to stop the LINE commands from going into the sky, which detects colors. And the grid is just a bunch of LINE commands. :) Feel free to learn with any code here on the forum, that's one reason why we post it. :) I do have to say though that some of my code is a bit messy in the fact that I did a lot of trial and error. lol

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Flight Simulator
« Reply #5 on: May 25, 2020, 06:07:36 pm »
Cool... A flight Sim. Haven't used one of those since Micro$oft's Flight Sim 4....

No pressure, but I have a usb joystick, gathering dust on my shelf... lol
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Flight Simulator
« Reply #6 on: May 25, 2020, 06:18:02 pm »
LOL Johno.

Here's a small update again, this time with added clouds.

Code: QB64: [Select]
  1. 'Flying - By SierraKen
  2. 'Made on May 25, 2020.
  3. 'V. 0.7 - Added Clouds.
  4.  
  5. DIM waterx(500), watery(500), shape(500), watersz(500)
  6. DIM hillx(500), hilly(500), hshape(500), hillsz(500), hcolor(500)
  7. DIM cloudx(500), cloudy(500), shapecl(500), cloudsz(500)
  8. SCREEN _NEWIMAGE(800, 600, 32)
  9. xs = 10
  10. c = 0
  11. e = 100
  12. _TITLE "Down arrow goes up. Up arrow goes down. + and - number pad keys are the accelerator. Left and Right keys turn."
  13.     _LIMIT 2000
  14.     a$ = INKEY$
  15.  
  16.     IF a$ = CHR$(0) + CHR$(72) THEN d = 6: e = e + .5: b = 0 'Up arrow key flies down.
  17.     IF a$ = CHR$(0) + CHR$(80) THEN d = 5: e = e - .5: b = 0 'Down arrow key flies up.
  18.     IF a$ = "+" THEN d = 1: speed2 = speed2 + 10
  19.     IF a$ = "-" THEN
  20.         speed2 = speed2 - 10
  21.     END IF
  22.     IF speed2 <= 0 THEN speed = 0: b = 1: d = 0
  23.     IF a$ = CHR$(0) + CHR$(77) THEN d = 3: speed2 = speed2 + .2 'Right
  24.     IF a$ = CHR$(0) + CHR$(75) THEN d = 4: speed2 = speed2 + .2 'Left
  25.     IF a$ = CHR$(27) THEN END
  26.     IF d = 1 THEN speed = speed + 2: b = 0
  27.     IF d = 3 AND speed > 0 THEN
  28.         v = v - 1
  29.         vv = vv - 2
  30.         tilt = tilt - 2
  31.     END IF
  32.     IF d = 4 AND speed > 0 THEN
  33.         v = v + 1
  34.         vv = vv + 2
  35.         tilt = tilt + 2
  36.     END IF
  37.     IF d = 3 AND speed <= 0 THEN
  38.         v = v - 1
  39.         vv = vv - 2
  40.         tilt = tilt - 2
  41.         speed = speed + 4
  42.     END IF
  43.     IF d = 4 AND speed <= 0 THEN
  44.         v = v + 1
  45.         vv = vv + 2
  46.         tilt = tilt + 2
  47.         speed = speed + 4
  48.     END IF
  49.     IF d = 5 OR speed2 > 0 THEN speed = speed + 1: b = 0
  50.     IF d = 6 OR speed2 > 0 THEN speed = speed + 1: b = 0
  51.  
  52.     IF tilt > 200 THEN tilt = 200
  53.     IF tilt < -200 THEN tilt = -200
  54.     IF (d = 3 OR d = 4 OR d = 5 OR d = 6) AND b = 0 THEN speed = speed + 1
  55.     IF (d = 3 OR d = 4) AND b = 1 THEN speed = speed - 1
  56.     IF e > 100 THEN e = 100
  57.     IF e < 0 THEN e = 0
  58.     elevation = e - 100
  59.     elevation = -elevation
  60.     elevation = elevation * 100
  61.     GOSUB grid:
  62.     IF speed2 < 0 THEN speed2 = 0
  63.     IF speed2 > 500 THEN speed2 = 500
  64.     delay = 2 / speed2
  65.     IF delay < .002 THEN delay = .002
  66.     IF delay > .02 THEN delay = .02
  67.     _DELAY delay
  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. IF cc >= 340 OR cc < 25 THEN comp$ = "North"
  85. IF cc >= 25 AND cc < 65 THEN comp$ = "Northeast"
  86. IF cc >= 65 AND cc < 115 THEN comp$ = "East"
  87. IF cc >= 115 AND cc < 160 THEN comp$ = "Southeast"
  88. IF cc >= 160 AND cc < 205 THEN comp$ = "South"
  89. IF cc >= 205 AND cc < 250 THEN comp$ = "Southwest"
  90. IF cc >= 250 AND cc < 295 THEN comp$ = "West"
  91. IF cc >= 295 AND cc < 340 THEN comp$ = "Northwest"
  92. _PRINTSTRING (390, 550), comp$
  93. cc$ = STR$(cc)
  94. _PRINTSTRING (395, 570), cc$
  95.  
  96. 'Sun
  97. IF cc < 225 OR cc > 315 THEN til = 0: GOTO nosun:
  98. tilt3 = tilt / 50
  99. IF cc = 315 THEN sunx = 800
  100. IF cc = 225 THEN sunx = 0
  101. IF cc < 315 AND tilt < 0 AND tilt3 = oldtilt3 THEN sunx = sunx - 10: til = til - tilt3
  102. IF cc > 225 AND tilt > 0 AND tilt3 = oldtilt3 THEN sunx = sunx + 10: til = til + tilt3
  103. oldtilt3 = tilt3
  104. FOR sz = .25 TO 10 STEP .25
  105.     CIRCLE (sunx, til), sz, _RGB32(255, 255, 127)
  106. NEXT sz
  107. nosun:
  108.  
  109. 'Clouds
  110. clouds = INT(RND * 200) + 1
  111. IF clouds > 190 THEN
  112.     cl = cl + 1
  113.     IF cl > 100 THEN cl = 1
  114.     cloudx(cl) = INT(RND * 799) + 1
  115.     cloudy(cl) = 200
  116.     cloudsz(cl) = INT(RND * 5) + 1 + e / 2
  117.     shapecl(cl) = (RND - .35)
  118. IF cl = 0 THEN GOTO skipclouds2:
  119. FOR cl2 = 1 TO cl
  120.     cloudy(cl2) = cloudy(cl2) - speed2 / 125
  121.     tilt6 = tilt / 5
  122.     IF tilt6 < 0 THEN tilt6 = -tilt6
  123.     cloudy(cl2) = cloudy(cl2) + tilt6 / 10
  124.     IF cloudy(cl2) < -50 THEN GOTO skipclouds:
  125.     ttttilt = tilt / 10
  126.     IF ttttilt > 6 THEN ttttilt = 6
  127.     IF ttttilt < -6 THEN ttttilt = -6
  128.     cloudx(cl2) = cloudx(cl2) + ttttilt
  129.     IF cloudx(cl2) < -50 OR cloudx(cl2) > 850 THEN GOTO skipclouds:
  130.     FOR sz = .25 TO cloudsz(cl2) STEP .25
  131.         CIRCLE (cloudx(cl2), cloudy(cl2)), sz, _RGB32(255, 255, 255), , , shapecl(cl2)
  132.     NEXT sz
  133.     skipclouds:
  134. NEXT cl2
  135. skipclouds2:
  136.  
  137.  
  138.  
  139. 'Water
  140. water = INT(RND * 200) + 1
  141. IF water > 197 THEN
  142.     w = w + 1
  143.     IF w > 100 THEN w = 1
  144.     waterx(w) = INT(RND * 799) + 1
  145.     watery(w) = 310
  146.     watersz(w) = INT(RND * 5) + 1 + e / 1.5
  147.     shape(w) = (RND - .35)
  148. IF w = 0 THEN GOTO skipwater2:
  149. FOR ww = 1 TO w
  150.     watery(ww) = watery(ww) + speed2 / 125
  151.     tilt4 = tilt / 5
  152.     IF tilt4 < 0 THEN tilt4 = -tilt4
  153.     watery(ww) = watery(ww) + tilt4 / 10
  154.     IF watery(ww) > 650 THEN GOTO skipwater:
  155.     ttilt = tilt / 10
  156.     IF ttilt > 6 THEN ttilt = 6
  157.     IF ttilt < -6 THEN ttilt = -6
  158.     waterx(ww) = waterx(ww) + ttilt
  159.     IF waterx(ww) < -50 OR waterx(ww) > 850 THEN GOTO skipwater:
  160.     IF POINT(waterx(ww), watery(ww)) = _RGB32(0, 0, 150) THEN GOTO skipwater:
  161.     FOR sz = .25 TO watersz(ww) STEP .25
  162.         CIRCLE (waterx(ww), watery(ww)), sz, _RGB32(100, 100, 255), , , shape(ww)
  163.     NEXT sz
  164.     skipwater:
  165. NEXT ww
  166. skipwater2:
  167.  
  168. 'Hills
  169. IF d = 0 THEN GOTO skiphill2:
  170. hills = INT(RND * 200) + 1
  171. IF hills > 150 THEN
  172.     h = h + 1
  173.     IF h > 300 THEN h = 1
  174.     hillx(h) = INT(RND * 799) + 1
  175.     hilly(h) = 310
  176.     hillsz(h) = INT(RND * 5) + 1 + e / 1.5
  177.     hshape(h) = (RND - .35)
  178.     hcolor(h) = INT(RND * 100) + 100
  179. IF h = 0 THEN GOTO skiphill2:
  180. l = l + 1
  181. FOR hh = 1 TO h
  182.     IF speed2 > 0 THEN hilly(hh) = hilly(hh) + speed2 / 125
  183.     tilt5 = tilt / 5
  184.     IF tilt5 < 0 THEN tilt5 = -tilt5
  185.     hilly(hh) = hilly(hh) + tilt5 / 10
  186.     IF hilly(hh) > 650 THEN GOTO skiphill:
  187.     tttilt = tilt / 10
  188.     IF tttilt > 6 THEN tttilt = 6
  189.     IF tttilt < -6 THEN tttilt = -6
  190.     hillx(hh) = hillx(hh) + tttilt
  191.     IF hillx(hh) < -50 OR hillx(hh) > 850 THEN GOTO skiphill:
  192.     IF POINT(hillx(hh), hilly(hh)) = _RGB32(0, 0, 150) THEN GOTO skiphill:
  193.     FOR sz = .25 TO hillsz(hh) STEP .25
  194.         CIRCLE (hillx(hh), hilly(hh)), sz, _RGB32(hcolor(hh) + 44, hcolor(hh), 0), , , hshape(hh)
  195.     NEXT sz
  196.     skiphill:
  197. NEXT hh
  198. skiphill2:
  199.  
  200. 'Left vertical lines.
  201. FOR x = 395 - e TO -300 STEP -xs - xx - e
  202.     xx = xx + 55
  203.     IF v > 7 + e THEN v = -7
  204.     IF v < -7 THEN v = 7 + e
  205.     IF vv > 300 THEN vv = 300
  206.     IF vv < -300 THEN vv = -300
  207.     FOR findy = 0 TO 600
  208.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy = findy: GOTO nex:
  209.     NEXT findy
  210.     nex:
  211.     IF POINT(x - xx + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy) = _RGB32(0, 0, 150) THEN GOTO skip:
  212.     LINE (x + v - vv, yy)-(x - xx + v + vv, 600), _RGB32(255, 255, 255)
  213.     skip:
  214.  
  215. 'Right vertical lines.
  216. FOR x = 405 + e TO 1100 STEP xs + xx2 + e
  217.     xx2 = xx2 + 55
  218.     IF v > 7 + e THEN v = -7
  219.     IF v < -7 THEN v = 7 + e
  220.     IF vv > 300 THEN vv = 300
  221.     IF vv < -300 THEN vv = -300
  222.     FOR findy = 0 TO 600
  223.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy2 = findy: GOTO nex2:
  224.     NEXT findy
  225.     nex2:
  226.     IF POINT(x - xx2 + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy2) = _RGB32(0, 0, 150) THEN GOTO skip2:
  227.     LINE (x + v - vv, yy2)-(x + xx2 + v + vv, 600), _RGB32(255, 255, 255)
  228.     skip2:
  229.  
  230. 'Horizontal lines.
  231. FOR hy = 0 TO 600 STEP xs + xx3 + e
  232.     xx3 = xx3 + 5
  233.     IF speed > 7 + e THEN speed = -7
  234.     IF speed < -7 THEN speed = 7 + e
  235.     FOR findx = 0 TO 800
  236.         IF POINT(findx, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  237.             xx4 = findx
  238.         END IF
  239.     NEXT findx
  240.     FOR findx2 = 0 TO 800
  241.         IF POINT(findx2, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  242.             xx5 = findx2
  243.             LINE (xx4, hy + xx3 + speed)-(xx5, hy + xx3 + speed), _RGB32(255, 255, 255)
  244.             GOTO nex3:
  245.         END IF
  246.     NEXT findx2
  247.     nex3:
  248. NEXT hy
  249. _PRINTSTRING (250, 550), "Altitude"
  250. elevation$ = STR$(elevation)
  251. _PRINTSTRING (255, 570), elevation$
  252.  
  253. _PRINTSTRING (530, 550), "Airspeed"
  254. speed2 = INT(speed2)
  255. speed2$ = STR$(speed2)
  256. _PRINTSTRING (535, 570), speed2$
  257.  
  258. xx = 0: xx2 = 0: xx3 = 0
  259. l = l + 1
  260.  

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Flight Simulator
« Reply #7 on: May 26, 2020, 04:19:15 am »
This might sound a little stupid....  Parallax starfields in space shooters would be coloured based on speed. The slower the darker, the faster the brighter. Can a similar principle be applied to the colour of the clouds. The 'closer' the cloud the brighter. Might help out with "depth perception". No idea as to how to do that... Just a thought.
« Last Edit: May 26, 2020, 04:20:34 am by johnno56 »
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Flight Simulator
« Reply #8 on: May 26, 2020, 02:22:18 pm »
Great idea Johno, thanks! I made the clouds have 7 different shades of gray going to white as they get closer to you. I just used IF/THEN statements on the cloudy(cl2) vertical variable on them. The higher they are, the closer to you, and the less gray they get.

P.S. Anyone seen B+ lately? Hope he didn't take off like I did a few months ago. I apologize for doing that without saying a word. I should have said something at least.

Code: QB64: [Select]
  1. 'Flying - By SierraKen
  2. 'Made on May 26, 2020.
  3. 'V. 0.8 - Added cloud color shades.
  4.  
  5. DIM waterx(500), watery(500), shape(500), watersz(500)
  6. DIM hillx(500), hilly(500), hshape(500), hillsz(500), hcolor(500)
  7. DIM cloudx(500), cloudy(500), shapecl(500), cloudsz(500)
  8. SCREEN _NEWIMAGE(800, 600, 32)
  9. xs = 10
  10. c = 0
  11. e = 100
  12. _TITLE "Down arrow goes up. Up arrow goes down. + and - number pad keys are the accelerator. Left and Right keys turn."
  13.     _LIMIT 2000
  14.     a$ = INKEY$
  15.  
  16.     IF a$ = CHR$(0) + CHR$(72) THEN d = 6: e = e + .5: b = 0 'Up arrow key flies down.
  17.     IF a$ = CHR$(0) + CHR$(80) THEN d = 5: e = e - .5: b = 0 'Down arrow key flies up.
  18.     IF a$ = "+" THEN d = 1: speed2 = speed2 + 10
  19.     IF a$ = "-" THEN
  20.         speed2 = speed2 - 10
  21.     END IF
  22.     IF speed2 <= 0 THEN speed = 0: b = 1: d = 0
  23.     IF a$ = CHR$(0) + CHR$(77) THEN d = 3: speed2 = speed2 + .2 'Right
  24.     IF a$ = CHR$(0) + CHR$(75) THEN d = 4: speed2 = speed2 + .2 'Left
  25.     IF a$ = CHR$(27) THEN END
  26.     IF d = 1 THEN speed = speed + 2: b = 0
  27.     IF d = 3 AND speed > 0 THEN
  28.         v = v - 1
  29.         vv = vv - 2
  30.         tilt = tilt - 2
  31.     END IF
  32.     IF d = 4 AND speed > 0 THEN
  33.         v = v + 1
  34.         vv = vv + 2
  35.         tilt = tilt + 2
  36.     END IF
  37.     IF d = 3 AND speed <= 0 THEN
  38.         v = v - 1
  39.         vv = vv - 2
  40.         tilt = tilt - 2
  41.         speed = speed + 4
  42.     END IF
  43.     IF d = 4 AND speed <= 0 THEN
  44.         v = v + 1
  45.         vv = vv + 2
  46.         tilt = tilt + 2
  47.         speed = speed + 4
  48.     END IF
  49.     IF d = 5 OR speed2 > 0 THEN speed = speed + 1: b = 0
  50.     IF d = 6 OR speed2 > 0 THEN speed = speed + 1: b = 0
  51.  
  52.     IF tilt > 200 THEN tilt = 200
  53.     IF tilt < -200 THEN tilt = -200
  54.     IF (d = 3 OR d = 4 OR d = 5 OR d = 6) AND b = 0 THEN speed = speed + 1
  55.     IF (d = 3 OR d = 4) AND b = 1 THEN speed = speed - 1
  56.     IF e > 100 THEN e = 100
  57.     IF e < 0 THEN e = 0
  58.     elevation = e - 100
  59.     elevation = -elevation
  60.     elevation = elevation * 100
  61.     GOSUB grid:
  62.     IF speed2 < 0 THEN speed2 = 0
  63.     IF speed2 > 500 THEN speed2 = 500
  64.     delay = 2 / speed2
  65.     IF delay < .002 THEN delay = .002
  66.     IF delay > .02 THEN delay = .02
  67.     _DELAY delay
  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. IF cc >= 340 OR cc < 25 THEN comp$ = "North"
  85. IF cc >= 25 AND cc < 65 THEN comp$ = "Northeast"
  86. IF cc >= 65 AND cc < 115 THEN comp$ = "East"
  87. IF cc >= 115 AND cc < 160 THEN comp$ = "Southeast"
  88. IF cc >= 160 AND cc < 205 THEN comp$ = "South"
  89. IF cc >= 205 AND cc < 250 THEN comp$ = "Southwest"
  90. IF cc >= 250 AND cc < 295 THEN comp$ = "West"
  91. IF cc >= 295 AND cc < 340 THEN comp$ = "Northwest"
  92. _PRINTSTRING (390, 550), comp$
  93. cc$ = STR$(cc)
  94. _PRINTSTRING (395, 570), cc$
  95.  
  96. 'Sun
  97. IF cc < 225 OR cc > 315 THEN til = 0: GOTO nosun:
  98. tilt3 = tilt / 50
  99. IF cc = 315 THEN sunx = 800
  100. IF cc = 225 THEN sunx = 0
  101. IF cc < 315 AND tilt < 0 AND tilt3 = oldtilt3 THEN sunx = sunx - 10: til = til - tilt3
  102. IF cc > 225 AND tilt > 0 AND tilt3 = oldtilt3 THEN sunx = sunx + 10: til = til + tilt3
  103. oldtilt3 = tilt3
  104. FOR sz = .25 TO 10 STEP .25
  105.     CIRCLE (sunx, til), sz, _RGB32(255, 255, 127)
  106. NEXT sz
  107. nosun:
  108.  
  109. 'Clouds
  110. clouds = INT(RND * 200) + 1
  111. IF clouds > 190 THEN
  112.     cl = cl + 1
  113.     IF cl > 100 THEN cl = 1
  114.     cloudx(cl) = INT(RND * 799) + 1
  115.     cloudy(cl) = 200
  116.     cloudsz(cl) = INT(RND * 5) + 1 + e / 1.5
  117.     IF cloudsz(cl) < 10 THEN cloudsz(cl) = 10
  118.     shapecl(cl) = (RND - .35)
  119. IF cl = 0 THEN GOTO skipclouds2:
  120. FOR cl2 = 1 TO cl
  121.     cloudy(cl2) = cloudy(cl2) - speed2 / 125
  122.     tilt6 = tilt / 5
  123.     IF tilt6 < 0 THEN tilt6 = -tilt6
  124.     cloudy(cl2) = cloudy(cl2) + tilt6 / 10
  125.     IF cloudy(cl2) < -50 THEN GOTO skipclouds:
  126.     ttttilt = tilt / 10
  127.     IF ttttilt > 6 THEN ttttilt = 6
  128.     IF ttttilt < -6 THEN ttttilt = -6
  129.     cloudx(cl2) = cloudx(cl2) + ttttilt
  130.     IF cloudx(cl2) < -50 OR cloudx(cl2) > 850 THEN GOTO skipclouds:
  131.     IF cloudy(cl2) >= 175 THEN ccl = 100
  132.     IF cloudy(cl2) < 175 AND cloudy(cl2) >= 150 THEN ccl = 125
  133.     IF cloudy(cl2) < 150 AND cloudy(cl2) >= 125 THEN ccl = 150
  134.     IF cloudy(cl2) < 125 AND cloudy(cl2) >= 100 THEN ccl = 175
  135.     IF cloudy(cl2) < 100 AND cloudy(cl2) >= 75 THEN ccl = 200
  136.     IF cloudy(cl2) < 75 AND cloudy(cl2) >= 50 THEN ccl = 225
  137.     IF cloudy(cl2) < 50 THEN ccl = 255
  138.     FOR sz = .25 TO cloudsz(cl2) STEP .25
  139.         CIRCLE (cloudx(cl2), cloudy(cl2)), sz, _RGB32(ccl, ccl, ccl), , , shapecl(cl2)
  140.     NEXT sz
  141.     skipclouds:
  142. NEXT cl2
  143. skipclouds2:
  144.  
  145.  
  146.  
  147. 'Water
  148. water = INT(RND * 200) + 1
  149. IF water > 197 THEN
  150.     w = w + 1
  151.     IF w > 100 THEN w = 1
  152.     waterx(w) = INT(RND * 799) + 1
  153.     watery(w) = 310
  154.     watersz(w) = INT(RND * 5) + 1 + e / 1.5
  155.     shape(w) = (RND - .35)
  156. IF w = 0 THEN GOTO skipwater2:
  157. FOR ww = 1 TO w
  158.     watery(ww) = watery(ww) + speed2 / 125
  159.     tilt4 = tilt / 5
  160.     IF tilt4 < 0 THEN tilt4 = -tilt4
  161.     watery(ww) = watery(ww) + tilt4 / 10
  162.     IF watery(ww) > 650 THEN GOTO skipwater:
  163.     ttilt = tilt / 10
  164.     IF ttilt > 6 THEN ttilt = 6
  165.     IF ttilt < -6 THEN ttilt = -6
  166.     waterx(ww) = waterx(ww) + ttilt
  167.     IF waterx(ww) < -50 OR waterx(ww) > 850 THEN GOTO skipwater:
  168.     IF POINT(waterx(ww), watery(ww)) = _RGB32(0, 0, 150) THEN GOTO skipwater:
  169.     FOR sz = .25 TO watersz(ww) STEP .25
  170.         CIRCLE (waterx(ww), watery(ww)), sz, _RGB32(100, 100, 255), , , shape(ww)
  171.     NEXT sz
  172.     skipwater:
  173. NEXT ww
  174. skipwater2:
  175.  
  176. 'Hills
  177. IF d = 0 THEN GOTO skiphill2:
  178. hills = INT(RND * 200) + 1
  179. IF hills > 150 THEN
  180.     h = h + 1
  181.     IF h > 300 THEN h = 1
  182.     hillx(h) = INT(RND * 799) + 1
  183.     hilly(h) = 310
  184.     hillsz(h) = INT(RND * 5) + 1 + e / 1.5
  185.     hshape(h) = (RND - .35)
  186.     hcolor(h) = INT(RND * 100) + 100
  187. IF h = 0 THEN GOTO skiphill2:
  188. l = l + 1
  189. FOR hh = 1 TO h
  190.     IF speed2 > 0 THEN hilly(hh) = hilly(hh) + speed2 / 125
  191.     tilt5 = tilt / 5
  192.     IF tilt5 < 0 THEN tilt5 = -tilt5
  193.     hilly(hh) = hilly(hh) + tilt5 / 10
  194.     IF hilly(hh) > 650 THEN GOTO skiphill:
  195.     tttilt = tilt / 10
  196.     IF tttilt > 6 THEN tttilt = 6
  197.     IF tttilt < -6 THEN tttilt = -6
  198.     hillx(hh) = hillx(hh) + tttilt
  199.     IF hillx(hh) < -50 OR hillx(hh) > 850 THEN GOTO skiphill:
  200.     IF POINT(hillx(hh), hilly(hh)) = _RGB32(0, 0, 150) THEN GOTO skiphill:
  201.     FOR sz = .25 TO hillsz(hh) STEP .25
  202.         CIRCLE (hillx(hh), hilly(hh)), sz, _RGB32(hcolor(hh) + 44, hcolor(hh), 0), , , hshape(hh)
  203.     NEXT sz
  204.     skiphill:
  205. NEXT hh
  206. skiphill2:
  207.  
  208. 'Left vertical lines.
  209. FOR x = 395 - e TO -300 STEP -xs - xx - e
  210.     xx = xx + 55
  211.     IF v > 7 + e THEN v = -7
  212.     IF v < -7 THEN v = 7 + e
  213.     IF vv > 300 THEN vv = 300
  214.     IF vv < -300 THEN vv = -300
  215.     FOR findy = 0 TO 600
  216.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy = findy: GOTO nex:
  217.     NEXT findy
  218.     nex:
  219.     IF POINT(x - xx + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy) = _RGB32(0, 0, 150) THEN GOTO skip:
  220.     LINE (x + v - vv, yy)-(x - xx + v + vv, 600), _RGB32(255, 255, 255)
  221.     skip:
  222.  
  223. 'Right vertical lines.
  224. FOR x = 405 + e TO 1100 STEP xs + xx2 + e
  225.     xx2 = xx2 + 55
  226.     IF v > 7 + e THEN v = -7
  227.     IF v < -7 THEN v = 7 + e
  228.     IF vv > 300 THEN vv = 300
  229.     IF vv < -300 THEN vv = -300
  230.     FOR findy = 0 TO 600
  231.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy2 = findy: GOTO nex2:
  232.     NEXT findy
  233.     nex2:
  234.     IF POINT(x - xx2 + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy2) = _RGB32(0, 0, 150) THEN GOTO skip2:
  235.     LINE (x + v - vv, yy2)-(x + xx2 + v + vv, 600), _RGB32(255, 255, 255)
  236.     skip2:
  237.  
  238. 'Horizontal lines.
  239. FOR hy = 0 TO 600 STEP xs + xx3 + e
  240.     xx3 = xx3 + 5
  241.     IF speed > 7 + e THEN speed = -7
  242.     IF speed < -7 THEN speed = 7 + e
  243.     FOR findx = 0 TO 800
  244.         IF POINT(findx, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  245.             xx4 = findx
  246.         END IF
  247.     NEXT findx
  248.     FOR findx2 = 0 TO 800
  249.         IF POINT(findx2, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  250.             xx5 = findx2
  251.             LINE (xx4, hy + xx3 + speed)-(xx5, hy + xx3 + speed), _RGB32(255, 255, 255)
  252.             GOTO nex3:
  253.         END IF
  254.     NEXT findx2
  255.     nex3:
  256. NEXT hy
  257. _PRINTSTRING (250, 550), "Altitude"
  258. elevation$ = STR$(elevation)
  259. _PRINTSTRING (255, 570), elevation$
  260.  
  261. _PRINTSTRING (530, 550), "Airspeed"
  262. speed2 = INT(speed2)
  263. speed2$ = STR$(speed2)
  264. _PRINTSTRING (535, 570), speed2$
  265.  
  266. xx = 0: xx2 = 0: xx3 = 0
  267. l = l + 1
  268.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Flight Simulator
« Reply #9 on: May 26, 2020, 04:09:45 pm »
Quote
P.S. Anyone seen B+ lately? Hope he didn't take off like I did a few months ago. I apologize for doing that without saying a word. I should have said something at least.

Hey Ken, still hang'in around but catching up on reading and some interesting stuff on YouTube. Thanks for asking.

Hey to @johnno56  too, I checked out your game at Syntax Bomb, nice work! though seems familiar ;-))

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Flight Simulator
« Reply #10 on: May 26, 2020, 04:44:30 pm »
Awesome Bplus, glad you are still around. :)

I just re-shaped the hills by cutting them in half instead of ovals lol and I changed the colors of them from brown to different shades of green. I also fixed the airspeed so you can stop and everything won't keep adding up on the screen (hills, water, clouds). Plus I moved the clouds up a tiny bit and made them a little bit smaller and less round.

Code: QB64: [Select]
  1. 'Flying - By SierraKen
  2. 'Made on May 26, 2020.
  3. 'V. 0.9 - Fixed airspeed and clouds, and made hills look better.
  4.  
  5. DIM waterx(500), watery(500), shape(500), watersz(500)
  6. DIM hillx(500), hilly(500), hshape(500), hillsz(500), hcolor(500)
  7. DIM cloudx(500), cloudy(500), shapecl(500), cloudsz(500)
  8. SCREEN _NEWIMAGE(800, 600, 32)
  9. xs = 10
  10. c = 0
  11. e = 100
  12. d = 0
  13. FOR g = 1 TO 20
  14.     GOSUB grid:
  15.  
  16. _TITLE "Down arrow goes up. Up arrow goes down. + and - number pad keys are the accelerator. Left and Right keys turn."
  17.     _LIMIT 2000
  18.     a$ = INKEY$
  19.  
  20.     IF a$ = CHR$(0) + CHR$(72) THEN d = 6: e = e + .5: b = 0 'Up arrow key flies down.
  21.     IF a$ = CHR$(0) + CHR$(80) THEN d = 5: e = e - .5: b = 0 'Down arrow key flies up.
  22.     IF a$ = "+" THEN d = 1: speed2 = speed2 + 10
  23.     IF a$ = "-" THEN
  24.         speed2 = speed2 - 10
  25.     END IF
  26.     IF speed2 <= 0 THEN speed = 0: b = 1: d = 0
  27.     IF a$ = CHR$(0) + CHR$(77) THEN d = 3: speed2 = speed2 + .2 'Right
  28.     IF a$ = CHR$(0) + CHR$(75) THEN d = 4: speed2 = speed2 + .2 'Left
  29.     IF a$ = CHR$(27) THEN END
  30.     IF d = 1 THEN speed = speed + 2: b = 0
  31.     IF d = 3 AND speed > 0 THEN
  32.         v = v - 1
  33.         vv = vv - 2
  34.         tilt = tilt - 2
  35.     END IF
  36.     IF d = 4 AND speed > 0 THEN
  37.         v = v + 1
  38.         vv = vv + 2
  39.         tilt = tilt + 2
  40.     END IF
  41.     IF d = 3 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 = 4 AND speed <= 0 THEN
  48.         v = v + 1
  49.         vv = vv + 2
  50.         tilt = tilt + 2
  51.         speed = speed + 4
  52.     END IF
  53.     IF d = 5 OR speed2 > 0 THEN speed = speed + 1: b = 0
  54.     IF d = 6 OR speed2 > 0 THEN speed = speed + 1: b = 0
  55.  
  56.     IF tilt > 200 THEN tilt = 200
  57.     IF tilt < -200 THEN tilt = -200
  58.     IF (d = 3 OR d = 4 OR d = 5 OR d = 6) AND b = 0 THEN speed = speed + 1
  59.     IF (d = 3 OR d = 4) AND b = 1 THEN speed = speed - 1
  60.     IF e > 100 THEN e = 100
  61.     IF e < 0 THEN e = 0
  62.     elevation = e - 100
  63.     elevation = -elevation
  64.     elevation = elevation * 100
  65.     IF d <> 0 THEN GOSUB grid:
  66.     IF speed2 < 0 THEN speed2 = 0
  67.     IF speed2 > 500 THEN speed2 = 500
  68.     delay = 2 / speed2
  69.     IF delay < .002 THEN delay = .002
  70.     IF delay > .02 THEN delay = .02
  71.     _DELAY delay
  72.  
  73. grid:
  74. LINE (0, 299 - e - tilt)-(800, 299 - e + tilt), _RGB32(0, 0, 150)
  75. PAINT (400, 2), _RGB32(0, 0, 150)
  76. LINE (0, 300 - e - tilt)-(800, 300 - e + tilt), _RGB32(0, 155, 0)
  77. PAINT (400, 599), _RGB32(0, 155, 0)
  78.  
  79. 'Calculate Compass
  80. tilt2 = tilt
  81. IF tilt2 < 0 THEN tilt2 = -tilt2
  82.  
  83. IF tilt < 0 THEN c = c - tilt2 / 314
  84. IF tilt > 0 THEN c = c + tilt2 / 314
  85. IF c > 359 THEN c = 0
  86. IF c < 0 THEN c = 359
  87. cc = INT(c)
  88. IF cc >= 340 OR cc < 25 THEN comp$ = "North"
  89. IF cc >= 25 AND cc < 65 THEN comp$ = "Northeast"
  90. IF cc >= 65 AND cc < 115 THEN comp$ = "East"
  91. IF cc >= 115 AND cc < 160 THEN comp$ = "Southeast"
  92. IF cc >= 160 AND cc < 205 THEN comp$ = "South"
  93. IF cc >= 205 AND cc < 250 THEN comp$ = "Southwest"
  94. IF cc >= 250 AND cc < 295 THEN comp$ = "West"
  95. IF cc >= 295 AND cc < 340 THEN comp$ = "Northwest"
  96. _PRINTSTRING (390, 550), comp$
  97. cc$ = STR$(cc)
  98. _PRINTSTRING (395, 570), cc$
  99.  
  100. 'Sun
  101. IF cc < 225 OR cc > 315 THEN til = 0: GOTO nosun:
  102. tilt3 = tilt / 50
  103. IF cc = 315 THEN sunx = 800
  104. IF cc = 225 THEN sunx = 0
  105. IF cc < 315 AND tilt < 0 AND tilt3 = oldtilt3 THEN sunx = sunx - 10: til = til - tilt3
  106. IF cc > 225 AND tilt > 0 AND tilt3 = oldtilt3 THEN sunx = sunx + 10: til = til + tilt3
  107. oldtilt3 = tilt3
  108. FOR sz = .25 TO 10 STEP .25
  109.     CIRCLE (sunx, til), sz, _RGB32(255, 255, 127)
  110. NEXT sz
  111. nosun:
  112.  
  113. 'Clouds
  114. clouds = INT(RND * 200) + 1
  115. IF clouds > 190 THEN
  116.     cl = cl + 1
  117.     IF cl > 100 THEN cl = 1
  118.     cloudx(cl) = INT(RND * 799) + 1
  119.     cloudy(cl) = 180
  120.     cloudsz(cl) = INT(RND * 5) + 1 + e / 1.5
  121.     IF cloudsz(cl) < 10 THEN cloudsz(cl) = 10
  122.     shapecl(cl) = (RND - .4)
  123.     IF shapecl(cl) < .4 THEN shapecl(cl) = .4
  124. IF cl = 0 THEN GOTO skipclouds2:
  125. FOR cl2 = 1 TO cl
  126.     cloudy(cl2) = cloudy(cl2) - speed2 / 125
  127.     tilt6 = tilt / 5
  128.     IF tilt6 < 0 THEN tilt6 = -tilt6
  129.     cloudy(cl2) = cloudy(cl2) + tilt6 / 10
  130.     IF cloudy(cl2) < -50 THEN GOTO skipclouds:
  131.     ttttilt = tilt / 10
  132.     IF ttttilt > 6 THEN ttttilt = 6
  133.     IF ttttilt < -6 THEN ttttilt = -6
  134.     cloudx(cl2) = cloudx(cl2) + ttttilt
  135.     IF cloudx(cl2) < -50 OR cloudx(cl2) > 850 THEN GOTO skipclouds:
  136.     IF cloudy(cl2) >= 175 THEN ccl = 100
  137.     IF cloudy(cl2) < 175 AND cloudy(cl2) >= 150 THEN ccl = 125
  138.     IF cloudy(cl2) < 150 AND cloudy(cl2) >= 125 THEN ccl = 150
  139.     IF cloudy(cl2) < 125 AND cloudy(cl2) >= 100 THEN ccl = 175
  140.     IF cloudy(cl2) < 100 AND cloudy(cl2) >= 75 THEN ccl = 200
  141.     IF cloudy(cl2) < 75 AND cloudy(cl2) >= 50 THEN ccl = 225
  142.     IF cloudy(cl2) < 50 THEN ccl = 255
  143.     FOR sz = .25 TO cloudsz(cl2) STEP .25
  144.         CIRCLE (cloudx(cl2), cloudy(cl2)), sz, _RGB32(ccl, ccl, ccl), , , shapecl(cl2)
  145.     NEXT sz
  146.     skipclouds:
  147. NEXT cl2
  148. skipclouds2:
  149.  
  150.  
  151.  
  152. 'Water
  153. water = INT(RND * 200) + 1
  154. IF water > 197 THEN
  155.     w = w + 1
  156.     IF w > 100 THEN w = 1
  157.     waterx(w) = INT(RND * 799) + 1
  158.     watery(w) = 310
  159.     watersz(w) = INT(RND * 5) + 1 + e / 1.5
  160.     shape(w) = (RND - .35)
  161. IF w = 0 THEN GOTO skipwater2:
  162. FOR ww = 1 TO w
  163.     watery(ww) = watery(ww) + speed2 / 125
  164.     tilt4 = tilt / 5
  165.     IF tilt4 < 0 THEN tilt4 = -tilt4
  166.     watery(ww) = watery(ww) + tilt4 / 10
  167.     IF watery(ww) > 650 THEN GOTO skipwater:
  168.     ttilt = tilt / 10
  169.     IF ttilt > 6 THEN ttilt = 6
  170.     IF ttilt < -6 THEN ttilt = -6
  171.     waterx(ww) = waterx(ww) + ttilt
  172.     IF waterx(ww) < -50 OR waterx(ww) > 850 THEN GOTO skipwater:
  173.     IF POINT(waterx(ww), watery(ww)) = _RGB32(0, 0, 150) THEN GOTO skipwater:
  174.     FOR sz = .25 TO watersz(ww) STEP .25
  175.         CIRCLE (waterx(ww), watery(ww)), sz, _RGB32(100, 100, 255), , , shape(ww)
  176.     NEXT sz
  177.     skipwater:
  178. NEXT ww
  179. skipwater2:
  180.  
  181. 'Hills
  182. hills = INT(RND * 200) + 1
  183. IF hills > 150 THEN
  184.     h = h + 1
  185.     IF h > 300 THEN h = 1
  186.     hillx(h) = INT(RND * 799) + 1
  187.     hilly(h) = 310
  188.     hillsz(h) = INT(RND * 5) + 1 + e / 1.5
  189.     hshape(h) = (RND - .35)
  190.     hcolor(h) = INT(RND * 100) + 100
  191. IF h = 0 THEN GOTO skiphill2:
  192. l = l + 1
  193. FOR hh = 1 TO h
  194.     IF speed2 > 0 THEN hilly(hh) = hilly(hh) + speed2 / 125
  195.     tilt5 = tilt / 5
  196.     IF tilt5 < 0 THEN tilt5 = -tilt5
  197.     hilly(hh) = hilly(hh) + tilt5 / 10
  198.     IF hilly(hh) > 650 THEN GOTO skiphill:
  199.     tttilt = tilt / 10
  200.     IF tttilt > 6 THEN tttilt = 6
  201.     IF tttilt < -6 THEN tttilt = -6
  202.     hillx(hh) = hillx(hh) + tttilt
  203.     IF hillx(hh) < -50 OR hillx(hh) > 850 THEN GOTO skiphill:
  204.     IF POINT(hillx(hh), hilly(hh)) = _RGB32(0, 0, 150) THEN GOTO skiphill:
  205.     FOR sz = .25 TO hillsz(hh) STEP .25
  206.         CIRCLE (hillx(hh), hilly(hh)), sz, _RGB32(hcolor(hh), hcolor(hh) + 44, 0), 2 * _PI, _PI, hshape(hh)
  207.     NEXT sz
  208.     skiphill:
  209. NEXT hh
  210. skiphill2:
  211.  
  212. 'Left vertical lines.
  213. FOR x = 395 - e TO -300 STEP -xs - xx - e
  214.     xx = xx + 55
  215.     IF v > 7 + e THEN v = -7
  216.     IF v < -7 THEN v = 7 + e
  217.     IF vv > 300 THEN vv = 300
  218.     IF vv < -300 THEN vv = -300
  219.     FOR findy = 0 TO 600
  220.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy = findy: GOTO nex:
  221.     NEXT findy
  222.     nex:
  223.     IF POINT(x - xx + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy) = _RGB32(0, 0, 150) THEN GOTO skip:
  224.     LINE (x + v - vv, yy)-(x - xx + v + vv, 600), _RGB32(255, 255, 255)
  225.     skip:
  226.  
  227. 'Right vertical lines.
  228. FOR x = 405 + e TO 1100 STEP xs + xx2 + e
  229.     xx2 = xx2 + 55
  230.     IF v > 7 + e THEN v = -7
  231.     IF v < -7 THEN v = 7 + e
  232.     IF vv > 300 THEN vv = 300
  233.     IF vv < -300 THEN vv = -300
  234.     FOR findy = 0 TO 600
  235.         IF POINT(x + v - vv, findy) = _RGB32(0, 155, 0) THEN yy2 = findy: GOTO nex2:
  236.     NEXT findy
  237.     nex2:
  238.     IF POINT(x - xx2 + v + vv, 600) = _RGB32(0, 0, 150) OR POINT(x + v - vv, yy2) = _RGB32(0, 0, 150) THEN GOTO skip2:
  239.     LINE (x + v - vv, yy2)-(x + xx2 + v + vv, 600), _RGB32(255, 255, 255)
  240.     skip2:
  241.  
  242. 'Horizontal lines.
  243. FOR hy = 0 TO 600 STEP xs + xx3 + e
  244.     xx3 = xx3 + 5
  245.     IF speed > 7 + e THEN speed = -7
  246.     IF speed < -7 THEN speed = 7 + e
  247.     FOR findx = 0 TO 800
  248.         IF POINT(findx, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  249.             xx4 = findx
  250.         END IF
  251.     NEXT findx
  252.     FOR findx2 = 0 TO 800
  253.         IF POINT(findx2, hy + xx3 + speed) = _RGB32(0, 155, 0) THEN
  254.             xx5 = findx2
  255.             LINE (xx4, hy + xx3 + speed)-(xx5, hy + xx3 + speed), _RGB32(255, 255, 255)
  256.             GOTO nex3:
  257.         END IF
  258.     NEXT findx2
  259.     nex3:
  260. NEXT hy
  261. _PRINTSTRING (250, 550), "Altitude"
  262. elevation$ = STR$(elevation)
  263. _PRINTSTRING (255, 570), elevation$
  264.  
  265. _PRINTSTRING (530, 550), "Airspeed"
  266. speed2 = INT(speed2)
  267. speed2$ = STR$(speed2)
  268. _PRINTSTRING (535, 570), speed2$
  269.  
  270. xx = 0: xx2 = 0: xx3 = 0
  271.  
  272.  
« Last Edit: May 26, 2020, 05:28:17 pm by SierraKen »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Flight Simulator
« Reply #11 on: May 26, 2020, 10:21:08 pm »
I can remember, before the advent of graphic cards, flight sims were either a text display of height, speed and direction etc. and waited for the user to input variations... or it was a text rendition of an artificial horizon.. Horizontal line of "-", tilting left or right, moving up or down, whilst displaying heading, altitude and speed... Relied heavily on one's imagination... ah... the memories...

bplus: Familiar? You can't go wrong with an Asteroids clone... Well, it was either that, or a player vs computer version of Pong... lol  Good to know that you are still around... All this isolation would give one the opportunity to get one's creative juices flowing again... says me who prefers Asteroids and Pong... lol Apart from reading, have you been doing much, in the way of game creation?
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Flight Simulator
« Reply #12 on: May 26, 2020, 10:50:29 pm »
@johnno56  check your Message's

Ken here is my overland flight (posted sometime ago but worth repeating):
Code: QB64: [Select]
  1. _TITLE "Drawlandscape Parallax test" 'started 2019-03-27
  2. 'test if can get end of landscape level to start for big looping background
  3. '2019-03-27 a more gentle adjustment back to Mountain starting height for
  4. 'more seamless connect of back end to front
  5. '2019-03-27 start this file with parallax drawing test
  6.  
  7.  
  8. SCREEN _NEWIMAGE(800, 600, 32)
  9. _SCREENMOVE 100, 20
  10. TYPE parallaxType
  11.     handle AS LONG
  12.     rate AS SINGLE 'number of pixels per frame added to le (leading edge)
  13.     le AS SINGLE
  14. nLevels = 6
  15. DIM SHARED para(1 TO nLevels) AS parallaxType
  16.  
  17. DIM SHARED scape&
  18. LoadLandscape
  19. scapeWidth = _WIDTH(para(1).handle)
  20. scapeHeight = _HEIGHT(para(1).handle)
  21.  
  22. WHILE t < 6000
  23.     CLS
  24.     FOR i = 1 TO nLevels
  25.         IF para(i).le + 800 > scapeWidth THEN
  26.             te = scapeWidth - para(i).le
  27.             _PUTIMAGE (0, 0)-(te, scapeHeight), para(i).handle, 0, (scapeWidth - te, 0)-(scapeWidth, scapeHeight)
  28.             _PUTIMAGE (te, 0)-(800, scapeHeight), para(i).handle, 0, (0, 0)-(800 - te, scapeHeight)
  29.  
  30.         ELSE
  31.             _PUTIMAGE (0, 0)-(800, scapeHeight), para(i).handle, 0, (para(i).le, 0)-(para(i).le + 800, scapeHeight)
  32.         END IF
  33.  
  34.         para(i).le = para(i).le - para(i).rate
  35.         IF para(i).le < 0 THEN para(i).le = scapeWidth
  36.     NEXT
  37.     t = t + 1
  38.     _DISPLAY
  39.     _LIMIT 120
  40.  
  41. SUB LoadLandscape
  42.     cur& = _DEST
  43.     xmax = 800 * 3.25: ymax = 600
  44.     hdl& = 1
  45.     para(hdl&).handle = _NEWIMAGE(xmax, ymax, 32)
  46.     _DEST para(hdl&).handle
  47.  
  48.     FOR i = 0 TO ymax
  49.         midInk 0, 0, 128, 128, 128, 200, i / ymax
  50.         LINE (0, i)-(xmax, i)
  51.     NEXT
  52.     'the land
  53.     startH = ymax - 200
  54.     rr = 70: gg = 70: bb = 90
  55.     FOR mountain = 1 TO nLevels
  56.         IF mountain > 1 THEN
  57.             para(mountain).handle = _NEWIMAGE(xmax, ymax, 32)
  58.             _DEST para(mountain).handle
  59.         END IF
  60.         Xright = 0
  61.         y = startH
  62.         COLOR _RGB(rr, gg, bb)
  63.         WHILE Xright < xmax - 50
  64.             ' upDown = local up / down over range, change along Y
  65.             ' range = how far up / down, along X
  66.             upDown = (RND * .8 - .4) * (mountain * .5)
  67.             range = Xright + rand%(15, 25) * 2.5 / mountain
  68.             IF range > xmax - 50 THEN range = xmax - 50
  69.             lastx = Xright - 1
  70.             FOR x = Xright TO range 'need less flat tops
  71.                 test = y + upDown
  72.                 test2 = y - upDown
  73.                 IF ABS(test - startH) < .13 * startH THEN y = test ELSE y = test2: upDown = -upDown
  74.                 LINE (lastx, y)-(x, ymax), , BF 'just lines weren't filling right
  75.                 lastx = x
  76.             NEXT
  77.             Xright = range
  78.         WEND
  79.         x = lastx + 1
  80.         dy = (startH - y) / 50 'more gentle adjustment back to start of screen
  81.         WHILE x <= xmax
  82.             y = y + dy
  83.             LINE (lastx, y)-(x, ymax), , BF 'just lines weren't filling right
  84.             lastx = x
  85.             x = x + 1
  86.         WEND
  87.         rr = rand%(rr - 15, rr): gg = rand%(gg - 15, gg): bb = rand%(bb - 25, bb)
  88.         IF rr < 0 THEN rr = 0
  89.         IF gg < 0 THEN gg = 0
  90.         IF bb < 0 THEN bb = 0
  91.         startH = startH + mountain * rand%(2, 10)
  92.         para(mountain).le = xmax - 800
  93.         para(mountain).rate = mountain * .5
  94.     NEXT
  95.     _DEST cur&
  96.  
  97. FUNCTION rand% (lo%, hi%)
  98.     rand% = INT(RND * (hi% - lo% + 1)) + lo%
  99.  
  100. SUB midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  101.     COLOR _RGB(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  102.  
  103.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Flight Simulator
« Reply #13 on: May 26, 2020, 11:26:34 pm »
Thanks bplus! Way cool. I forgot that we can make the sky shades and ground like that. I might look into it. :)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Flight Simulator
« Reply #14 on: May 27, 2020, 12:30:40 am »
OK, I decided to go with the color idea bplus had on his example (not the mountains) and made a much better ground and sky. I also decided to remove the grid lines. So here is what I have so far. The graphics aren't perfect but we have now gone from 1985 technology to around 1994 or so. :) Thanks bplus!

Code: QB64: [Select]
  1. 'Flying - By SierraKen
  2. 'Made on May 26, 2020.
  3. 'V. 1.0 - Removed grid lines and made ground and sky look better.
  4. 'Thank you bplus for sky and ground idea.
  5.  
  6. DIM waterx(500), watery(500), shape(500), watersz(500)
  7. DIM hillx(500), hilly(500), hshape(500), hillsz(500), hcolor(500)
  8. DIM cloudx(500), cloudy(500), shapecl(500), cloudsz(500)
  9. SCREEN _NEWIMAGE(800, 600, 32)
  10. xs = 10
  11. c = 0
  12. e = 100
  13. d = 0
  14. FOR g = 1 TO 20
  15.     GOSUB grid:
  16.  
  17. _TITLE "Down arrow goes up. Up arrow goes down. + and - number pad keys are the accelerator. Left and Right keys turn."
  18.     _LIMIT 3000
  19.     a$ = INKEY$
  20.  
  21.     IF a$ = CHR$(0) + CHR$(72) THEN d = 6: e = e + .5: b = 0 'Up arrow key flies down.
  22.     IF a$ = CHR$(0) + CHR$(80) THEN d = 5: e = e - .5: b = 0 'Down arrow key flies up.
  23.     IF a$ = "+" THEN d = 1: speed2 = speed2 + 10
  24.     IF a$ = "-" THEN
  25.         speed2 = speed2 - 10
  26.     END IF
  27.     IF speed2 <= 0 THEN speed = 0: b = 1: d = 0
  28.     IF a$ = CHR$(0) + CHR$(77) THEN d = 3: speed2 = speed2 + .2 'Right
  29.     IF a$ = CHR$(0) + CHR$(75) THEN d = 4: speed2 = speed2 + .2 'Left
  30.     IF a$ = CHR$(27) THEN END
  31.     IF d = 1 THEN speed = speed + 2: b = 0
  32.     IF d = 3 AND speed > 0 THEN
  33.         v = v - 1
  34.         vv = vv - 2
  35.         tilt = tilt - 3
  36.     END IF
  37.     IF d = 4 AND speed > 0 THEN
  38.         v = v + 1
  39.         vv = vv + 2
  40.         tilt = tilt + 3
  41.     END IF
  42.     IF d = 3 AND speed <= 0 THEN
  43.         v = v - 1
  44.         vv = vv - 2
  45.         tilt = tilt - 3
  46.         speed = speed + 4
  47.     END IF
  48.     IF d = 4 AND speed <= 0 THEN
  49.         v = v + 1
  50.         vv = vv + 2
  51.         tilt = tilt + 3
  52.         speed = speed + 4
  53.     END IF
  54.     IF d = 5 OR speed2 > 0 THEN speed = speed + 1: b = 0
  55.     IF d = 6 OR speed2 > 0 THEN speed = speed + 1: b = 0
  56.  
  57.     IF tilt > 175 THEN tilt = 175
  58.     IF tilt < -175 THEN tilt = -175
  59.     IF (d = 3 OR d = 4 OR d = 5 OR d = 6) AND b = 0 THEN speed = speed + 1
  60.     IF (d = 3 OR d = 4) AND b = 1 THEN speed = speed - 1
  61.     IF e > 100 THEN e = 100
  62.     IF e < 0 THEN e = 0
  63.     elevation = e - 100
  64.     elevation = -elevation
  65.     elevation = elevation * 100
  66.     IF d <> 0 THEN GOSUB grid:
  67.     IF speed2 < 0 THEN speed2 = 0
  68.     IF speed2 > 1000 THEN speed2 = 1000
  69.     delay = 1 / speed2
  70.     IF delay < .001 THEN delay = .001
  71.     IF delay > .02 THEN delay = .02
  72.     _DELAY delay
  73.  
  74. grid:
  75. FOR bsky = 0 TO 300 STEP .25
  76.     LINE (0, bsky - e - tilt)-(800, bsky - e + tilt), _RGB32(0, 0, bsky)
  77.     LINE (0, bsky - e - tilt + .12)-(800, bsky - e + tilt + .12), _RGB32(0, 0, bsky)
  78. NEXT bsky
  79.  
  80. FOR ground = 300 TO 900 STEP .25
  81.     IF ground = INT(ground) THEN ground2 = ground2 + 1
  82.     LINE (0, ground - e - tilt)-(800, ground - e + tilt), _RGB32(0, ground2, 0)
  83.     LINE (0, ground - e - tilt + .12)-(800, ground - e + tilt + .12), _RGB32(0, ground2, 0)
  84. NEXT ground
  85. ground2 = 0
  86. 'LINE (0, 300 - e - tilt)-(800, 300 - e + tilt), _RGB32(0, 155, 0)
  87. 'PAINT (400, 599), _RGB32(0, 155, 0)
  88.  
  89. 'Calculate Compass
  90. tilt2 = tilt
  91. IF tilt2 < 0 THEN tilt2 = -tilt2
  92.  
  93. IF tilt < 0 THEN c = c - tilt2 / 314
  94. IF tilt > 0 THEN c = c + tilt2 / 314
  95. IF c > 359 THEN c = 0
  96. IF c < 0 THEN c = 359
  97. cc = INT(c)
  98. IF cc >= 340 OR cc < 25 THEN comp$ = "North"
  99. IF cc >= 25 AND cc < 65 THEN comp$ = "Northeast"
  100. IF cc >= 65 AND cc < 115 THEN comp$ = "East"
  101. IF cc >= 115 AND cc < 160 THEN comp$ = "Southeast"
  102. IF cc >= 160 AND cc < 205 THEN comp$ = "South"
  103. IF cc >= 205 AND cc < 250 THEN comp$ = "Southwest"
  104. IF cc >= 250 AND cc < 295 THEN comp$ = "West"
  105. IF cc >= 295 AND cc < 340 THEN comp$ = "Northwest"
  106. _PRINTSTRING (390, 550), comp$
  107. cc$ = STR$(cc)
  108. _PRINTSTRING (395, 570), cc$
  109.  
  110. 'Sun
  111. IF cc < 225 OR cc > 315 THEN til = 0: GOTO nosun:
  112. tilt3 = tilt / 50
  113. IF cc = 315 THEN sunx = 800
  114. IF cc = 225 THEN sunx = 0
  115. IF cc < 315 AND tilt < 0 AND tilt3 = oldtilt3 THEN sunx = sunx - 10: til = til - tilt3
  116. IF cc > 225 AND tilt > 0 AND tilt3 = oldtilt3 THEN sunx = sunx + 10: til = til + tilt3
  117. oldtilt3 = tilt3
  118. FOR sz = .25 TO 10 STEP .25
  119.     CIRCLE (sunx, til), sz, _RGB32(255, 255, 127)
  120. NEXT sz
  121. nosun:
  122.  
  123. 'Clouds
  124. clouds = INT(RND * 200) + 1
  125. IF clouds > 190 THEN
  126.     cl = cl + 1
  127.     IF cl > 100 THEN cl = 1
  128.     cloudx(cl) = INT(RND * 799) + 1
  129.     cloudy(cl) = 180
  130.     cloudsz(cl) = INT(RND * 5) + 1 + e / 1.5
  131.     IF cloudsz(cl) < 10 THEN cloudsz(cl) = 10
  132.     shapecl(cl) = (RND - .4)
  133.     IF shapecl(cl) < .4 THEN shapecl(cl) = .4
  134. IF cl = 0 THEN GOTO skipclouds2:
  135. FOR cl2 = 1 TO cl
  136.     cloudy(cl2) = cloudy(cl2) - speed2 / 125
  137.     tilt6 = tilt / 5
  138.     IF tilt6 < 0 THEN tilt6 = -tilt6
  139.     cloudy(cl2) = cloudy(cl2) + tilt6 / 10
  140.     IF cloudy(cl2) < -50 THEN GOTO skipclouds:
  141.     ttttilt = tilt / 10
  142.     IF ttttilt > 6 THEN ttttilt = 6
  143.     IF ttttilt < -6 THEN ttttilt = -6
  144.     cloudx(cl2) = cloudx(cl2) + ttttilt
  145.     IF cloudx(cl2) < -50 OR cloudx(cl2) > 850 THEN GOTO skipclouds:
  146.     IF cloudy(cl2) >= 175 THEN ccl = 100
  147.     IF cloudy(cl2) < 175 AND cloudy(cl2) >= 150 THEN ccl = 125
  148.     IF cloudy(cl2) < 150 AND cloudy(cl2) >= 125 THEN ccl = 150
  149.     IF cloudy(cl2) < 125 AND cloudy(cl2) >= 100 THEN ccl = 175
  150.     IF cloudy(cl2) < 100 AND cloudy(cl2) >= 75 THEN ccl = 200
  151.     IF cloudy(cl2) < 75 AND cloudy(cl2) >= 50 THEN ccl = 225
  152.     IF cloudy(cl2) < 50 THEN ccl = 255
  153.     FOR sz = .25 TO cloudsz(cl2) STEP .25
  154.         CIRCLE (cloudx(cl2), cloudy(cl2)), sz, _RGB32(ccl, ccl, ccl), , , shapecl(cl2)
  155.     NEXT sz
  156.     skipclouds:
  157. NEXT cl2
  158. skipclouds2:
  159.  
  160.  
  161.  
  162. 'Water
  163. water = INT(RND * 200) + 1
  164. IF water > 197 THEN
  165.     w = w + 1
  166.     IF w > 100 THEN w = 1
  167.     waterx(w) = INT(RND * 799) + 1
  168.     watery(w) = 310
  169.     watersz(w) = INT(RND * 5) + 1 + e / 1.5
  170.     shape(w) = (RND - .35)
  171. IF w = 0 THEN GOTO skipwater2:
  172. FOR ww = 1 TO w
  173.     watery(ww) = watery(ww) + speed2 / 125
  174.     tilt4 = tilt / 5
  175.     IF tilt4 < 0 THEN tilt4 = -tilt4
  176.     watery(ww) = watery(ww) + tilt4 / 10
  177.     IF watery(ww) > 650 THEN GOTO skipwater:
  178.     ttilt = tilt / 10
  179.     IF ttilt > 6 THEN ttilt = 6
  180.     IF ttilt < -6 THEN ttilt = -6
  181.     waterx(ww) = waterx(ww) + ttilt
  182.     IF waterx(ww) < -50 OR waterx(ww) > 850 THEN GOTO skipwater:
  183.     IF POINT(waterx(ww), watery(ww)) = _RGB32(0, 0, 150) THEN GOTO skipwater:
  184.     FOR sz = .25 TO watersz(ww) STEP .25
  185.         CIRCLE (waterx(ww), watery(ww)), sz, _RGB32(100, 100, 255), , , shape(ww)
  186.     NEXT sz
  187.     skipwater:
  188. NEXT ww
  189. skipwater2:
  190.  
  191. 'Hills
  192. hills = INT(RND * 200) + 1
  193. IF hills > 150 THEN
  194.     h = h + 1
  195.     IF h > 300 THEN h = 1
  196.     hillx(h) = INT(RND * 799) + 1
  197.     hilly(h) = 310
  198.     hillsz(h) = INT(RND * 5) + 1 + e / 1.5
  199.     hshape(h) = (RND - .35)
  200.     hcolor(h) = INT(RND * 100) + 100
  201. IF h = 0 THEN GOTO skiphill2:
  202. l = l + 1
  203. FOR hh = 1 TO h
  204.     IF speed2 > 0 THEN hilly(hh) = hilly(hh) + speed2 / 125
  205.     tilt5 = tilt / 5
  206.     IF tilt5 < 0 THEN tilt5 = -tilt5
  207.     hilly(hh) = hilly(hh) + tilt5 / 10
  208.     IF hilly(hh) > 650 THEN GOTO skiphill:
  209.     tttilt = tilt / 10
  210.     IF tttilt > 6 THEN tttilt = 6
  211.     IF tttilt < -6 THEN tttilt = -6
  212.     hillx(hh) = hillx(hh) + tttilt
  213.     IF hillx(hh) < -50 OR hillx(hh) > 850 THEN GOTO skiphill:
  214.     IF POINT(hillx(hh), hilly(hh)) = _RGB32(0, 0, 150) THEN GOTO skiphill:
  215.     FOR sz = .25 TO hillsz(hh) STEP .25
  216.         CIRCLE (hillx(hh), hilly(hh)), sz, _RGB32(hcolor(hh), hcolor(hh) + 44, 0), 2 * _PI, _PI, hshape(hh)
  217.     NEXT sz
  218.     skiphill:
  219. NEXT hh
  220. skiphill2:
  221.  
  222. _PRINTSTRING (250, 550), "Altitude"
  223. elevation$ = STR$(elevation)
  224. _PRINTSTRING (255, 570), elevation$
  225.  
  226. _PRINTSTRING (530, 550), "Airspeed"
  227. speed2 = INT(speed2)
  228. speed2$ = STR$(speed2)
  229. _PRINTSTRING (535, 570), speed2$
  230.  
  231. xx = 0: xx2 = 0: xx3 = 0
  232.  
  233.  

« Last Edit: May 27, 2020, 12:48:34 am by SierraKen »