Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mini Space Invaders
#6
And due to the OVERWHELMING interest in this thread, I decided to add 3 levels!

Code: (Select All)
_Title "Pete's Mini Space Invaders"
Width 40, 20: _Font 16
Type invaders
    RenewVars As Integer
    Level As Integer
    Direction As Integer
    TopRow As Integer
    RowHeight As Integer
    BaseLine As Integer
    TrailColumn As Integer
    MissileSpeed As Single
    AlienSpeed As Single
    HomeBase As Integer
    BaseAction As Integer
    TrailRow As Integer
    LtColReduce As Integer
    RtColReduce As Integer
    z1 As Single
    z2 As Single
    z3 As Single
    yfire As Integer
    xfire As Integer
    ybomb As Integer
    xbomb As Integer
    BombSpeed As Single
    BombFreq As Single
    Outcome As Integer
    Score As _Integer64
    Array As String
End Type
Dim si As invaders: ReDim a$(4)
Do
    Levels si, a$()
    Do
        ScoreKeeper si
        If si.yfire <> 0 And Abs(si.z2 - Timer) > si.MissileSpeed Then MissileAction si, a$(): If si.Outcome Then Exit Do
        If Abs(si.z1 - Timer) > si.AlienSpeed Then
            MoveAliens si, a$(): If si.Outcome Then Exit Do
        End If
        If Abs(si.z3 - Timer) > si.BombFreq Or si.ybomb And Abs(si.z3 - Timer) > si.BombSpeed Then
            AlienBomb si, a$(): If si.Outcome Then Exit Do
        End If
        KeyBoard si
        If si.BaseAction Then BaseAction si
        If si.RenewVars Then si.RenewVars = 0
    Loop
    If si.Level = 3 And si.Outcome = 1 Then si.Outcome = 2 ' Winner!
    If si.Outcome <> 1 Then
        Finish si, a$() ' Loser!
    Else
        View Print 2 To _Height - 1: Cls 2: View Print: _Delay 1.5 ' CLear any remaining bombs or missiles.
    End If
Loop

Sub Levels (si As invaders, a$())
    si.RenewVars = 1
    si.Outcome = 0
    si.LtColReduce = 0
    si.RtColReduce = 0
    si.Direction = 1
    si.TopRow = 4
    si.RowHeight = 5
    si.BaseLine = _Height
    si.MissileSpeed = .04
    si.HomeBase = _Width \ 2
    si.Level = si.Level + 1
    Select Case si.Level
        Case 1
            si.Array = "A A A A A A A A A"
            si.AlienSpeed = .325
            si.BombSpeed = .125
            si.BombFreq = 1
        Case 2
            si.Array = "A A A A A A A A A A"
            si.AlienSpeed = .35
            si.BombSpeed = .1
            si.BombFreq = .85
        Case 3
            si.Array = "A A A A A A A A A A A"
            si.AlienSpeed = .375
            si.BombSpeed = .075
            si.BombFreq = .7
    End Select
    ReDim a$(4): For i = 0 To si.RowHeight - 1: a$(i) = si.Array: Next
    si.TrailColumn = _Width \ 2 - Len(si.Array) \ 2
    Cls
    ScoreKeeper si
    Refresh si, a$()
    _Delay .5
    Locate si.TopRow + si.RowHeight + 2: msg$ = "LEVEL 0" + LTrim$(Str$(si.Level)): CenterX msg$: _Delay 2.5
    Locate si.TopRow + si.RowHeight + 2, 1: EraseRow
    _Delay .5
End Sub

Sub CenterX (msg$)
    Locate , _Width \ 2 - Len(msg$) \ 2: Print msg$;
End Sub

Sub EraseRow
    Locate , 1: Print Space$(_Width);
End Sub

Sub ScoreKeeper (si As invaders)
    info$ = Space$(_Width)
    x$ = " Altitude:" + Str$(_Height * 1000 - (si.TopRow - 1 + si.RowHeight) * 1000) + " Ft  Score:" + Str$(si.Score)
    i = _Width / 2 - Len(x$) / 2
    Mid$(info$, i) = x$
    Locate 1, 1: Print info$;
End Sub

