Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ken's Artillery 2
#11
Here is another big update for this game. This uses graphical Click Bars instead of typing in the power number and the angle number, and also a Fire! button using your mouse. Thanks to B+ for helping me on the help section of this forum for better mouse control and click bars. I also changed the amount you need to hit the enemy from 5 times to 4 times to win the level. And he needs to hit you 4 times in a level to beat you. You will also notice that I made the instructions much simpler to read at the beginning. 

Code: (Select All)
'I've always wanted to make this game ever since I started programming in the 80's.
'This was created by Ken G. with much help from others below.
'Thank you to B+ for much of the math code, Mouse and click bar help on https://qb64phoenix.com/forum/index.php
'It takes the computer a little time to learn how to hit your base.
'Created on June 26, 2019.
'Version 2 made on May 2, 2022.
'Added: Levels, random colored mountains, and better looking cannons.
'Added: Click Bars and Fire! button. Simpler Instructions. Changed 5 to 4 times needed to hit enemy and enemy to hit you.

_Title "Ken's Artillery 2"
_Limit 200
Cls
Screen _NewImage(1200, 700, 32)
Print "                                              Ken's Artillery 2"
Print: Print: Print
Print "                                        By SierraKen with help from B+."
Print: Print: Print
Print "                        Instructions: Red Click Bar   = Power"
Print "                                      Green Click Bar = Angle"
Print "                                      Fire! Button = Fire Cannonball"
Print
Print "                                      Hit enemy 4 times you advance to next level."
Print "                                      Get hit 4 times in a level and you lose."
Print: Print: Print
Print "                                          Press Any Key To Begin."
Sleep
Cls
level = 1

start:
c = 0
mountain = 0
win = 0
compoints = 0
points = 0
ground = 590 'up is negative in direction

'Your Cannon

cbx = 10 '              cannon butt end x, y
cby = ground - 20
cmx = 50 '              cannon mouth end
cmy = ground - 70

'Computer's Cannon

cbx2 = 1190
cby2 = cby
cmx2 = 1150
cmy2 = cmy


g = .15 '       with air resistance
Randomize Timer
air = Int(Rnd * 20)
air2 = air / 1000
Randomize Timer
air3 = Int(Rnd * 100)
If air3 > 50 Then air2 = -air2
airX = air2
Color , _RGB32(156, 210, 237)
Cls
'Bases
Line (cbx, ground)-(cbx + 100, ground - 20), _RGB32(4, 4, 4), BF
Line (cbx2, ground)-(cbx2 - 100, ground - 20), _RGB32(4, 4, 4), BF
'Mountain
Randomize Timer
sz = Int(Rnd * 300) + 100
circx = 595
cl1 = Int(Rnd * 55) + 50
cl2 = Int(Rnd * 55) + 50
cl3 = Int(Rnd * 55) + 50
Line (0, ground)-(1200, 700), _RGB32(cl1, cl2, cl3), BF 'ground
Circle (circx, ground), sz, _RGB32(cl1, cl2, cl3)
Paint (circx, ground - 2), _RGB32(cl1, cl2, cl3)
again:
Color _RGB(0, 0, 0)
Locate 10, 136: Print "              "
Color _RGB32(255, 0, 0), _RGB32(156, 210, 237)
Locate 10, 2: Print "Your Turn     "
Randomize Timer
air = Int(Rnd * 20)
air2 = air / 1000
Randomize Timer
air3 = Int(Rnd * 100)
If air3 > 50 Then air2 = -air2
airX = air2
airx2 = airX * 1000
If airx2 < -1 Then winddir$ = "West"
If airx2 > 1 Then winddir$ = "East"
If airx2 > -1 And airx2 < 1 Then winddir$ = "Sunny"
If airx2 < 0 Then airx2 = airx2 * -1

