Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mouse Tank
#21
@sierraken
great job! I like it!
Seeing your video on it I realize that your Mouse Tank is also Asteroid mouse ! Yeah, in the place of so many little monsters you could generate a few giant monsters that when hit they are splitted into littler more noumeros monsters.
Reply
#22
LOL thanks Tempodi! I do need to fix it though, because sometimes it doesn't change levels and it just leaves a blank screen. Thanks for the idea though. Or I can just make an asteroids clone that I've never made before. Smile
Reply
#23
OK I believe I fixed it! Don't ask me how, but reducing some variables to 0 before every game and others before every level works great! I also did like Steve asked and slowed the LIMIT down from 120 to 60 and now per every level the monsters come at you a little bit faster. I got to level 39 myself, but I'm also used to playing the game. Good luck!

Also, please tell me if you run into any more issues, thanks. 

@bplus
@SMcNeill

Code: (Select All)

'Mouse Tank by SierraKen
'January 28, 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.
'Update: Fixed level problem.

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

start:

num = 40
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 "Hold down Space Bar or left mouse button to fire at 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
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 * 1.5) + .25 + (level * .05)
        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 60
    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

        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

        'Detect Level Change
        If hits > (num - 1) Then
            Cls
            hits = 0
            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
                    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

Reply
#24
? When I am shooting with space bar the bullets don't have any range on them.

I have to keep my finger on mouse button to shoot and that makes it hard to use mouse wheel, for me anyway.
b = b + ...
Reply
#25
It works fairly well. The collision detection is a bit off as shooting out a monster's legs is like missing it completely.

I think what Mark is experiencing is something I recall for a shooter game I engineered several years ago, the multi-firing effect. In this game if you hold the space bar down, the bullet fired disappears so the new bullet can begin. 

Two ways to fix this.

1) Don't let another bullet emerge until the previous bullet is ended.

2) Assign the bullets as arrays, and FOR/NEXT loop the collision possibilities so each fired bullet is tracked.

Over-all I like it. I got through 1 screen of monsters, successfully, before I shut it down.

+1

Pete
Reply
#26
Thanks guys, yeah I knew this problem. One shot has to be fired at once if you want full-range.
I'll look into this soon hopefully. Pete, I'll probably go with the arrays of the bullets to keep the flying, just like I do with how many raindrops can fall at once. 
I also have to use this fix on a new game I'm making right now, Asteroids Clone. Smile
Reply
#27
I did it!! Now people can hold down the Space Bar to keep shooting and the range is as far as the screen. Smile 
I also made it so you can hit the monster when you shoot the legs.  
Thanks @bplus and @Pete 
I can now implement this into my new Asteroids Clone I'm making! Big Grin 

-Update: I also removed the mouse button firing, there was no more need for it.

Here is the fixed version.

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!


_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
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 * .05)
        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&]]
                        Play "MB"
                        Sound 800, .5, , , 5
                        Sound 600, 1, , , 6
                        Sound 500, .5, , , 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

Reply
#28
On a side note, when I got to level 62 tonight, the sound was messing up a bit, but it was probably my computer. So I stopped the game.
Reply
#29
+1 Much Better!
b = b + ...
Reply
#30
Thanks B+! Yeah I think this is my first shooting game that finally has non-stop bullets. Big Grin 
I might have fixed that sound issue I had. I removed one of the 2 PLAY "MB" commands I had. I thought maybe the one right next to the SOUND lines weren't needed. And it turns out it wasn't. I kept the one that is out of the loop above it. I also reduced the 3 SOUND lines slightly for each shot. So maybe that fixed it, we'll see I guess.
I also made the game a little more challenging up front so you won't have to wait 20 levels to have some challenge to it, by adding a tiny bit more speed. 

Enjoy! Smile 

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

Reply




Users browsing this thread: 28 Guest(s)