Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Space Lander
#1
Exploring moving/controlling an object etc...very fun project

No collisions yet, no sound.   Control with w, a, d keys 

Cheers

Code: (Select All)
'Lander
'james2464
'Sept 2 2022


Dim scx, scy As Integer


'screen size
scx = 1100 '    640 min --- 1600 max  made for 1100
scy = 600 '    480 min --- 700 max    made for 600

Screen _NewImage(scx, scy, 32)

Randomize Timer

Const PI = 3.141592654#




Dim c0(100) As Long

c0(0) = _RGB(0, 0, 0)
c0(1) = _RGB(255, 255, 255, 60)
c0(2) = _RGB(255, 0, 0)
c0(3) = _RGB(150, 150, 255)
c0(4) = _RGB(0, 200, 50)
c0(5) = _RGB(100, 100, 100)
c0(6) = _RGB(50, 50, 50)
c0(7) = _RGB(255, 50, 50)
c0(8) = _RGB(125, 125, 200)
c0(9) = _RGB(0, 125, 255)
c0(10) = _RGB(255, 200, 125)
c0(11) = _RGB(20, 20, 20)

c0(30) = _RGBA32(255, 255, 150, 160) 'ship exhaust
c0(31) = _RGBA32(255, 255, 150, 80) 'ship exhaust
c0(32) = _RGBA32(255, 255, 150, 40) 'ship exhaust
c0(33) = _RGBA32(255, 255, 150, 20) 'ship exhaust
c0(34) = _RGBA32(255, 220, 0, 200) 'ship exhaust
c0(35) = _RGBA32(255, 220, 0, 100) 'ship exhaust
c0(36) = _RGBA32(255, 220, 0, 70) 'ship exhaust
c0(37) = _RGBA32(255, 220, 0, 40) 'ship exhaust
c0(38) = _RGBA32(255, 220, 0, 10) 'ship exhaust
c0(39) = _RGBA32(255, 220, 0, 0) 'ship exhaust


Dim xx, yy
xx = scx / 2
yy = scy / 2

Type BB
    live As Integer
    x As Single
    y As Single
    xv As Single
    yv As Single
    age As Integer
    rad As Integer
    spd As Single
    colour As Integer
End Type

Dim bnb(900) As BB



Cls
'lower random landscape
j = 0
jj = 0
k = 170
Do
    j = j + 1
    jj = jj + 1
    If jj > 8 Then
        r = Int(Rnd * 5) - 2
        jj = 0
    End If
    k = k + r
    If k > 220 Then
        k = k - r
    End If
    If k < 120 Then
        k = k - r
    End If
    Line (j, scy - k)-(j, scy), c0(6)
Loop Until j >= scx

'upper random landscape
j = 0
jj = 0
k = scy / 6
Do
    j = j + 1
    jj = jj + 1
    If jj > 8 Then
        r = Int(Rnd * 5) - 2
        jj = 0
    End If
    k = k + r
    If k > (scy / 5) Then
        k = k - r
    End If
    If k < scy / 9 Then
        k = k - r
    End If
    Line (j, 0)-(j, k), c0(6)
Loop Until j >= scx



'===== ground
Line (0, scy - 20)-(scx, scy), c0(5), BF

'===== right wall
Line (scx - 40, 0)-(scx, scy - 20), c0(5), BF

'===== left wall
Line (0, 0)-(40, scy - 20), c0(5), BF

'===== pad 1
Line (100, yy)-(200, scy - 80), c0(0), BF
Line (100, scy - 80)-(200, scy - 78), c0(4), BF

'===== pad 2
Line (280, yy)-(355, scy - 50), c0(0), BF
Line (280, scy - 50)-(355, scy - 48), c0(4), BF

'===== pad 3
Line (380 + (scx - 480) / 6, yy)-(430 + (scx - 480) / 6, scy - 90), c0(0), BF
Line (380 + (scx - 480) / 6, scy - 90)-(430 + (scx - 480) / 6, scy - 88), c0(4), BF

'===== pad 4
Line (scx - 120, yy)-(scx - 160, scy - 50), c0(0), BF
Line (scx - 120, scy - 50)-(scx - 160, scy - 48), c0(4), BF


'Sleep



'===== parameters
flow = 1
dv = .033 '              time delay value
pt = 2 '                point size aka circle size
fan = 30 ' fountain fan size
cc1 = 1 '              colour 1
cc2 = 4 '              colour 2
ls = 4 ' launch speed
Dim blive, maxb As Integer

blive = 1
maxb = 1
flip = 0

stx = scx - 140
sty = scy - 70

bnb(1).live = 1
bnb(1).colour = 3

bnb(1).x = stx
bnb(1).y = sty

j = 1