Sub KeyBoard (si As invaders)
    Static restrict
    If RenewVars Then restrict = 0
    Select Case _KeyHit
        Case 19200: If si.HomeBase > 1 And restrict = 0 Then si.HomeBase = si.HomeBase - 1: restrict = 1: si.BaseAction = -1
        Case 19712: If si.HomeBase < _Width And restrict = 0 Then si.HomeBase = si.HomeBase + 1: restrict = 1: si.BaseAction = -1
        Case -19200, -19712: restrict = 0: _KeyClear: si.BaseAction = 0
        Case 32: If si.yfire = 0 Then si.BaseAction = 1
    End Select
End Sub

Sub MissileAction (si As invaders, a$())
    si.z2 = Timer
    If Screen(si.yfire, si.xfire) = 24 Then Locate si.yfire, si.xfire: Print " ";
    si.yfire = si.yfire - 1
    If Screen(si.yfire, si.xfire) = 65 Then
        RowCheck = 0: si.LtColReduce = 0: si.RtColReduce = 0: si.Score = si.Score + 625
        Locate si.yfire, si.xfire: Print Chr$(15);: _Delay .1: Locate si.yfire, si.xfire: Print " ";
        Mid$(a$(si.yfire - si.TopRow), si.xfire - si.TrailColumn + 1, 1) = " ": si.yfire = 0: Sound 1000, .5
        For i = 4 To 0 Step -1
            If Len(LTrim$(a$(i))) And RowCheck = 0 Then si.RowHeight = i + 1: RowCheck = 1
            If Len(RTrim$(a$(i))) > si.RtColReduce Then si.RtColReduce = Len(RTrim$(a$(i)))
            If Len(LTrim$(a$(i))) > si.LtColReduce Then si.LtColReduce = Len(LTrim$(a$(i)))
        Next
        si.RtColReduce = Len(si.Array) - si.RtColReduce: si.LtColReduce = Len(si.Array) - si.LtColReduce
        If LTrim$(a$(0) + a$(1) + a$(2) + a$(3) + a$(4)) = "" Then
            si.Outcome = 1
        Else
            Refresh si, a$()
        End If
    Else
        If si.yfire < si.TrailRow Then si.yfire = 0 Else Locate si.yfire, si.xfire: Print Chr$(24);
    End If
End Sub

Sub MoveAliens (si As invaders, a$())
    si.z1 = Timer
    If si.TopRow - 1 + si.RowHeight = si.BaseLine Then
        si.Outcome = -1
    Else
        If si.TrailColumn + Len(si.Array) - si.RtColReduce > _Width And si.Direction = 1 Or si.TrailColumn = 1 - si.LtColReduce And si.Direction = -1 Then
            si.Direction = -si.Direction: si.TopRow = si.TopRow + 1: si.AlienSpeed = si.AlienSpeed - .0225
            If si.AlienSpeed < .1 Then si.AlienSpeed = .1: si.MissileSpeed = .025
        Else
            si.TrailColumn = si.TrailColumn + si.Direction
        End If
        Refresh si, a$()
        Sound 500, .1
    End If
End Sub

Sub AlienBomb (si As invaders, a$())
    si.z3 = Timer
    If si.TopRow + si.RowHeight < _Height - 3 Then
        If si.ybomb = 0 Then ' Designate alien ship.
            i = si.RowHeight - 1
            k = Int(Rnd * (Len(si.Array) \ 2 + 1)) * 2 + 1
            Do
                For j = 1 To Len(si.Array)
                    If Mid$(a$(i), k, 1) = "A" Then
                        g = k: row = i: Exit Do
                    Else
                        For h = i To 0 Step -1
                            If Mid$(a$(h), k, 1) = "A" Then g = k: row = h: Exit Do
                        Next
                    End If
                    k = k + 2: If k > Len(a$(i)) Then k = 1
                Next
                Exit Do
            Loop
            si.ybomb = row + si.TopRow + 1
            si.xbomb = si.TrailColumn - 1 + g
            Locate si.ybomb - 1, si.xbomb: Color 4: Print "A";: Color 7: Sound 200, 1
        Else
            Locate si.ybomb, si.xbomb: Print " ";
            If si.ybomb = _Height Then
                si.ybomb = 0
            Else
                si.ybomb = si.ybomb + 1
                If Screen(si.ybomb, si.xbomb) = 234 Then
                    Locate si.ybomb, si.xbomb: Color 4, 0: Print Chr$(236);: _Delay .15: Color 7, 0
                    Locate si.ybomb, si.xbomb
                    si.Outcome = -2
                Else
                    Locate si.ybomb, si.xbomb: Print Chr$(249);
                End If
            End If
        End If
    End If
