09-27-2022, 11:51 PM
Added shields. Not 100% thrilled with them but they mostly work.
Code: (Select All)
'Tvaders 1b
'by James D. Jarvis , you are of course free to modiyt and share this code as you like
'
'a text-mode qb64 retro-shooter
'
'$dynamic
Screen _NewImage(100, 35, 0)
_Title "Tvaders 1"
Type spritetype
s As String
w As Integer 'i wanted to make this a byte but i want to be a tiny bit backwards compatible for folks with different versions
sx As Integer
sy As Integer
hdg As Integer
End Type
Dim Shared a(16) As spritetype
Dim Shared ps As spritetype
Dim Shared ss(10) As spritetype
Dim Shared b(100) As spritetype
Dim Shared aspace(100, 35)
Dim Shared shieldrow(100)
Dim Shared a$, gflag$
Dim Shared shotmax, shotspeed, shottimer, aliencount, aliendelay, alientimer, alive, level, score
Dim Shared boltmax, bolttimer, boltspeed, alienfire, shields, shieldy, shieldcounter
_ControlChr Off
Randomize Timer
Read a$
Read ship$
Read bolt$
Read shot$
ps.s = ship$
ps.w = 8
ps.sx = 32
ps.sy = 31
a(1).s = a$
a(1).w = 8
a(1).sx = 1
a(1).sy = 3
a(1).hdg = 1
For n = 1 To 100
b(n).s = bolt$
b(n).w = 1
b(n).sx = 0
b(n).sy = 0
Next n
For n = 1 To 10
ss(n).s = shot$
ss(n).w = 2
ss(n).sx = 0
ss(n).sy = 0
Next n
For n = 1 To 100
shieldrow(n) = 0
Next n
gflag$ = "GAMEON"
shotmax = 3
shotspeed = 10
shottimer = 0
aliencount = 1
aliendelay = 20
alientimer = 0
alive = aliencounter
level = 1
boltmax = 100
bolttimer = 0
boltspeed = 9
shieldy = 29
startlevel level
Do
_Limit 60
handleshots
handlealiens
handlezaps
handleshields
Cls
Locate 1, 1
Print "LEVEL : "; level
Locate 1, 40
Print "Shields : "; shields
Locate 1, 70
Print "SCORE : "; score
Locate 2, 1
Print "ALive "; alive
If gflag$ = "BOOM" Then doboom
For bc = 1 To 100
If b(bc).sx > 0 Then splat b(bc).s, b(bc).w, b(bc).sx, b(bc).sy
Next bc
For sr = 1 To 100
If shieldrow(sr) > 0 Then
_PrintString (sr, shieldy), "*"
End If
Next sr
For ac = 1 To aliencount
If a(ac).sx > 0 Then
splat a(ac).s, a(ac).w, a(ac).sx, a(ac).sy
End If
Next ac
splat ps.s, ps.w, ps.sx, ps.sy
For s = 1 To shotmax
If ss(s).sx <> 0 Then splat ss(s).s, ss(s).w, ss(s).sx, ss(s).sy
Next s
kk$ = InKey$
If LCase$(kk$) = "a" Or kk$ = "," Or kk$ = "<" Then ps.sx = ps.sx - 1
If LCase$(kk$) = "d" Or kk$ = "." Or kk$ = ">" Then ps.sx = ps.sx + 1
If LCase$(kk$) = "s" Then shieldon ps.sx
If kk$ = " " Then fire ps.sx + 3
If ps.sx < 1 Then ps.sx = 1
If ps.sx > 92 Then ps.sx = 92
If alive < 1 Then nextlevel level
_Display
Loop Until kk$ = Chr$(27) Or gflag$ = "GAMEOVER"
System
'sprites were orignally drawn in ascii tilemaker and stripped out of the data file without the color data for use here
Data "ÛÛÛÛÛÛÛÛ Û0 0Û ÛÛÛÛÛÛÛÛ ^ ^^ ^ "
Data " ²² ÎÎ ²²²² ²²^²²^²²"
Data "/\/"
Data "##^^"
Sub fire (fx)
shotfound = 0
noshots = 0
If shieldrow(fx) <= 0 Or shieldrow(fx + 2) <= 0 Then
Do
noshots = noshots + 1
If ss(noshots).sx = 0 Then shotfound = noshots
Loop Until shotfound > 0 Or noshots = shotmax
If shotfound > 0 Then
ss(shotfound).sx = fx
ss(shotfound).sy = ps.sy - 2
End If
End If
End Sub
Sub shieldon (sxx)
If shields > 0 Then
shields = shields - 1
For so = sxx To sxx + 7
shieldrow(so) = shieldrow(so) + 3
Next so
End If
End Sub
Sub zap (zx, zy)
zapfound = 0
zapcount = 0
Do
zapcount = zapcount + 1
If b(zapcount).sx = 0 Then zapfound = zapcount
Loop Until zapfound > 1 Or zapcount = boltmax
If zapcount > 0 Then
b(zapcount).sx = zx + 4
b(zapcount).sy = zy + 3
End If
End Sub
Sub handleshields
shieldcounter = shieldcounter + 1
For sr = 1 To 100
If shieldrow(sr) < 0 Then shieldrow(sr) = 0
If shieldcounter = 200 Then
shieldrow(sr) = shieldrow(sr) - 1
End If
Next sr
If shieldcounter = 200 Then shieldcounter = 0
End Sub
Sub handlezaps
bolttimer = bolttimer + 1
If bolttimer = boltspeed Then
bolttimer = 0
For n = 1 To 100
If b(n).sx > 0 Then
b(n).sy = b(n).sy + 1
If b(n).sy = 33 Then
b(n).sx = 0
b(n).sy = 0
End If
If b(n).sy = 27 And shieldrow(b(n).sx) > 0 Then
b(n).sy = 0: b(n).sx = 0
shieldrow(b(n).sx) = shieldrow(b(n).sx) - 1
End If
If b(n).sy = 31 Then
For xx = ps.sx To ps.sx + 7
If b(n).sx = xx Then playerhit$ = "BOOM"
If playerhit$ = "BOOM" Then
For rr = 1 To 20
_Limit 150
For d = 1 To 300
_PrintString (2 + Int(Rnd * 98), 5 + Int(Rnd * 30)), "*"
Next d
_PrintString (b(n).sx + Int(Rnd * 3), b(n).sy + Int(Rnd * 3)), "BOOM!"
gflag$ = "BOOM"
_Display
Next rr
End If
Next xx
End If
End If
Next n
End If
End Sub
Sub handleshots
shottimer = shottimer + 1
If shottimer = shotspeed Then
hittag$ = "miss"
For s = 1 To shotmax
For aa = 1 To aliencount
If a(aa).sx > 0 Then
sl = Len(a(aa).s)
sh = sl / a(aa).w
For y = 1 To sh
For x = 1 To a(aa).w
If a(aa).sx + x - 1 = ss(s).sx And a(aa).sy + y - 1 = ss(s).sy And hittag$ = "miss" Then hittag$ = "hit"
Next x
Next
End If
If hittag$ = "hit" Then
ss(s).sx = 0
a(aa).sx = 0
alive = alive - 1
hittag$ = "miss"
score = score + 100
Beep
End If
Next aa
ss(s).sy = ss(s).sy - 2
If ss(s).sy < 1 Then
ss(s).sx = 0
ss(s).sy = 0
End If
Next s
shottimer = 0
End If
End Sub
Sub handlealiens
alientimer = alientimer + 1
If alientimer > 32000 Then alientimer = 1
For n = 1 To aliencount
If a(n).sx > 0 And (alientimer Mod aliendelay = 0) Then
a(n).sx = a(n).sx + a(n).hdg
If a(n).sx > 92 Then
a(n).sx = 92
a(n).sy = a(n).sy + 2
a(n).hdg = a(n).hdg * -1
End If
If a(n).sx < 1 Then
a(n).sx = 1
a(n).sy = a(n).sy + 2
a(n).hdg = a(n).hdg * -1
End If
If 1 + Int(Rnd * 100) <= alienfire Then zap a(n).sx, a(n).sy
If a(n).sy = 31 Then
For xx = ps.sx To ps.sx + 7
If a(n).sx = xx Then playerhit$ = "BOOM"
If playerhit$ = "BOOM" Then
For rr = 1 To 20
_Limit 150
For d = 1 To 300
_PrintString (2 + Int(Rnd * 98), 5 + Int(Rnd * 30)), "*"
Next d
_PrintString (a(n).sx + Int(Rnd * 3), a(n).sy + Int(Rnd * 3)), "BOOM!"
gflag$ = "BOOM"
_Display
Next rr
End If
Next xx
End If
End If
Next
End Sub
Sub splat (SA$, ww As Integer, sx As Integer, sy As Integer)
sl = Len(SA$)
sh = sl / ww
For y = 1 To sh
_PrintString (sx, sy - 1 + y), Mid$(SA$, (y - 1) * ww + 1, ww)
Next
End Sub
Sub startlevel (level)
For bb = 1 To 100
b(bb).sx = 0
b(bb).sy = 0
Next bb
For n = 1 To 10
ss(n).sx = 0
ss(n).sy = 0
Next n
For sr = 1 To 100
shieldrow(sr) = 0
Next sr
shieldcounter = 0
Select Case level
Case 1
aliencount = 1
alive = 1
aliendelay = 20
a(1).s = a$
a(1).w = 8
a(1).sx = 46
a(1).sy = 3
a(1).hdg = 1
shields = 0
score = 0
alienfire = 0
Case 2
aliencount = 3
alive = 3
aliendelay = 20
For n = 1 To aliencount
a(n).s = a$
a(n).w = 8
a(n).sx = n * 12 + 30
a(n).sy = 3
a(n).hdg = 1
Next n
shields = 3
alienfire = 2
Case 3
aliencount = 5
alive = 5
aliendelay = 19
For n = 1 To aliencount
a(n).s = a$
a(n).w = 8
a(n).sx = n * 11 + 20
a(n).sy = 4
a(n).hdg = 1
Next n
shields = shields + 2
alienfire = 4
Case 4
aliencount = 6
alive = 6
aliendelay = 19
For n = 1 To aliencount
a(n).s = a$
a(n).w = 8
a(n).sx = n * 15
a(n).sy = 5
a(n).hdg = 1
Next n
shields = shields + 2
alienfire = 6
Case 5
aliencount = 7
alive = 7
aliendelay = 18
For n = 1 To aliencount
a(n).s = a$
a(n).w = 8
a(n).hdg = 1
Next n
For n = 1 To 5
a(n).sx = n * 15
a(n).sy = 1
Next n
For n = 6 To 7
a(n).sx = (n - 5) * 35
a(n).sy = 5
Next n
shields = shields + 2
alienfire = 6
Case 6
aliencount = 8
alive = 8
aliendelay = 18
For n = 1 To aliencount
a(n).s = a$
a(n).w = 8
a(n).hdg = 1
Next n
For n = 1 To 3
a(n).sx = n * 25
a(n).sy = 3
Next n
For n = 4 To aliencount
a(n).sx = (n - 3) * 12
a(n).sy = 7
Next n
shields = shields + 2
alienfire = 8
Case 7
aliencount = 9
alive = 9
aliendelay = 17
For n = 1 To aliencount
a(n).s = a$
a(n).w = 8
a(n).hdg = 1
Next n
For n = 1 To 3
a(n).sx = n * 12
a(n).sy = 3
Next n
For n = 4 To 6
a(n).sx = (n - 3) * 12 + 30
a(n).sy = 7
a(n).hdg = -1
Next n
For n = 7 To 9
a(n).sx = (n - 6) * 12
a(n).sy = 11
Next n
shields = shields + 2
alienfire = 8
Case 8
aliencount = 10
alive = 10
aliendelay = 17
For n = 1 To aliencount
a(n).s = a$
a(n).w = 8
a(n).hdg = Int(Rnd * 2) - 1
If a(n).hdg = 0 Then a(n).hdg = 1
a(n).sx = 12 + Int(Rnd * 8) * 8
a(n).sy = 1 + Int(Rnd * 3) * 4
Next n
shields = shields + 2
alienfire = 9
Case 9
aliencount = 11
alive = 11
aliendelay = 16
For n = 1 To aliencount
a(n).s = a$
a(n).w = 8
a(n).hdg = -2
Next n
For n = 1 To 5
a(n).sx = n * 12 + 12
a(n).sy = 3
Next n
For n = 6 To aliencount
a(n).sx = (n - 5) * 8
a(n).sy = 7
Next n
shields = shields + 2
alienfire = 9
Case 10
aliencount = 12
alive = 12
aliendelay = 16
For n = 1 To aliencount
a(n).s = a$
a(n).w = 8
a(n).hdg = Int(Rnd * 4) - 2
If a(n).hdg = 0 Then a(n).hdg = 1
a(n).sx = 12 + Int(Rnd * 8) * 8
a(n).sy = 1 + Int(Rnd * 3) * 4
Next n
shields = shields + 1
alienfire = 10
Case 11
aliencount = 13
alive = 13
aliendelay = 15
For n = 1 To aliencount
a(n).s = a$
a(n).w = 8
a(n).hdg = -2
Next n
For n = 1 To 7
a(n).sx = n * 12
a(n).sy = 1 + Int(Rnd * 3) * 4
Next n
For n = 8 To aliencount
a(n).sx = (n - 7) * 12
a(n).sy = 13
Next n
shields = shields + 1
alienfire = 1
Case 12
aliencount = 14
alive = 14
aliendelay = 14
For n = 1 To aliencount
a(n).s = a$
a(n).w = 8
Next n
For n = 1 To 7
a(n).sx = n * 9
a(n).sy = 1
a(n).hdg = -2
Next n
For n = 8 To aliencount
a(n).sx = (n - 7) * 9
a(n).sy = 11
a(n).hdg = 2
Next n
shields = shields + 1
alienfire = 11
Case 13
aliencount = 15
alive = 15
aliendelay = 13
For n = 1 To aliencount
a(n).s = a$
a(n).w = 8
Next n
For n = 1 To 10
a(n).sx = (n * 9) - 8
a(n).sy = 2
a(n).hdg = -2
Next n
For n = 11 To aliencount
a(n).sx = (n - 10) * 9
a(n).sy = 9
a(n).hdg = 3
Next n
shields = shields + 1
alienfire = 12
Case 14
aliencount = 16
alive = 16
aliendelay = 12
For n = 1 To aliencount
a(n).s = a$
a(n).w = 8
Next n
For n = 1 To 8
a(n).sx = (n * 9) - 8
a(n).sy = 2
a(n).hdg = -3
Next n
For n = 9 To aliencount
a(n).sx = (n - 8) * 9
a(n).sy = 11
a(n).hdg = 3
Next n
shields = shields + 1
alienfire = 13
Case 15
aliencount = 16
alive = 16
aliendelay = 10
For n = 1 To aliencount
a(n).s = a$
a(n).w = 8
Next n
For n = 1 To 9
a(n).sx = (n * 9) - 8
a(n).sy = 4
a(n).hdg = -3
Next n
For n = 10 To 14
a(n).sx = (n - 9) * 9 + 4
a(n).sy = 9
a(n).hdg = 3
Next n
For n = 15 To aliencount
a(n).sx = (n - 14) * 20 + 40
a(n).sy = 13
a(n).hdg = 4
Next n
shields = shields + 1
alienfire = 14
Case 16
aliencount = 16
alive = 16
aliendelay = 8
For n = 1 To aliencount
a(n).s = a$
a(n).w = 8
a(n).hdg = Int(Rnd * 8) - 4
If a(n).hdg = 0 Then a(n).hdg = 4
Next n
For x = 0 To 3
For y = 1 To 4
a(x * 4 + y).sx = x * 20
a(x * 4 + y).sy = y * 5
Next y
Next x
shields = shields + 1
alienfire = 15
End Select
End Sub
Sub nextlevel (level)
If level < 17 Then
score = score + level * 1000
Locate 10, 10
Cls
_KeyClear
Print "*********************************************************"
Print "* *"
Print "* COMPLETED LEVEL *"
Print "* *"
Print "* PRESS ANY KEY *"
Print "* *"
Print "* TO START NEXT LEVEL *"
Print "* *"
Print "* *"
Print "*********************************************************"
_Display
any$ = Input$(1)
level = level + 1
If level < 17 Then startlevel level
If level = 17 Then gameflag$ = "GAMEOVER"
End If
If level = 17 Or gameflag$ = "GAMEOVER" Then
Cls
Locate 10, 10
_KeyClear
Print "*********************************************************"
Print "* *"
Print " CONGRATULATIONS ! "
Print "* *"
Print " You Have Defeated the ALIENs! "
Print "* *"
Print
Print " FINAL SCORE : "; score
Print
Print "* PRESS Y to Play again *"
Print " "
Print "* *"
Print "*********************************************************"
_Display
any$ = Input$(1)
If any$ = "y" Or any$ = "Y" Then
gfla$ = "GAMEON"
startlevel 1
Else
Cls
gflag$ = "GAMEOVER"
End If
End If
End Sub
Sub doboom
_KeyClear
Locate 10, 10: Print "*********************************************************"
Locate 11, 10: Print "* ÛÛÛÛÛÛÛÛ *"
Locate 12, 10: Print " Û0 0Û B O O M ! "
Locate 13, 10: Print "* ÛÛÛÛÛÛÛÛ *"
Locate 14, 10: Print " ^ ^^ ^ You Were Defeated by the ALIENs! "
Locate 15, 10: Print "* *"
Locate 16, 10: Print
Locate 17, 10: Print " FINAL SCORE : "; score
Locate 18, 10: Print
Locate 19, 10: Print "* PRESS Y to Play again ÛÛÛÛÛÛÛÛ *"
Locate 20, 10: Print " ÛÛÛÛÛÛÛÛ Û0 0Û "
Locate 21, 10: Print "* Û0 0Û ÛÛÛÛÛÛÛÛ *"
Locate 22, 10: Print "*********************************************************"
_Display
any$ = Input$(1)
If any$ = "y" Or any$ = "Y" Then
gflag$ = "GAMEON"
startlevel 1
Else
Cls
gflag$ = "GAMEOVER"
End If
End Sub