'======== main loop
Do

    flag = 0
    Do



        'update screen

        'erase ship
        cc = 0
        Line (bnb(j).x - 16, bnb(j).y - 15)-(bnb(j).x + 16, bnb(j).y + 19), c0(cc), BF



        'find what's changed before drawing ship again

        'what colour pixels are beneath the ship?
        'if not black, then it has touched down or collided
        c0(99) = Point(bnb(j).x, bnb(j).y + 20)
        If c0(99) <> c0(0) Then
            ccflag = 1 'contact
        Else
            ccflag = 0 'no contact
        End If

        gravityadd = .03
        bnb(j).yv = bnb(j).yv + gravityadd




        If ccflag = 0 Then 'if ship is flying


            '===============  player input
            If _KeyDown(119) Then
                bnb(j).yv = bnb(j).yv - .2
                fire = 1
            End If
            If bnb(j).yv > 10 Then bnb(j).yv = 10
            If bnb(j).yv < -10 Then bnb(j).yv = -10

            If _KeyDown(97) Then
                bnb(j).xv = bnb(j).xv - .1
                fire = 2
            End If
            If bnb(j).xv < -5 Then bnb(j).xv = -5


            If _KeyDown(100) Then
                bnb(j).xv = bnb(j).xv + .1
                fire = 3
            End If
            If bnb(j).xv > 5 Then bnb(j).xv = 5


            cc = 3 'normal ship colour
            'if ship is not landed anywhere
            bnb(j).x = bnb(j).x + bnb(j).xv
            bnb(j).y = bnb(j).y + bnb(j).yv
            If bnb(j).x < 50 Then bnb(j).x = 50
            If bnb(j).x > scx - 50 Then bnb(j).x = scx - 50
            If bnb(j).y < 10 Then bnb(j).y = 10
            If bnb(j).y > scy - 30 Then bnb(j).y = scy - 30

            'ship
            Line (bnb(j).x - 3, bnb(j).y - 15)-(bnb(j).x + 3, bnb(j).y - 14), c0(cc), BF
            Line (bnb(j).x - 5, bnb(j).y - 13)-(bnb(j).x + 5, bnb(j).y - 11), c0(cc), BF
            Line (bnb(j).x - 6, bnb(j).y - 10)-(bnb(j).x + 6, bnb(j).y + 4), c0(cc), BF
            Line (bnb(j).x - 6, bnb(j).y - 12)-(bnb(j).x - 16, bnb(j).y + 19), c0(cc)
            Line (bnb(j).x + 6, bnb(j).y - 12)-(bnb(j).x + 16, bnb(j).y + 19), c0(cc)
            Line (bnb(j).x - 16, bnb(j).y + 19)-(bnb(j).x - 6, bnb(j).y + 4), c0(cc)
            Line (bnb(j).x + 16, bnb(j).y + 19)-(bnb(j).x + 6, bnb(j).y + 4), c0(cc)
            Line (bnb(j).x - 1, bnb(j).y + 5)-(bnb(j).x + 1, bnb(j).y + 5), c0(cc) 'engine
            Line (bnb(j).x - 2, bnb(j).y + 6)-(bnb(j).x + 2, bnb(j).y + 6), c0(cc) 'engine
            Line (bnb(j).x - 3, bnb(j).y + 7)-(bnb(j).x + 3, bnb(j).y + 7), c0(cc) 'engine
            'ship exhaust
            If fire = 1 Then
                cc = 30
                Line (bnb(j).x - 2, bnb(j).y + 8)-(bnb(j).x + 2, bnb(j).y + 9), c0(30), BF
                Line (bnb(j).x - 2, bnb(j).y + 10)-(bnb(j).x + 2, bnb(j).y + 10), c0(31), BF
                Line (bnb(j).x - 2, bnb(j).y + 11)-(bnb(j).x + 2, bnb(j).y + 12), c0(32), BF
                Line (bnb(j).x - 2, bnb(j).y + 13)-(bnb(j).x + 2, bnb(j).y + 15), c0(33), BF
                'PSet (bnb(j).x, bnb(j).y + 16), c0(33)
            ElseIf fire = 2 Then
                cc = 31
                Line (bnb(j).x + 7, bnb(j).y - 5)-(bnb(j).x + 12, bnb(j).y - 4), c0(cc), BF
            ElseIf fire = 3 Then
                cc = 31
                Line (bnb(j).x - 7, bnb(j).y - 5)-(bnb(j).x - 12, bnb(j).y - 4), c0(cc), BF
            End If
            fire = 0



        Else 'ship is touching down
            '===============  player input
            If _KeyDown(119) Then
                bnb(j).yv = bnb(j).yv - .2
                fire = 1
            End If
            If bnb(j).yv > 10 Then bnb(j).yv = 10
            If bnb(j).yv < -10 Then bnb(j).yv = -10

            'If _KeyDown(97) Then bnb(j).xv = bnb(j).xv - .1
            'If _KeyDown(100) Then bnb(j).xv = bnb(j).xv + .1
            'If bnb(j).xv > 5 Then bnb(j).xv = 5
            'If bnb(j).xv < -5 Then bnb(j).xv = -5

            cc = 3 'ship landed alt colour
            'if ship is landed
            bnb(j).xv = bnb(j).xv * .6 'cancel out most of existing x velocity
            If bnb(j).yv > 0 Then bnb(j).yv = 0 'cancel y velocity if heading down

            bnb(j).x = bnb(j).x + bnb(j).xv
            bnb(j).y = bnb(j).y + bnb(j).yv 'since y velocity can only be upward, go for it
            If bnb(j).x < 50 Then bnb(j).x = 50
            If bnb(j).x > scx - 50 Then bnb(j).x = scx - 50
            If bnb(j).y < 10 Then bnb(j).y = 10
            If bnb(j).y > scy - 30 Then bnb(j).y = scy - 30

            'ship
            Line (bnb(j).x - 3, bnb(j).y - 15)-(bnb(j).x + 3, bnb(j).y - 14), c0(cc), BF
            Line (bnb(j).x - 5, bnb(j).y - 13)-(bnb(j).x + 5, bnb(j).y - 11), c0(cc), BF
            Line (bnb(j).x - 6, bnb(j).y - 10)-(bnb(j).x + 6, bnb(j).y + 4), c0(cc), BF
            Line (bnb(j).x - 6, bnb(j).y - 12)-(bnb(j).x - 16, bnb(j).y + 19), c0(cc)
            Line (bnb(j).x + 6, bnb(j).y - 12)-(bnb(j).x + 16, bnb(j).y + 19), c0(cc)
            Line (bnb(j).x - 16, bnb(j).y + 19)-(bnb(j).x - 6, bnb(j).y + 4), c0(cc)
            Line (bnb(j).x + 16, bnb(j).y + 19)-(bnb(j).x + 6, bnb(j).y + 4), c0(cc)
            Line (bnb(j).x - 1, bnb(j).y + 5)-(bnb(j).x + 1, bnb(j).y + 5), c0(cc) 'engine
            Line (bnb(j).x - 2, bnb(j).y + 6)-(bnb(j).x + 2, bnb(j).y + 6), c0(cc) 'engine
            Line (bnb(j).x - 3, bnb(j).y + 7)-(bnb(j).x + 3, bnb(j).y + 7), c0(cc) 'engine


            'ship exhaust
            If fire = 1 Then
                cc = 30
                Line (bnb(j).x - 2, bnb(j).y + 8)-(bnb(j).x + 2, bnb(j).y + 9), c0(30), BF
                Line (bnb(j).x - 2, bnb(j).y + 10)-(bnb(j).x + 2, bnb(j).y + 10), c0(31), BF
                Line (bnb(j).x - 2, bnb(j).y + 11)-(bnb(j).x + 2, bnb(j).y + 12), c0(32), BF
                Line (bnb(j).x - 2, bnb(j).y + 13)-(bnb(j).x + 2, bnb(j).y + 15), c0(33), BF
                'PSet (bnb(j).x, bnb(j).y + 16), c0(33)
            End If
            fire = 0

        End If


        blink = blink + 1
        If blink < 25 Then
            bk = 0
        End If
        If blink > 24 Then
            bk = 2
        End If
        If blink > 50 Then blink = 0

        If ccflag = 0 Then
            Line (bnb(j).x - 1, bnb(j).y - 10)-(bnb(j).x + 1, bnb(j).y - 8), c0(bk), BF
        Else
            Line (bnb(j).x - 1, bnb(j).y - 10)-(bnb(j).x + 1, bnb(j).y - 8), c0(4), BF
        End If

        _Delay dv
    Loop Until flag = 1



