Woops! Using code from this for Asteroids I noticed 2 lines with typos. They aren't exactly needed, but they are in a loop in the beginning that zeros out some variables. So you might want to get this code, it might even run better. Sorry about that.
@bplus
@Pete
Code: (Select All)
'Mouse Tank by SierraKen
'January 29, 2025
'Thank you to the QB64 Phoenix Forum, including B+ and Steve for the help over the years.
'Thanks grymmjack for the new SOUND information.
'Thanks Pete and B+ for the help on bullet ranges.
'New sound and now some of the monsters come right at you starting from the beginning
'to make it more challenging.
'Added arms, hands, legs, and feet that move. Also made eyes and mouths get smaller and larger.
'Also, the gun turret turns red when a monster hits you.
'Plus, there's a better sound at the end of the game.
'Update: Fixed level problem.
'Update: Fixed bullet ranges. Now you can hold down the Space Bar!
'Update: Made a little more challenging and hopefully fixed a sound issuue.
_Title "Mouse Tank - by SierraKen"
Screen _NewImage(800, 600, 32)
Randomize Timer
Dim oldx(100), oldy(100)
Dim d1(100), d2(100), s(100), d(100), t(100)
Dim x(100), y(100), xx(100), yy(100), si(100), red(100), green(100), blue(100)
Dim nox(100), llx(100), lly(100), lx(50), ly(50), ldir(50)
Dim sp(100), mou(100), eyes(100), arms(100)
start:
num = 40
level = 1
score = 0
health = 50
healthp = 100
mw = -90
For ll3 = 1 To 50
lx(ll3) = 0
ly(ll3) = 0
ldir(ll3) = 0
Next ll3
Cls
_AutoDisplay
Locate 3, 25: Print "M O U S E T A N K"
Locate 5, 25: Print "By SierraKen"
Locate 10, 25: Print "Move your tank around with your mouse."
Locate 11, 25: Print "Turn your cannon turret with your mouse wheel."
Locate 12, 25: Print "Hold down the Space Bar to fire at the monsters."
Locate 13, 25: Print "To pause and un-pause, press Esc."
Locate 14, 25: Print "Press Q anytime to quit."
Locate 15, 25: Print "Be ready because some of the monsters will be coming directly at you!"
Locate 18, 25: Print "Center Mouse on screen and click left mouse Button to begin."
Do
If _MouseInput Then mi = 1
Loop Until mi = 1 And _MouseButton(1)
start2:
Cls
_Title "Score: " + Str$(score) + " Health: " + Str$(healthp) + "% Level: " + Str$(level)
hits = 0
For t = 1 To num
xx(t) = 0
yy(t) = 0
oldx(t) = 0
oldy(t) = 0
Next t
oldx = 400
oldy = 300
bx = 1
bx2 = 1
r1 = 4
r2 = 30
r3 = 25
loops = 0
loops2 = 0
For size = 1 To num
si(size) = (Rnd * 10) + 10
Next size
For colors = 1 To num
red(colors) = Int(Rnd * 100) + 155
green(colors) = Int(Rnd * 100) + 155
blue(colors) = Int(Rnd * 100) + 155
Next colors
For speed = 1 To num
If speed / 3 = Int(speed / 3) Then
sp(speed) = (Rnd * 2) + .25 + (level * .1)
yy(speed) = Rnd * 600
side = Int(Rnd * 2) + 1
If side = 1 Then xx(speed) = 0
If side = 2 Then xx(speed) = 800
End If
Next speed
For mouths = 1 To num
mou(mouths) = .2
Next mouths
For eye = 1 To num
eyes(eye) = .05
Next eye
For arm = 1 To num
arms(arm) = 0
Next arm
Play "MB"
Do
_Limit 120
For landy = 0 To 800
bl = bl + .25
Line (0, landy)-(800, landy), _RGB32(0, 0, bl)
Next landy
bl = 0
For n = 1 To num
If nox(n) = 1 Then GoTo skip:
If n / 3 = Int(n / 3) Then
If xx(n) > mx Then xx(n) = xx(n) - sp(n)
If xx(n) < mx Then xx(n) = xx(n) + sp(n)
If yy(n) > my Then yy(n) = yy(n) - sp(n)
If yy(n) < my Then yy(n) = yy(n) + sp(n)
GoTo monsters
End If
If d1(n) > d2(n) Then s(n) = s(n) + .1
If d2(n) > d1(n) Then s(n) = s(n) - .1
d(n) = d(n) + 1
If d(n) > t(n) Then
oldx(n) = oldx(n) + x(n)
oldy(n) = oldy(n) + y(n)
bugchange d1(n), d2(n), d(n), t(n)
End If
x(n) = Cos(s(n) * _Pi / 180) * d(n)
y(n) = Sin(s(n) * _Pi / 180) * d(n)
xx(n) = x(n) + oldx(n)
yy(n) = y(n) + oldy(n)
If xx(n) > 750 Then oldx(n) = 50: bugchange d1(n), d2(n), d(n), t(n)
If xx(n) < 50 Then oldx(n) = 750: bugchange d1(n), d2(n), d(n), t(n)
If yy(n) > 550 Then oldy(n) = 50: bugchange d1(n), d2(n), d(n), t(n)
If yy(n) < 50 Then oldy(n) = 550: bugchange d1(n), d2(n), d(n), t(n)
monsters:
If xx(n) - mx < 120 And yy(n) - my < 120 Then
eyes(n) = eyes(n) + .0005
If eyes(n) > .3 Then eyes(n) = .3
mou(n) = mou(n) + .0005
If mou(n) > 3.5 Then mou(n) = 3.5
arms(n) = arms(n) + .1
If arms(n) > 25 Then arms(n) = 25
Else
If xx(n) - mx > 120 Or yy(n) - my > 120 Then
eyes(n) = eyes(n) - .0005
If eyes(n) < .05 Then eyes(n) = .05
mou(n) = mou(n) - .0005
If mou(n) < .2 Then mou(n) = .2
arms(n) = arms(n) - .1
If arms(n) < 0 Then arms(n) = 0
End If
End If
fillCircle xx(n), yy(n) + si(n) - 2, si(n) / 1.5, _RGB32(red(n), green(n), blue(n)) 'Neck
'arms
For ar = 1 To 5
Line (xx(n), yy(n) + ar + si(n))-(xx(n) - 30, yy(n) + ar - arms(n) + si(n)), _RGB32(red(n), green(n), blue(n))
Line (xx(n), yy(n) + ar + si(n))-(xx(n) + 30, yy(n) + ar - arms(n) + si(n)), _RGB32(red(n), green(n), blue(n))
Next ar
fillCircle xx(n) + 30, yy(n) + si(n) - arms(n), si(n) / 3, _RGB32(red(n), green(n), blue(n)) 'Right Hand
fillCircle xx(n) - 30, yy(n) + si(n) - arms(n), si(n) / 3, _RGB32(red(n), green(n), blue(n)) 'Left Hand
fillCircle xx(n), yy(n), si(n), _RGB32(red(n), green(n), blue(n))
fillCircle xx(n) - (si(n) * .3), yy(n) - (si(n) * .3), si(n) * eyes(n), _RGB32(255, 0, 0)
fillCircle xx(n) + (si(n) * .3), yy(n) - (si(n) * .3), si(n) * eyes(n), _RGB32(255, 0, 0)
fillCircle xx(n), yy(n), 3, _RGB32(255, 0, 0)
For sz = .1 To si(n) * .4 Step .1
Circle (xx(n), yy(n) + (si(n) * .4)), sz, _RGB32(255, 0, 0), , , mou(n)
Next sz
'legs
For ar = 1 To 5
Line (xx(n), yy(n) + ar + si(n))-(xx(n) - 20, yy(n) + ar - arms(n) + si(n) + 30), _RGB32(red(n), green(n), blue(n))
Line (xx(n), yy(n) + ar + si(n))-(xx(n) + 20, yy(n) + ar - arms(n) + si(n) + 30), _RGB32(red(n), green(n), blue(n))
Next ar
fillCircle xx(n) + 20, yy(n) + si(n) - arms(n) + 30, si(n) / 3, _RGB32(red(n), green(n), blue(n)) 'Right foot
fillCircle xx(n) - 20, yy(n) + si(n) - arms(n) + 30, si(n) / 3, _RGB32(red(n), green(n), blue(n)) 'Left foot
skip:
b$ = InKey$
If b$ = " " Then
ll = ll + 1
If ll > 50 Then ll = 1
laser = 1
lx(ll) = mx
ly(ll) = my + 25
ldir(ll) = mw
End If
If b$ = Chr$(27) Then
Do: c$ = InKey$
Loop Until c$ = Chr$(27)
End If
If b$ = "q" Or b$ = "Q" Then End
If _MouseInput Then
mx = _MouseX
my = _MouseY
If _MouseWheel Then
mw = mw + _MouseWheel * 5
End If
End If
If laser = 1 Then
For lz = 1 To ll Step 5
lx2 = Cos(ldir(lz) * _Pi / 180)
ly2 = Sin(ldir(lz) * _Pi / 180)
lx(lz) = lx2 / 2 + lx(lz)
ly(lz) = ly2 / 2 + ly(lz)
If lx(lz) > 1100 Then lx(lz) = 1100
If lx(lz) < -300 Then lx(lz) = -300
If ly(lz) > 900 Then ly(lz) = 900
If ly(lz) < -300 Then ly(lz) = -300
fillCircle lx(lz), ly(lz), r1, _RGB32(255, 0, 5)
For chk = 1 To num
distance = Sqr((lx(lz) - xx(chk)) ^ 2 + (ly(lz) - yy(chk)) ^ 2)
If distance <= r1 + r2 + 15 Then
DetectCollision = -1 ' True (collision detected)
Else
DetectCollision = 0 ' False (no collision)
End If
If DetectCollision Then
For explosion = 1 To 50
Circle (lx(lz), ly(lz)), explosion, _RGB32(255, 0, 0)
llx(explosion) = lx(lz)
lly(explosion) = ly(lz)
Next explosion
'SOUND frequency!, duration![, volume!][, panPosition!][, waveform&][, waveformParameters!][, voice&]]
Sound 800, .4, , , 5
Sound 600, .75, , , 6
Sound 500, .4, , , 7
oldx(chk) = -100: oldy(chk) = -100
nox(chk) = 1
xx(chk) = -500: yy(chk) = 1200
lx(lz) = -300: ly(lz) = -300: ldir(lz) = 0
score = score + 10
_Title "Score: " + Str$(score) + " Health: " + Str$(healthp) + "% Level: " + Str$(level)
hits = hits + 1
laser = 0
GoTo skip2:
End If
Next chk
Next lz
End If
skip2:
'Detect Level Change
If hits > (num - 1) Then
Cls
hits = 0
For lz2 = 1 To ll
ly(lz2) = 0
Next lz2
laser = 0
For nn = 1 To num
nox(nn) = 0
Next nn
level = level + 1
num = num + 2
If num > 75 Then num = 75
GoTo start2
End If
'Draw your tank.
For mxx = -25 To 25 Step .25
Line (mx, my - 5)-(mx - mxx, my + 25), _RGB32(127, 255, 127)
Next mxx
For mxx2 = 1 To 25 Step .25
Line (mx, my - 5)-(mx + mxx2, my + 25), _RGB32(127, 255, 127)
Next mxx2
For mxx = -25 To 25 Step .25
Line (mx, my + 50)-(mx + mxx, my + 25), _RGB32(127, 255, 127)
Next mxx
For mxx2 = 1 To 25 Step .25
Line (mx, my + 50)-(mx - mxx2, my + 25), _RGB32(127, 255, 127)
Next mxx2
fillCircle mx, my + 25, 15, _RGB32(0, 0, 255)
fillCircle mx, my + 25, 7, _RGB32(127, 255, 127)
'Draw your tank turret cannon.
s1 = 90 - mw
x = Int(Sin(s1 / 180 * _Pi) * 30) + mx
y = Int(Cos(s1 / 180 * _Pi) * 30) + my
Line (mx, my + 25)-(x, y + 25), _RGB32(255, 0, 0)
If loops < 1000 Then GoTo skip3
'Detect collision with monsters.
For chk = 1 To num
distance = Sqr((mx - xx(chk)) ^ 2 + (my - yy(chk)) ^ 2)
If distance <= r3 + r2 Then
DetectCollision = -1 ' True (collision detected)
Else
DetectCollision = 0 ' False (no collision)
End If
If DetectCollision And nox(chk) <> 1 Then
health = health - .005
healthp = Int((health / 50) * 100)
_Title "Score: " + Str$(score) + " Health: " + Str$(healthp) + "% Level: " + Str$(level)
loops2 = loops2 + 1
If loops2 < 1000 Then fillCircle mx, my + 25, 7, _RGB32(255, 0, 0)
If loops2 > 999 Then loops2 = 0
If health < .01 Then
For explosion = 1 To 200
Circle (mx, my + 25), explosion, _RGB32(255, 0, 0)
Next explosion
For nn = 1 To num
nox(nn) = 0
Next nn
Sound 500, 4, , , 8
Sound 500, 8, , , 5
Sound 100, 4, , , 7
Locate 20, 30: Print "G A M E O V E R"
Locate 25, 30: Input "Again (Y/N)"; ag$
If Left$(ag$, 1) = "y" Or Left$(ag$, 1) = "Y" Then GoTo start
End
End If
End If
Next chk
skip3:
If loops < 1000 Then
loops = loops + 1
End If
Next n
_Display
Cls
Loop
Sub bugchange (d1, d2, d, t)
d1 = Rnd * 360
d2 = Rnd * 360
d = 0
t = Int(Rnd * 360) + 1
End Sub
'from Steve Gold standard
Sub fillCircle (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
Dim Radius As Integer, RadiusError As Integer
Dim X As Integer, Y As Integer
Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
If Radius = 0 Then PSet (CX, CY), C: Exit Sub
Line (CX - X, CY)-(CX + X, CY), C, BF
While X > Y
RadiusError = RadiusError + Y * 2 + 1
If RadiusError >= 0 Then
If X <> Y + 1 Then
Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
End If
X = X - 1
RadiusError = RadiusError - X * 2
End If
Y = Y + 1
Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
Wend
End Sub