GoSub Wind:
_PrintString (5, 50), "Power"
_PrintString (5, 80), "Angle"
Line (60, 40)-(260, 70), _RGB32(255, 255, 255), B
Line (60, 70)-(260, 100), _RGB32(255, 255, 255), B
Line (60, 100)-(120, 130), _RGB32(255, 0, 5), BF
Color _RGB32(0, 0, 0), _RGB32(255, 0, 5)
_PrintString (70, 110), "Fire!"
vel = 40
vel3 = 100
a = 45
a3 = 100
Line (61, 41)-(vel3, 69), _RGB32(255, 0, 1), BF
Line (61, 71)-(a3, 99), _RGB32(0, 255, 1), BF

go:
_Display ' update screen !!! sure like to know if my turn or not after computer
fired = 0
While _MouseInput: Wend
mx = _MouseX: my = _MouseY: mb = _MouseButton(1) ' this update the mouse x, y and button status save to variable because they change
If mb Then
    If mx >= 60 And my <= 260 Then
        If my >= 40 And my < 70 Then
            vel = (mx - 60) / 200 * 100 ' converts place in box to 0 to 100
            If mx > 259 Then mx = 259: vel = 100
            Line (61, 41)-(259, 69), _RGB32(156, 210, 237), BF
            Line (61, 41)-(mx, 69), _RGB32(255, 0, 1), BF
            Color _RGB32(0, 0, 0), _RGB32(255, 0, 0)
            _PrintString (265, 50), Str$(vel)
            _Delay .25 'wait for release of mouse button
            GoTo go
        ElseIf my >= 70 And my < 100 Then
            a = (mx - 60) / 200 * 90 ' converts place in box to 0 to 90
            If mx > 259 Then mx = 259: a = 90
            Line (61, 71)-(259, 99), _RGB32(156, 210, 237), BF
            Line (61, 71)-(mx, 99), _RGB32(0, 255, 1), BF
            Color _RGB32(0, 0, 0), _RGB32(0, 255, 0)
            _PrintString (265, 80), Str$(a)
            _Delay .25 'wait for release of mouse button
            GoTo go
        ElseIf my >= 100 And my < 130 Then
            fired = 1
            _Delay .25
            GoTo going
        End If
    End If
End If
If fired = 0 Then GoTo go '  need?

going:
Color _RGB32(0, 0, 0), _RGB32(156, 210, 237)
If a > 90 Then a = 90
If a < 0 Then a = 0
If vel < 0 Then vel = 0
If vel > 80 Then vel = 80
vel = Int(vel / 4)
a = 360 - a
ca = _D2R(a)
cmx = cbx + (100 * Cos(_D2R(a)))
cmy = cby + (100 * Sin(_D2R(a)))

'initialize
bx = cmx 'ball x, y same as cannon mouth at start of shot
by = cmy


dx = vel * Cos(ca) 'start at cannon mouth
dy = vel * Sin(ca)

'shot

Do
    _Limit 200
    GoSub Wind:

    a$ = InKey$
    If a$ = Chr$(27) Then End
    Circle (bx, by), 5, _RGB32(0, 0, 0)
    Paint (bx, by), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
    For ccc = 0 To 7 Step .1
        Line (cbx, cby)-(cmx + ccc, cmy), _RGB32(150, 50, 0) 'cannon line
    Next ccc
    oldbx = bx: oldby = by
    dx = dx + airX
    dy = dy + g
    bx = bx + dx
    by = by + dy
    _Display
    _Limit 30
    Circle (oldbx, oldby), 5, _RGB(156, 210, 237)
    Paint (oldbx, oldby), _RGB(156, 210, 237)
    If Point(bx, by) = _RGB32(cl1, cl2, cl3) Then
        mountain = 1
        For explosion = 0 To 20 Step .5
            Circle (bx, by), explosion, _RGB32(156, 210, 237)
            Sound 100 + explosion, .25
        Next explosion
    End If
    If bx > cbx2 - 120 And bx < cbx2 + 20 And by >= ground - 2 Then
        points = points + 1
        win = 0
        Locate 3, 64: Print "You: "; points; " Computer: "; compoints
        For explosion = 0 To 20 Step .5
            Circle (bx, by), explosion, _RGB32(156, 210, 237)
            Sound 100 + explosion, .25
        Next explosion
        For sndd = 500 To 700 Step 50
            Sound sndd, 1
        Next sndd
        mountain = 1
        If points = 4 And win = 0 Then win = 1: level = level + 1: GoTo start:
    End If
