Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flying
#1
Here is a pretty basic flying simulator I made back in 2020. It has no ground map, just random hills, water, and line grid. And it doesn't show any part of the plane, just the outside. It shows the altitude and speed. I made this as an example, or a possible framework to make it better later on, or into a game. Instructions are in the title bar. There's no actual "flying simulation" to it, just basic turning, speed, and higher and lower. Start out by adding some speed with the + key (to decrease use the - key). Then use the down arrow key to go up and up arrow key to go down. The left and right arrow keys turn. And that's about it. It reminds me of 1980's games a little bit. 


Code: (Select All)

'Flying - By SierraKen
'Made on May 26, 2020.
'V. 0.9 - Fixed airspeed and made hills look better.

Dim waterx(500), watery(500), shape(500), watersz(500)
Dim hillx(500), hilly(500), hshape(500), hillsz(500), hcolor(500)
Dim cloudx(500), cloudy(500), shapecl(500), cloudsz(500)
Screen _NewImage(800, 600, 32)
xs = 10
c = 0
e = 100
d = 0
For g = 1 To 20
    GoSub grid:
Next g

_Title "Down arrow goes up. Up arrow goes down. + and - number pad keys are the accelerator. Left and Right keys turn."
Do
    _Limit 2000
    a$ = InKey$

    If a$ = Chr$(0) + Chr$(72) Then d = 6: e = e + .5: b = 0 'Up arrow key flies down.
    If a$ = Chr$(0) + Chr$(80) Then d = 5: e = e - .5: b = 0 'Down arrow key flies up.
    If a$ = "+" Then d = 1: speed2 = speed2 + 10
    If a$ = "-" Then
        speed2 = speed2 - 10
    End If
    If speed2 <= 0 Then speed = 0: b = 1: d = 0
    If a$ = Chr$(0) + Chr$(77) Then d = 3: speed2 = speed2 + .2 'Right
    If a$ = Chr$(0) + Chr$(75) Then d = 4: speed2 = speed2 + .2 'Left
    If a$ = Chr$(27) Then End
    If d = 1 Then speed = speed + 2: b = 0
    If d = 3 And speed > 0 Then
        v = v - 1
        vv = vv - 2
        tilt = tilt - 2
    End If
    If d = 4 And speed > 0 Then
        v = v + 1
        vv = vv + 2
        tilt = tilt + 2
    End If
    If d = 3 And speed <= 0 Then
        v = v - 1
        vv = vv - 2
        tilt = tilt - 2
        speed = speed + 4
    End If
    If d = 4 And speed <= 0 Then
        v = v + 1
        vv = vv + 2
        tilt = tilt + 2
        speed = speed + 4
    End If
    If d = 5 Or speed2 > 0 Then speed = speed + 1: b = 0
    If d = 6 Or speed2 > 0 Then speed = speed + 1: b = 0

    If tilt > 200 Then tilt = 200
    If tilt < -200 Then tilt = -200
    If (d = 3 Or d = 4 Or d = 5 Or d = 6) And b = 0 Then speed = speed + 1
    If (d = 3 Or d = 4) And b = 1 Then speed = speed - 1
    If e > 100 Then e = 100
    If e < 0 Then e = 0
    elevation = e - 100
    elevation = -elevation
    elevation = elevation * 100
    If d <> 0 Then GoSub grid:
    If speed2 < 0 Then speed2 = 0
    If speed2 > 500 Then speed2 = 500
    delay = 2 / speed2
    If delay < .002 Then delay = .002
    If delay > .02 Then delay = .02
    _Delay delay
Loop

grid:
Cls
For bsky = 0 To 600
    Line (0, bsky)-(800, bsky), _RGB32(0, 0, bsky)
Next bsky

Line (0, 300 - e - tilt)-(800, 300 - e + tilt), _RGB32(0, 155, 0)
Paint (400, 599), _RGB32(0, 155, 0)

'Calculate Compass
tilt2 = tilt
If tilt2 < 0 Then tilt2 = -tilt2

If tilt < 0 Then c = c - tilt2 / 314
If tilt > 0 Then c = c + tilt2 / 314
If c > 359 Then c = 0
If c < 0 Then c = 359
cc = Int(c)
If cc >= 340 Or cc < 25 Then comp$ = "North"
If cc >= 25 And cc < 65 Then comp$ = "Northeast"
If cc >= 65 And cc < 115 Then comp$ = "East"
If cc >= 115 And cc < 160 Then comp$ = "Southeast"
If cc >= 160 And cc < 205 Then comp$ = "South"
If cc >= 205 And cc < 250 Then comp$ = "Southwest"
If cc >= 250 And cc < 295 Then comp$ = "West"
If cc >= 295 And cc < 340 Then comp$ = "Northwest"
_PrintMode _KeepBackground
_PrintString (390, 550), comp$
cc$ = Str$(cc)
_PrintString (395, 570), cc$

