Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mouse Tank
#18
Code: (Select All)

'Mouse Tank by SierraKen
'January 23, 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.
'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.

_Title "Mouse Tank - by SierraKen"

Screen _NewImage(800, 600, 32)

Randomize Timer

num = 40

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)
Dim sp(100), mou(100), eyes(100), arms(100)

start:

level = 1
score = 0
health = 50
healthp = 100
mw = -90
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 "Press Space Bar or left mouse button to fire at monsters."
Locate 13, 25: Print "You must hit the monsters on the head to get them."
Locate 14, 25: Print "To pause and un-pause, press Esc."
Locate 15, 25: Print "Press Q anytime to quit."
Locate 16, 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)
Do
d = _DeviceInput

If d = 3 Then 'joystick input
For buttons = 1 To _LastButton(3)
If _Button(buttons) Then Exit Do 'use any button to start
Next
End If
Loop




start2:
Cls

_Title "Score: " + Str$(score) + " Health: " + Str$(healthp) + "% Level: " + Str$(level)

oldx = 400
oldy = 300

hits = 0

bx = 1
bx2 = 1

r1 = 4
r2 = 30
r3 = 25
loops = 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
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"
numDevices = _Devices

Do
_Limit 700
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
laser = 1
lx = mx
ly = my + 25
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 _MouseButton(1) Then
' laser = 1
' lx = mx
' ly = my + 25
' End If
' If _MouseWheel Then
' mw = mw + _MouseWheel * 5
' End If
'End If

d = _DeviceInput
If d = 3 Then 'joystick input
mx = _Clamp(mx + _Axis(1) * 8, 0, _Width - 1) 'left paddle for left/right
my = _Clamp(my + _Axis(2) * 8, o, _Height - 1) 'left paddle for up/down
mw = mw + _Axis(4) * 5 'this should be reword so that the gun points to the same direction as the axis4 and axis5
'but I'm too lazy to do that.
For buttons = 1 To _LastButton(3)
If _Button(buttons) Then 'use any button to fire
laser = 1
lx = mx
ly = my + 25
End If
Next
End If






If laser = 1 Then
lx2 = Cos(mw * _Pi / 180)
ly2 = Sin(mw * _Pi / 180)
lx = lx2 / 2 + lx
ly = ly2 / 2 + ly
If lx > 850 Then lx = 850
If lx < -50 Then lx = -50
If ly > 650 Then ly = 650
If ly < -50 Then ly = -50
fillCircle lx, ly, r1, _RGB32(255, 0, 5)
For chk = 1 To num

distance = Sqr((lx - xx(chk)) ^ 2 + (ly - yy(chk)) ^ 2)
If distance <= r1 + r2 Then
DetectCollision = -1 ' True (collision detected)
Else
DetectCollision = 0 ' False (no collision)
End If

If DetectCollision Then
For explosion = 1 To 100
Circle (lx, ly), explosion, _RGB32(255, 0, 0)
llx(explosion) = lx
lly(explosion) = ly
Next explosion
'SOUND frequency!, duration![, volume!][, panPosition!][, waveform&][, waveformParameters!][, voice&]]
Sound 500, 1, , , 8
Sound 500, 2, , , 5
Sound 100, 1, , , 7
oldx(chk) = -100: nox(chk) = 1
xx(chk) = -500: yy(chk) = 1200
score = score + 10
_Title "Score: " + Str$(score) + " Health: " + Str$(healthp) + "% Level: " + Str$(level)
hits = hits + 1
laser = 0
ly = -3
GoTo skip2:
End If
Next chk
End If

skip2:
If ly < -2 Then
laser = 0
ly = 0
End If
If hits > num - 1 Then
Cls
ly = 0
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
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


I tried to play around with this to use a joystick, but positioning and such was a bit difficult as it wants to work off absolute mouse coordinates and not slowly increase some X/Y position of the tank. You may need to adjust the multiplier I used to make movement a little smoother or more responsive on your machine.