Loop Until mountain = 1 Or by > 700
For ccc = 0 To 7 Step .1
    Line (cbx, cby)-(cmx + ccc, cmy), _RGB32(156, 210, 237) 'delete cannon line
Next ccc
mountain = 0
'The Computer's Turn

comp:

Color _RGB(0, 0, 0)
Locate 10, 2: Print "                      "
Locate 10, 137: Print "Computer Turn"
GoSub Wind:

'Computer learns as it goes but is not perfect, like a human.  ;-)
If c = 0 Then GoTo compstuff:
oldvel2 = vel2

compstuff:
Randomize Timer
vel2 = Int(Rnd * 35) + 30

a2 = a

vel2 = Int(vel2 / 4)

If c = 0 Then GoTo nex:
'Last shot was too far away.
If oldbx2 < cbx Then
    vel2 = oldvel2 - 1
    If vel2 < 8 Then vel2 = 8
End If
'Last shot wasn't far enough.
If oldbx2 > cbx Then
    vel2 = oldvel2 + 1
    If vel2 > 15 Then vel2 = 15
End If
nex:
c = 1
ca2 = _D2R(a2)
cmx2 = cbx2 - (100 * Cos(_D2R(a2)))
cmy2 = cby2 + (100 * Sin(_D2R(a2)))

'initialize
bx2 = cmx2 'ball x, y same as cannon mouth at start of shot
by2 = cmy2
dx2 = vel2 * Cos(ca2) 'start at cannon mouth
dy2 = vel2 * Sin(ca2)

'shot

Do
    _Limit 200
    a$ = InKey$
    If a$ = Chr$(27) Then End
    Circle (bx2, by2), 5, _RGB32(0, 0, 0)
    Paint (bx2, by2), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
    For ccc = 0 To 7 Step .1
        Line (cbx2, cby2)-(cmx2 - ccc, cmy2), _RGB32(150, 50, 0) 'cannon line
    Next ccc
    oldbx2 = bx2: oldby2 = by2
    dx2 = dx2 + airX
    dy2 = dy2 + g
    bx2 = bx2 - dx2
    by2 = by2 + dy2
    _Display
    _Limit 30
    Circle (oldbx2, oldby2), 5, _RGB(156, 210, 237)
    Paint (oldbx2, oldby2), _RGB(156, 210, 237)
    If Point(bx2, by2) = _RGB32(cl1, cl2, cl3) Then
        mountain = 1
        For explosion = 0 To 20 Step .5
            Circle (bx2, by2), explosion, _RGB32(156, 210, 237)
            Sound 100 + explosion, .25
        Next explosion
    End If
    If bx2 > cbx - 20 And bx2 < cbx + 120 And by2 >= ground - 2 Then
        compoints = compoints + 1
        Locate 3, 64: Print "You: "; points; " Computer: "; compoints
        For explosion = 0 To 20 Step .5
            Circle (bx2, by2), explosion, _RGB32(156, 210, 237)
            Sound 100 + explosion, .25
        Next explosion
        For sndd = 500 To 700 Step 50
            Sound sndd, 1
        Next sndd
        mountain = 1
        If compoints = 4 Then Color _RGB(0, 0, 0): Locate 20, 65: Print "COMPUTER WINS!": GoTo asking:
    End If
Loop Until mountain = 1 Or by2 > 700