Loop


End
Reply


Messages In This Thread
Space Lander - by james2464 - 09-03-2022, 01:22 AM
RE: Space Lander - by bplus - 09-03-2022, 11:34 PM
RE: Space Lander - by james2464 - 09-04-2022, 01:56 AM
RE: Space Lander - by james2464 - 09-04-2022, 05:16 PM
RE: Space Lander - by james2464 - 09-04-2022, 05:41 PM
RE: Space Lander - by bplus - 09-04-2022, 06:48 PM
RE: Space Lander - by james2464 - 09-04-2022, 07:24 PM
RE: Space Lander - by james2464 - 09-06-2022, 12:35 AM
RE: Space Lander - by OldMoses - 09-06-2022, 01:31 AM
RE: Space Lander - by johnno56 - 09-07-2022, 06:07 AM
RE: Space Lander - by james2464 - 09-07-2022, 11:19 PM
RE: Space Lander - by james2464 - 09-07-2022, 11:23 PM
RE: Space Lander - by bplus - 09-07-2022, 11:34 PM
RE: Space Lander - by james2464 - 09-07-2022, 11:48 PM
RE: Space Lander - by johnno56 - 09-08-2022, 05:10 AM
RE: Space Lander - by james2464 - 09-08-2022, 12:25 PM
RE: Space Lander - by johnno56 - 09-08-2022, 06:38 PM
RE: Space Lander - by james2464 - 09-11-2022, 11:28 PM
RE: Space Lander - by johnno56 - 09-12-2022, 04:06 AM
RE: Space Lander - by james2464 - 09-12-2022, 02:48 PM
RE: Space Lander - by james2464 - 09-14-2022, 08:13 PM
RE: Space Lander - by james2464 - 09-30-2022, 11:13 PM
RE: Space Lander - by TerryRitchie - 10-01-2022, 01:23 AM



Users browsing this thread: 8 Guest(s)