Paddle 1 moves the tank left/right/up/down.
Paddle 2 rotates the gun (only left/right). This should be reworked so that the axis determines the angle of the gun, but I was too lazy to dig into it to sort that part out properly.
Any button on the joystick fires.

This isn't the best demo for joystick support just by its old reliance on mouse positioning and such, but I thought I'd have fun and give it a go. Feel free to tweak all I've done to suit yourself as needed.

For the record, let me state that Steve is NOT a joystick paddle guy. I miss the old days of the original nintendo joysticks -- 2 buttons and one D-pad for direction. I've got arthritis in my knuckles and the idea of using both hands to move and rotate guns and fire and do a dozen other things just doesn't work for me personally.



Note #1: One thing that I've noticed on this, and it occurs even without my changes, is that sometimes it doesn't advance levels. I can get stuck at 370 points, every enemy dead, and then the game will never increase to level 2. No idea why that is either; it's just something that's happened to me a couple of times so far.

Note #2: There should probably be a _Limit in here somewhere. On my PC, this thing runs superfast and you have about 2 seconds to respond and either clear a level, or die.
Reply


Messages In This Thread
Mouse Tank - by SierraKen - 01-21-2025, 10:04 PM
RE: Mouse Tank - by bplus - 01-22-2025, 12:09 AM
RE: Mouse Tank - by SierraKen - 01-22-2025, 12:52 AM
RE: Mouse Tank - by SierraKen - 01-22-2025, 01:41 AM
RE: Mouse Tank - by Jack002 - 01-22-2025, 02:34 AM
RE: Mouse Tank - by SierraKen - 01-22-2025, 03:49 AM
RE: Mouse Tank - by grymmjack - 01-22-2025, 05:26 AM
RE: Mouse Tank - by grymmjack - 01-22-2025, 05:41 AM
RE: Mouse Tank - by SierraKen - 01-22-2025, 09:47 PM
RE: Mouse Tank - by grymmjack - 01-23-2025, 12:34 PM
RE: Mouse Tank - by bplus - 01-23-2025, 02:46 PM
RE: Mouse Tank - by a740g - 01-23-2025, 04:19 PM
RE: Mouse Tank - by SierraKen - 01-23-2025, 09:46 PM
RE: Mouse Tank - by bplus - 01-23-2025, 10:05 PM
RE: Mouse Tank - by SierraKen - 01-23-2025, 10:09 PM
RE: Mouse Tank - by SierraKen - 01-24-2025, 01:02 AM
RE: Mouse Tank - by SierraKen - 01-24-2025, 06:24 PM
RE: Mouse Tank - by SMcNeill - 01-25-2025, 06:32 AM
RE: Mouse Tank - by a740g - 01-26-2025, 05:18 AM
RE: Mouse Tank - by SierraKen - 01-26-2025, 04:50 PM
RE: Mouse Tank - by TempodiBasic - 01-29-2025, 04:26 AM
RE: Mouse Tank - by SierraKen - 01-29-2025, 04:40 AM
RE: Mouse Tank - by SierraKen - 01-29-2025, 05:59 AM
RE: Mouse Tank - by bplus - 01-30-2025, 12:43 AM
RE: Mouse Tank - by Pete - 01-30-2025, 02:09 AM
RE: Mouse Tank - by SierraKen - 01-30-2025, 04:13 AM
RE: Mouse Tank - by SierraKen - 01-30-2025, 05:45 AM
RE: Mouse Tank - by SierraKen - 01-30-2025, 06:22 AM
RE: Mouse Tank - by bplus - 01-30-2025, 06:37 AM
RE: Mouse Tank - by SierraKen - 01-30-2025, 06:55 AM
RE: Mouse Tank - by Pete - 01-30-2025, 08:44 AM
RE: Mouse Tank - by SierraKen - 01-30-2025, 08:11 PM



Users browsing this thread: 21 Guest(s)