For ccc = 0 To 7 Step .1
    Line (cbx2, cby2)-(cmx2 - ccc, cmy2), _RGB32(156, 210, 237) 'delete cannon line
Next ccc
mountain = 0
GoTo again:

'This code is used in a few different places in the program.
Wind:
Color _RGB(0, 0, 0)
Locate 1, 73: Print "Wind"
If winddir$ = "West" Then
    Locate 2, 82: Print "                               "
    Locate 2, 59: Print airx2; " mph   "
End If
If winddir$ = "East" Then
    Locate 2, 59: Print "               "
    Locate 2, 82: Print airx2; " mph   "
End If
Locate 2, 68: Print "West <-> East"
Locate 3, 64: Print "You: "; points; " Computer: "; compoints
Locate 4, 71: Print "Level: "; level
Return

asking:
Locate 22, 65: Input "Again? (Yes/No):", ag$
If ag$ = "y" Or ag$ = "Y" Or ag$ = "yes" Or ag$ = "Yes" Or ag$ = "YES" Or ag$ = "yES" Or ag$ = "yeS" Then points = 0: level = 1: GoTo start:
End
Reply
#12
Here is another big update. I made it so the click bars disappear when it's the computer's turn. I also reset the click bars back to the original amounts per turn, they were anyway but didn't show it on the graphics. Plus now to start the game you click the mouse button instead of any key. Oh also now when you press the Fire! button the red color is darkened over the button so you know you pressed it. I also fixed some minor errors. Thanks to B+, OldMoses, and Steve for the help and code!

Code: (Select All)
'I've always wanted to make this game ever since I started programming in the 80's.
'This was created by Ken G. with much help from others below.
'Thank you to B+ for much of the math code, Mouse and click bar help on https://qb64phoenix.com/forum/index.php
'It takes the computer a little time to learn how to hit your base.
'Created on June 26, 2019.
'Version 2 made on May 2, 2022.
'Added: Levels, random colored mountains, and better looking cannons.
'Added: Click Bars and Fire! button. Simpler Instructions. Changed 5 to 4 times needed to hit enemy and enemy to hit you.
'Added: Better mouse control thanks to B+, OldMoses, and Steve.
'Added: Delete click bars when it's not your turn.
'Added: Click mouse button to start game.
'Added: Set click bars back to original amounts per turn.

_Title "Ken's Artillery 2"
_Limit 200
Cls
Screen _NewImage(1200, 700, 32)
Print "                                              Ken's Artillery 2"
Print: Print: Print
Print "                                        By SierraKen with help from B+."
Print: Print: Print
Print "                        Instructions: Red Click Bar   = Power"
Print "                                      Green Click Bar = Angle"
Print "                                      Fire! Button    = Fire Cannonball"
Print
Print "                                      Hit enemy 4 times you advance to next level."
Print "                                      Get hit 4 times in a level and you lose."
Print: Print: Print
Print "                                        Press Mouse Button To Start!"
Do
    While _MouseInput: Wend
    mx = _MouseX: my = _MouseY: mb = _MouseButton(1) ' this update the mouse x, y and button status save to variable because they change
    If mb Then Clear_MB 1: GoTo continue:
Loop

continue:

Cls
level = 1

start:
c = 0
mountain = 0
win = 0
compoints = 0
points = 0
ground = 590 'up is negative in direction

'Your Cannon

cbx = 10 '              cannon butt end x, y
cby = ground - 20
cmx = 50 '              cannon mouth end
cmy = ground - 70

'Computer's Cannon

cbx2 = 1190
cby2 = cby
cmx2 = 1150
cmy2 = cmy