End Sub

Sub Refresh (si As invaders, a$())
    si.TrailRow = 0
    View Print si.TopRow - 1 To si.TopRow + si.RowHeight - 1: Cls 2
    For i = 0 To si.RowHeight - 1
        Locate si.TopRow + i, si.TrailColumn + si.LtColReduce
        Print RTrim$(Mid$(a$(i), si.LtColReduce + 1));
        If Len(LTrim$(a$(i))) And si.TrailRow = 0 Then si.TrailRow = si.TopRow + i
    Next
    View Print
    If si.HomeBase Then Locate _Height, si.HomeBase: Print Chr$(234);
End Sub

Sub BaseAction (si As invaders)
    Select Case si.BaseAction
        Case -1
            Locate _Height, 1: Print Space$(_Width);
            Locate _Height, si.HomeBase: Print Chr$(234);
        Case 1
            si.yfire = _Height: si.xfire = si.HomeBase
    End Select
    si.BaseAction = 0
End Sub

Sub AlienBlitz (si As invaders, a$())
    Cls: si.HomeBase = 0
    ScoreKeeper si
    Do
        si.TopRow = si.TopRow + 1
        Refresh si, a$()
        Sound 500, .1: _Delay .1
    Loop Until si.TopRow + si.RowHeight > _Height
    Sound 200, 1
End Sub

Sub Finish (si As invaders, a$())
    ScoreKeeper si
    msg$ = "GAME OVER - "
    Select Case si.Outcome
        Case -2: msg$ = msg$ + "YOU LOST!": AlienBlitz si, a$()
        Case -1: msg$ = msg$ + "YOU LOST!"
        Case 2: msg$ = msg$ + "YOU WON!"
    End Select
    Locate 3, _Width / 2 - Len(x$) / 2: CenterX msg$
    msg$ = "Replay? Y/N": Locate 5: CenterX msg$
    Do
        _Limit 10
        b$ = InKey$
        Select Case UCase$(b$)
            Case "Y", Chr$(13): Cls: Run
            Case "N", Chr$(27)
                _Delay .5: msg$ = "Bye!"
                Locate 7: CenterX msg$
                _Delay 1.5: System
        End Select
    Loop
End Sub
Reply


Messages In This Thread
Mini Space Invaders - by Pete - 09-11-2025, 08:40 PM
RE: Mini Space Invaders - by Pete - 09-12-2025, 02:03 AM
RE: Mini Space Invaders - by Pete - 09-12-2025, 06:38 AM
RE: Mini Space Invaders - by Pete - 09-12-2025, 09:17 AM
RE: Mini Space Invaders - by Pete - 09-12-2025, 11:20 PM
RE: Mini Space Invaders - by Pete - 09-13-2025, 09:39 PM
RE: Mini Space Invaders - by Pete - 09-18-2025, 07:13 PM
RE: Mini Space Invaders - by Pete - 09-19-2025, 12:01 AM
RE: Mini Space Invaders - by bplus - 09-20-2025, 12:01 AM
RE: Mini Space Invaders - by NakedApe - 09-20-2025, 12:31 AM
RE: Mini Space Invaders - by Pete - 09-20-2025, 07:06 AM
RE: Mini Space Invaders - by bplus - 09-20-2025, 01:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Space Ship Game aadityap0901 4 783 12-26-2024, 02:13 AM
Last Post: bplus
  The Space Globe NakedApe 4 1,052 09-04-2024, 10:49 PM
Last Post: bplus
  In the spirit of Terry's Tutorials - GUARDIAN Alien Space Ship Game Pete 24 4,213 10-18-2022, 05:16 PM
Last Post: Pete
  Space Lander james2464 22 4,122 10-01-2022, 01:23 AM
Last Post: TerryRitchie
  Space(d) Invaders! Cobalt 2 1,017 07-28-2022, 02:24 AM
Last Post: madscijr

Forum Jump:


Users browsing this thread: 1 Guest(s)