'Sun
If cc < 225 Or cc > 315 Then til = 0: GoTo nosun:
tilt3 = tilt / 50
If cc = 315 Then sunx = 800
If cc = 225 Then sunx = 0
If cc < 315 And tilt < 0 And tilt3 = oldtilt3 Then sunx = sunx - 10: til = til - tilt3
If cc > 225 And tilt > 0 And tilt3 = oldtilt3 Then sunx = sunx + 10: til = til + tilt3
oldtilt3 = tilt3
For sz = .25 To 10 Step .25
    Circle (sunx, til), sz, _RGB32(255, 255, 127)
Next sz
nosun:

'Clouds
Randomize Timer
clouds = Int(Rnd * 200) + 1
If clouds > 190 Then
    cl = cl + 1
    If cl > 100 Then cl = 1
    Randomize Timer
    cloudx(cl) = Int(Rnd * 799) + 1
    cloudy(cl) = 180
    Randomize Timer
    cloudsz(cl) = Int(Rnd * 5) + 1 + e / 1.5
    If cloudsz(cl) < 10 Then cloudsz(cl) = 10
    Randomize Timer
    shapecl(cl) = (Rnd - .4)
    If shapecl(cl) < .4 Then shapecl(cl) = .4
End If
If cl = 0 Then GoTo skipclouds2:
For cl2 = 1 To cl
    cloudy(cl2) = cloudy(cl2) - speed2 / 125
    tilt6 = tilt / 5
    If tilt6 < 0 Then tilt6 = -tilt6
    cloudy(cl2) = cloudy(cl2) + tilt6 / 10
    If cloudy(cl2) < -50 Then GoTo skipclouds:
    ttttilt = tilt / 10
    If ttttilt > 6 Then ttttilt = 6
    If ttttilt < -6 Then ttttilt = -6
    cloudx(cl2) = cloudx(cl2) + ttttilt
    If cloudx(cl2) < -50 Or cloudx(cl2) > 850 Then GoTo skipclouds:
    If cloudy(cl2) >= 175 Then ccl = 100
    If cloudy(cl2) < 175 And cloudy(cl2) >= 150 Then ccl = 125
    If cloudy(cl2) < 150 And cloudy(cl2) >= 125 Then ccl = 150
    If cloudy(cl2) < 125 And cloudy(cl2) >= 100 Then ccl = 175
    If cloudy(cl2) < 100 And cloudy(cl2) >= 75 Then ccl = 200
    If cloudy(cl2) < 75 And cloudy(cl2) >= 50 Then ccl = 225
    If cloudy(cl2) < 50 Then ccl = 255
    For sz = .25 To cloudsz(cl2) Step .25
        Circle (cloudx(cl2), cloudy(cl2)), sz, _RGB32(ccl, ccl, ccl), , , shapecl(cl2)
    Next sz
    skipclouds:
Next cl2
skipclouds2:



'Water
Randomize Timer
water = Int(Rnd * 200) + 1
If water > 197 Then
    w = w + 1
    If w > 100 Then w = 1
    Randomize Timer
    waterx(w) = Int(Rnd * 799) + 1
    watery(w) = 310
    Randomize Timer
    watersz(w) = Int(Rnd * 5) + 1 + e / 1.5
    Randomize Timer
    shape(w) = (Rnd - .35)
End If
If w = 0 Then GoTo skipwater2:
For ww = 1 To w
    watery(ww) = watery(ww) + speed2 / 125
    tilt4 = tilt / 5
    If tilt4 < 0 Then tilt4 = -tilt4
    watery(ww) = watery(ww) + tilt4 / 10
    If watery(ww) > 650 Then GoTo skipwater:
    ttilt = tilt / 10
    If ttilt > 6 Then ttilt = 6
    If ttilt < -6 Then ttilt = -6
    waterx(ww) = waterx(ww) + ttilt
    If waterx(ww) < -50 Or waterx(ww) > 850 Then GoTo skipwater:
    If Point(waterx(ww), watery(ww)) = _RGB32(0, 0, 150) Then GoTo skipwater:
    For sz = .25 To watersz(ww) Step .25
        Circle (waterx(ww), watery(ww)), sz, _RGB32(100, 100, 255), , , shape(ww)
    Next sz
    skipwater:
Next ww
skipwater2:

'Hills
Randomize Timer
hills = Int(Rnd * 200) + 1
If hills > 150 Then
    h = h + 1
    If h > 300 Then h = 1
    Randomize Timer
    hillx(h) = Int(Rnd * 799) + 1
    hilly(h) = 310
    Randomize Timer
    hillsz(h) = Int(Rnd * 5) + 1 + e / 1.5
    Randomize Timer
    hshape(h) = (Rnd - .35)
    hcolor(h) = Int(Rnd * 100) + 100
End If
If h = 0 Then GoTo skiphill2:
l = l + 1
For hh = 1 To h
    If speed2 > 0 Then hilly(hh) = hilly(hh) + speed2 / 125
    tilt5 = tilt / 5
    If tilt5 < 0 Then tilt5 = -tilt5
    hilly(hh) = hilly(hh) + tilt5 / 10
    If hilly(hh) > 650 Then GoTo skiphill:
    tttilt = tilt / 10
    If tttilt > 6 Then tttilt = 6
    If tttilt < -6 Then tttilt = -6
    hillx(hh) = hillx(hh) + tttilt
    If hillx(hh) < -50 Or hillx(hh) > 850 Then GoTo skiphill:
    If Point(hillx(hh), hilly(hh)) = _RGB32(0, 0, 150) Then GoTo skiphill:
    For sz = .25 To hillsz(hh) Step .25
        Circle (hillx(hh), hilly(hh)), sz, _RGB32(hcolor(hh), hcolor(hh) + 44, 0), 2 * _Pi, _Pi, hshape(hh)
    Next sz
    skiphill:
Next hh
skiphill2:

'Left vertical lines.
For x = 395 - e To -300 Step -xs - xx - e
    xx = xx + 55
    If v > 7 + e Then v = -7
    If v < -7 Then v = 7 + e
    If vv > 300 Then vv = 300
    If vv < -300 Then vv = -300
    For findy = 0 To 600
        If Point(x + v - vv, findy) = _RGB32(0, 155, 0) Then yy = findy: GoTo nex:
    Next findy
    nex:
    If Point(x - xx + v + vv, 600) = _RGB32(0, 0, 150) Or Point(x + v - vv, yy) = _RGB32(0, 0, 150) Then GoTo skip:
    Line (x + v - vv, yy)-(x - xx + v + vv, 600), _RGB32(255, 255, 255)
    skip:
Next x

'Right vertical lines.
For x = 405 + e To 1100 Step xs + xx2 + e
    xx2 = xx2 + 55
    If v > 7 + e Then v = -7
    If v < -7 Then v = 7 + e
    If vv > 300 Then vv = 300
    If vv < -300 Then vv = -300
    For findy = 0 To 600
        If Point(x + v - vv, findy) = _RGB32(0, 155, 0) Then yy2 = findy: GoTo nex2:
    Next findy
    nex2:
    If Point(x - xx2 + v + vv, 600) = _RGB32(0, 0, 150) Or Point(x + v - vv, yy2) = _RGB32(0, 0, 150) Then GoTo skip2:
    Line (x + v - vv, yy2)-(x + xx2 + v + vv, 600), _RGB32(255, 255, 255)
    skip2:
Next x

'Horizontal lines.
For hy = 0 To 600 Step xs + xx3 + e
    xx3 = xx3 + 5
    If speed > 7 + e Then speed = -7
    If speed < -7 Then speed = 7 + e
    For findx = 0 To 800
        If Point(findx, hy + xx3 + speed) = _RGB32(0, 155, 0) Then
            xx4 = findx
        End If
    Next findx
    For findx2 = 0 To 800
        If Point(findx2, hy + xx3 + speed) = _RGB32(0, 155, 0) Then
            xx5 = findx2
            Line (xx4, hy + xx3 + speed)-(xx5, hy + xx3 + speed), _RGB32(255, 255, 255)
            GoTo nex3:
        End If
    Next findx2
    nex3:
Next hy
_PrintMode _KeepBackground
_PrintString (250, 550), "Altitude"
elevation$ = Str$(elevation)
_PrintString (255, 570), elevation$

_PrintString (530, 550), "Airspeed"
speed2 = Int(speed2)
speed2$ = Str$(speed2)
_PrintString (535, 570), speed2$

_Display
xx = 0: xx2 = 0: xx3 = 0

Return

Reply


Messages In This Thread
Flying - by SierraKen - 11-23-2024, 05:07 AM
RE: Flying - by bplus - 11-23-2024, 04:56 PM
RE: Flying - by SierraKen - 11-23-2024, 05:53 PM
RE: Flying - by Pete - 11-24-2024, 05:51 PM
RE: Flying - by bplus - 11-24-2024, 07:12 PM



Users browsing this thread: 3 Guest(s)