g = .15 '       with air resistance
Randomize Timer
air = Int(Rnd * 20)
air2 = air / 1000
Randomize Timer
air3 = Int(Rnd * 100)
If air3 > 50 Then air2 = -air2
airX = air2
Color , _RGB32(156, 210, 237)
Cls
'Bases
Line (cbx, ground)-(cbx + 100, ground - 20), _RGB32(4, 4, 4), BF
Line (cbx2, ground)-(cbx2 - 100, ground - 20), _RGB32(4, 4, 4), BF
'Mountain
Randomize Timer
sz = Int(Rnd * 300) + 100
circx = 595
cl1 = Int(Rnd * 55) + 50
cl2 = Int(Rnd * 55) + 50
cl3 = Int(Rnd * 55) + 50
Line (0, ground)-(1200, 700), _RGB32(cl1, cl2, cl3), BF 'ground
Circle (circx, ground), sz, _RGB32(cl1, cl2, cl3)
Paint (circx, ground - 2), _RGB32(cl1, cl2, cl3)
Color _RGB32(0, 0, 0), _RGB32(0, 255, 0)
_PrintString (265, 80), Str$(a)
Color _RGB32(0, 0, 0), _RGB32(255, 0, 0)
_PrintString (265, 50), Str$(vel)

again:
vel = 40
vel3 = 100
a = 45
a3 = 100
Color _RGB32(156, 210, 237), _RGB32(156, 210, 237)
Locate 10, 129: Print "                 "
Color _RGB32(255, 0, 0), _RGB32(156, 210, 237)
Locate 10, 2: Print "Your Turn     "
Randomize Timer
air = Int(Rnd * 20)
air2 = air / 1000
Randomize Timer
air3 = Int(Rnd * 100)
If air3 > 50 Then air2 = -air2
airX = air2
airx2 = airX * 1000
If airx2 < -1 Then winddir$ = "West"
If airx2 > 1 Then winddir$ = "East"
If airx2 > -1 And airx2 < 1 Then winddir$ = "Sunny"
If airx2 < 0 Then airx2 = airx2 * -1

GoSub Wind:
Color _RGB32(0, 0, 0), _RGB32(156, 210, 237)
_PrintString (5, 50), "Power"
Color _RGB32(0, 0, 0), _RGB32(255, 0, 0)
_PrintString (265, 50), Str$(vel)
Color _RGB32(0, 0, 0), _RGB32(156, 210, 237)
_PrintString (5, 80), "Angle"
Color _RGB32(0, 0, 0), _RGB32(0, 255, 0)
_PrintString (265, 80), Str$(a)
Line (60, 40)-(260, 70), _RGB32(255, 255, 255), B
Line (60, 70)-(260, 100), _RGB32(255, 255, 255), B
Line (60, 100)-(120, 130), _RGB32(255, 0, 5), BF

Color _RGB32(0, 0, 0), _RGB32(255, 0, 5)
_PrintString (70, 110), "Fire!"

Line (61, 41)-(vel3, 69), _RGB32(255, 0, 1), BF
Line (61, 71)-(a3, 99), _RGB32(0, 255, 1), BF
go:
_Display ' update screen !!! sure like to know if my turn or not after computer
fired = 0
While _MouseInput: Wend
mx = _MouseX: my = _MouseY: mb = _MouseButton(1) ' this update the mouse x, y and button status save to variable because they change
If mb Then
    If mx >= 60 And mx <= 260 Then
        If my >= 40 And my < 70 Then
            vel = (mx - 60) / 200 * 100 ' converts place in box to 0 to 100
            If mx > 259 Then mx = 259: vel = 100
            Line (61, 41)-(259, 69), _RGB32(156, 210, 237), BF
            Line (61, 41)-(mx, 69), _RGB32(255, 0, 1), BF
            vel3 = mx
            Color _RGB32(0, 0, 0), _RGB32(255, 0, 0)
            _PrintString (265, 50), Str$(vel)
            Clear_MB 1
            GoTo go
        ElseIf my >= 70 And my < 100 Then
            a = (mx - 60) / 200 * 90 ' converts place in box to 0 to 90
            If mx > 259 Then mx = 259: a = 90
            Line (61, 71)-(259, 99), _RGB32(156, 210, 237), BF
            Line (61, 71)-(mx, 99), _RGB32(0, 255, 1), BF
            a3 = mx
            Color _RGB32(0, 0, 0), _RGB32(0, 255, 0)
            _PrintString (265, 80), Str$(a)
            Clear_MB 1
            GoTo go
        ElseIf my >= 100 And my < 130 And mx <= 120 Then
            fired = 1
            For pressed = 1 To 10
                Line (60 + pressed, 100 + pressed)-(120 - pressed, 130 - pressed), _RGB32(200 - (pressed * 10), 10, 5), BF
            Next pressed
            Color _RGB32(0, 0, 0), _RGB32(100, 10, 5)
            _PrintString (70, 110), "Fire!"
            Clear_MB 1
            GoTo going
        End If
    End If
