09-12-2025, 09:17 AM
And what I usually do to finish up a stage of a project, improve the names and make a few minor changes...
Beta testing was actually fun on this one. It's fairly addictive. Now that this stage is done, I wonder if I'll get around to adding returned fire, saucer fly overs, and levels.
Pete
Code: (Select All)
_Title "Pete's Mini Space Invaders"
Width 40, 20: _Font 16
Type invaders
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
yfire As Integer
xfire As Integer
Outcome As Integer
Score As _Integer64
Array As String
End Type
Dim si As invaders
si.Array = "A A A A A A A A A A A A": For i = 0 To 4: a$(i) = si.Array: Next
si.Direction = 1
si.TopRow = 4
si.RowHeight = 5
si.BaseLine = _Height
si.TrailColumn = _Width \ 2 - Len(si.Array) \ 2
si.MissileSpeed = .05
si.AlienSpeed = .325
si.HomeBase = _Width \ 2
Refresh si, a$(): _Delay 1
Do
ScoreKeeper si
If si.yfire <> 0 And Abs(si.z2 - Timer) > si.MissileSpeed Then MissileAction si, a$()
If si.Outcome = 0 Then
KeyBoard si
If Abs(si.z1 - Timer) > si.AlienSpeed Then MoveAliens si, a$()
If si.BaseAction Then BaseAction si
Else
Finish si
End If
Loop
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
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 + 2500
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$()
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 - .02
If si.AlienSpeed < .1 Then si.AlienSpeed = .1: si.MissileSpeed = .025
Else
si.TrailColumn = si.TrailColumn + si.Direction
End If
End If
Refresh si, a$()
Sound 500, .1
End Sub
Sub Refresh (si As invaders, a$())
View Print si.TopRow - 1 To si.TopRow + si.RowHeight - 1: si.TrailRow = 0: 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
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 Finish (si As invaders)
ScoreKeeper si: Locate 3, 2
Select Case si.Outcome
Case -1: x$ = "GAME OVER - YOU LOST!": Locate 3, _Width / 2 - Len(x$) / 2
Case 1: x$ = "GAME OVER - YOU WON!": Locate 3, _Width / 2 - Len(x$) / 2
End Select
Print x$;: x$ = "Replay? Y/N": Locate 5, _Width / 2 - Len(x$) / 2: Print x$;
Do: _Limit 10: b$ = InKey$
If UCase$(b$) = "Y" Then Cls: Run
If UCase$(b$) = "N" Then _Delay .5: Cls: Print " Bye!": _Delay 1.5: System
Loop
End Sub
Beta testing was actually fun on this one. It's fairly addictive. Now that this stage is done, I wonder if I'll get around to adding returned fire, saucer fly overs, and levels.
Pete