End If
If fired = 0 Then GoTo go

going:
Color _RGB32(0, 0, 0), _RGB32(156, 210, 237)
If a > 90 Then a = 90
If a < 0 Then a = 0
If vel < 0 Then vel = 0
If vel > 80 Then vel = 80
vel = Int(vel / 4)
a = 360 - a
ca = _D2R(a)
cmx = cbx + (100 * Cos(_D2R(a)))
cmy = cby + (100 * Sin(_D2R(a)))

'initialize
bx = cmx 'ball x, y same as cannon mouth at start of shot
by = cmy


dx = vel * Cos(ca) 'start at cannon mouth
dy = vel * Sin(ca)

'shot

Do
    _Limit 200
    GoSub Wind:

    a$ = InKey$
    If a$ = Chr$(27) Then End
    Circle (bx, by), 5, _RGB32(0, 0, 0)
    Paint (bx, by), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
    For ccc = 0 To 7 Step .1
        Line (cbx, cby)-(cmx + ccc, cmy), _RGB32(150, 50, 0) 'cannon line
    Next ccc
    oldbx = bx: oldby = by
    dx = dx + airX
    dy = dy + g
    bx = bx + dx
    by = by + dy
    _Display
    _Limit 30
    Circle (oldbx, oldby), 5, _RGB(156, 210, 237)
    Paint (oldbx, oldby), _RGB(156, 210, 237)
    If Point(bx, by) = _RGB32(cl1, cl2, cl3) Then
        mountain = 1
        For explosion = 0 To 20 Step .5
            Circle (bx, by), explosion, _RGB32(156, 210, 237)
            Sound 100 + explosion, .25
        Next explosion
    End If
    If bx > cbx2 - 120 And bx < cbx2 + 20 And by >= ground - 2 Then
        points = points + 1
        win = 0
        Locate 3, 64: Print "You: "; points; " Computer: "; compoints
        For explosion = 0 To 20 Step .5
            Circle (bx, by), explosion, _RGB32(156, 210, 237)
            Sound 100 + explosion, .25
        Next explosion
        For sndd = 500 To 700 Step 50
            Sound sndd, 1
        Next sndd
        mountain = 1
        If points = 4 And win = 0 Then win = 1: level = level + 1: GoTo start:
    End If
Loop Until mountain = 1 Or by > 700
For ccc = 0 To 7 Step .1
    Line (cbx, cby)-(cmx + ccc, cmy), _RGB32(156, 210, 237) 'delete cannon line
Next ccc
mountain = 0
'The Computer's Turn

comp:

'Clear Click Bars and Fire! Button
Line (4, 39)-(330, 131), _RGB32(156, 210, 237), BF


Color _RGB32(156, 210, 237)
Locate 10, 2: Print "                      "
Color _RGB32(0, 0, 0), _RGB32(156, 210, 237)
Locate 10, 130: Print "Computer's Turn"
GoSub Wind:

'Computer learns as it goes but is not perfect, like a human.  ;-)
If c = 0 Then GoTo compstuff:
oldvel2 = vel2

compstuff:
Randomize Timer
vel2 = Int(Rnd * 35) + 30

a2 = a

vel2 = Int(vel2 / 4)

If c = 0 Then GoTo nex:
'Last shot was too far away.
If oldbx2 < cbx Then
    vel2 = oldvel2 - 1
    If vel2 < 8 Then vel2 = 8
End If
'Last shot wasn't far enough.
If oldbx2 > cbx Then
    vel2 = oldvel2 + 1
    If vel2 > 15 Then vel2 = 15
End If
nex:
c = 1
ca2 = _D2R(a2)
cmx2 = cbx2 - (100 * Cos(_D2R(a2)))
cmy2 = cby2 + (100 * Sin(_D2R(a2)))

'initialize
bx2 = cmx2 'ball x, y same as cannon mouth at start of shot
by2 = cmy2
dx2 = vel2 * Cos(ca2) 'start at cannon mouth
dy2 = vel2 * Sin(ca2)

'shot

Do
    _Limit 200
    a$ = InKey$
    If a$ = Chr$(27) Then End
    Circle (bx2, by2), 5, _RGB32(0, 0, 0)
    Paint (bx2, by2), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
    For ccc = 0 To 7 Step .1
        Line (cbx2, cby2)-(cmx2 - ccc, cmy2), _RGB32(150, 50, 0) 'cannon line
    Next ccc
    oldbx2 = bx2: oldby2 = by2
    dx2 = dx2 + airX
    dy2 = dy2 + g
    bx2 = bx2 - dx2
    by2 = by2 + dy2
    _Display
    _Limit 30
    Circle (oldbx2, oldby2), 5, _RGB(156, 210, 237)
    Paint (oldbx2, oldby2), _RGB(156, 210, 237)
    If Point(bx2, by2) = _RGB32(cl1, cl2, cl3) Then
        mountain = 1
        For explosion = 0 To 20 Step .5
            Circle (bx2, by2), explosion, _RGB32(156, 210, 237)
            Sound 100 + explosion, .25
        Next explosion
    End If
    If bx2 > cbx - 20 And bx2 < cbx + 120 And by2 >= ground - 2 Then
        compoints = compoints + 1
        Locate 3, 64: Print "You: "; points; " Computer: "; compoints
        For explosion = 0 To 20 Step .5
            Circle (bx2, by2), explosion, _RGB32(156, 210, 237)
            Sound 100 + explosion, .25
        Next explosion
        For sndd = 500 To 700 Step 50
            Sound sndd, 1
        Next sndd
        mountain = 1
        If compoints = 4 Then Color _RGB(0, 0, 0): Locate 20, 65: Print "COMPUTER WINS!": GoTo asking:
    End If
Loop Until mountain = 1 Or by2 > 700

For ccc = 0 To 7 Step .1
    Line (cbx2, cby2)-(cmx2 - ccc, cmy2), _RGB32(156, 210, 237) 'delete cannon line
Next ccc
mountain = 0
GoTo again:

'This code is used in a few different places in the program.
Wind:
Color _RGB(0, 0, 0)
Locate 1, 73: Print "Wind"
If winddir$ = "West" Then
    Locate 2, 82: Print "                               "
    Locate 2, 59: Print airx2; " mph   "
End If
If winddir$ = "East" Then
    Locate 2, 59: Print "               "
    Locate 2, 82: Print airx2; " mph   "
End If
Locate 2, 68: Print "West <-> East"
Locate 3, 64: Print "You: "; points; " Computer: "; compoints
Locate 4, 71: Print "Level: "; level
Return

asking:
Locate 22, 65: Input "Again? (Yes/No):", ag$
If ag$ = "y" Or ag$ = "Y" Or ag$ = "yes" Or ag$ = "Yes" Or ag$ = "YES" Or ag$ = "yES" Or ag$ = "yeS" Then points = 0: level = 1: GoTo start:
End

Sub Clear_MB (var As Integer)
    Do Until Not _MouseButton(var)
        While _MouseInput: Wend
    Loop
End Sub 'Clear_MB
Reply
#13
Way to refine the game Ken! Thumbs up!

I did like it better when the last setting was the starting point for the next turn. This is working well as far as execution goes.
b = b + ...
Reply
#14
Thanks B+!!!! Big Grin
Reply
#15
excellent but I prefer the version where the choice made previously remains the same ...
Reply
#16
The mouse sliders are a nice upgrade. Much easier than keyboarding in the numbers. I even managed to win a first round exchange.
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
Reply
#17
(05-04-2022, 10:52 AM)Coolman Wrote: excellent but I prefer the version where the choice made previously remains the same ...

Yeah I tried hard to make it that way again but with the new click bars I can't figure it out. It might have something to do with doing extra calculations later on or something, I don't know.

(05-04-2022, 12:12 PM)OldMoses Wrote: The mouse sliders are a nice upgrade. Much easier than keyboarding in the numbers. I even managed to win a first round exchange.

Thanks OldMoses Smile
Reply
#18
"Yeah I tried hard to make it that way again but with the new click bars I can't figure it out. It might have something to do with doing extra calculations later on or something, I don't know."

Ken, If you make a sub for drawing velocity bar and feed it an x value, you can update the velocity bar with either the current mouse of the last mx value saved in a shared variable when it's players turn.

oldVelocityX = 61 'for starters until player clicks something

sub drawVelocityBar(x) ' x is mouse x
Line (61, 41)-(259, 69), _RGB32(156, 210, 237), BF
Line (61, 41)-(x, 69), _RGB32(255, 0, 1), BF
end sub

drawVelocityBar oldVelocityX ' when start player again

drawVelocityBar mx ' when he clicks it
oldVelocityX = mx when you change the bar


do likewise for the angle bar


Comment: man you change velocity so many times I don't know if I am coming or going
This is why your code keeps changing the velocity back, at player turn start
vel = 40
vel3 = 100 ' do you even use this?

then later this:
If vel < 0 Then vel = 0 ' << fine no problem there
If vel > 80 Then vel = 80 ' OK we could go 0 to 80 directly on click bar not to 100 then this line not needed
vel = Int(vel / 4) ' this is real stumper you want a max velocity of 20??? we could go 0 to 20 on click bar and skip all this changing around stuff


So what velocity range do you want to throw the ball at? It's no problem changing the click bar to that
vel = (mx - 60) / 200 * 100 ' <<< just change the 100 to the max velocity you want to throw the ball at
and throw out 5 lines messing with velocity
b = b + ...
Reply
#19
Thanks your help B+, I tried to add what you said but made a complete mess so I'm just going to stick with the code I had yesterday posted here. It's OK that the angle and velocity go back to the original amount every time. But you were right, the original code from a few years ago was very messy and it just gets me confused the more I dig into it. It's not that I don't understand what you say, because I do, but adding the right variables in the right places and the code in the right places just doesn't work for me this time with this old code. I appreciate the help though. I still think it's good how it was.
Reply
#20
I DID IT!!! I had a hunch I could do it so I went over your post again B+ and used almost everything you said. I kept the power at 100 max and got rid of vel3 and a3 and instead went with your oldVelocityX and oldAngleX and made 2 SUBs to make them anytime I needed them. I also went over where the vel's and a's are needed before and during the click bar code. And I did it! Now people are able to see their last selections on the click bars for the next turn. Thanks CoolMan for your opinion and B+ for pulling my leg on this. I also fixed the locations of some lines in the click bar code so that the power wouldn't accidentally go to over 1000. I also copied your 2 equations to change from oldVelcityX to vel and oldAngleX to a so it would say the right amount before you clicked anything.

Thanks again guys, this really makes my day. Here is the code below:

Code deleted because I found 1 fluke, the fix is on the next page.
Reply




Users browsing this thread: 1 Guest(s)