Link to home
Start Free TrialLog in
Avatar of thehegemon
thehegemon

asked on

Four timers running, some randomly disable

Good luck with this one ...

I can't figure out why, but for some reason one or more of the four timers moving the shapes around seem to randomly disable. I apogize for the messy code, I'm still getting the hang of VB.



'
Dim badl1 As Boolean
Dim badr1 As Boolean
Dim badu1 As Boolean
Dim badd1 As Boolean
Dim bad1dir As String
Dim bad1speed As Integer
Dim wallindexbad1 As Integer
Dim bad1side As String
'
Dim badl2 As Boolean
Dim badr2 As Boolean
Dim badu2 As Boolean
Dim badd2 As Boolean
Dim bad2dir As String
Dim bad2speed As Integer
Dim wallindexbad2 As Integer
Dim bad2side As String
'
Dim badl3 As Boolean
Dim badr3 As Boolean
Dim badu3 As Boolean
Dim badd3 As Boolean
Dim bad3dir As String
Dim bad3speed As Integer
Dim wallindexbad3 As Integer
Dim bad3side As String
'
Dim left1 As Boolean
Dim right1 As Boolean
Dim up1 As Boolean
Dim down1 As Boolean
Dim dir As String
Dim boxspeed As Integer

'******************************************************
'
'BEGIN PAC MOVEMENT

'******************************************************
Private Sub bad1_KeyDown(KeyCode As Integer, Shift As Integer)
Call okPAC

If KeyCode = vbKeyLeft And left1 = True Then
dir = "left"
ElseIf KeyCode = vbKeyRight And right1 = True Then
dir = "right"
ElseIf KeyCode = vbKeyDown And down1 = True Then
dir = "down"
ElseIf KeyCode = vbKeyUp And up1 = True Then
dir = "up"
End If
End Sub
Private Sub bad2_KeyDown(KeyCode As Integer, Shift As Integer)
Call okPAC

If KeyCode = vbKeyLeft And left1 = True Then
dir = "left"
ElseIf KeyCode = vbKeyRight And right1 = True Then
dir = "right"
ElseIf KeyCode = vbKeyDown And down1 = True Then
dir = "down"
ElseIf KeyCode = vbKeyUp And up1 = True Then
dir = "up"
End If
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Call okPAC

If KeyCode = vbKeyLeft And left1 = True Then
dir = "left"
ElseIf KeyCode = vbKeyRight And right1 = True Then
dir = "right"
ElseIf KeyCode = vbKeyDown And down1 = True Then
dir = "down"
ElseIf KeyCode = vbKeyUp And up1 = True Then
dir = "up"
End If
End Sub

Private Sub okPAC()
Dim int1 As Integer
Dim num As Integer
Dim boxRight As Double
Dim boxBot As Double

boxRight = (box.Left + box.Width)
boxBot = (box.Top + box.Height)


left1 = True
right1 = True
up1 = True
down1 = True

Do
    If int1 = 0 Then
        int1 = Shape1.LBound
    Else
        int1 = int1 + 1
    End If

'check all indexes of the shapes

For num = 0 To boxspeed

'check for approaching walls

    If box.Left = Shape1(int1).Left + num And boxBot >= Shape1(int1).Top And (box.Top) <= (Shape1(int1).Top + Shape1(int1).Height) Then
        'left wall
        left1 = False
    ElseIf boxRight = Shape1(int1).Left + num And boxBot >= Shape1(int1).Top And (box.Top) <= (Shape1(int1).Top + Shape1(int1).Height) Then
        'right wall, right point
        right1 = False
    ElseIf box.Top = Shape1(int1).Top + num And (boxRight) >= Shape1(int1).Left And box.Left <= (Shape1(int1).Left + Shape1(int1).Width) Then
        'top wall
        up1 = False
    ElseIf (boxBot) = Shape1(int1).Top + num And (boxRight) >= Shape1(int1).Left And box.Left <= (Shape1(int1).Left + Shape1(int1).Width) Then
        'bottom wall, bottom point
        down1 = False
    ElseIf box.Left = (Shape1(int1).Left + Shape1(int1).Width) + num And boxBot >= Shape1(int1).Top And (box.Top) <= (Shape1(int1).Top + Shape1(int1).Height) Then
        'left point
        left1 = False
    ElseIf box.Top = (Shape1(int1).Top + Shape1(int1).Height) + num And (boxRight) >= Shape1(int1).Left And box.Left <= (Shape1(int1).Left + Shape1(int1).Width) Then
        'top point
        up1 = False
    End If
   
    Next num

Loop While int1 < Shape1.UBound

End Sub
'
'
'      FORM LOAD
'

Private Sub Form_Load()
dir = "left"
boxspeed = 20
left1 = True
right1 = True
up1 = True
down1 = True

bad1speed = boxspeed
bad1dir = "left"
badl1 = True
badr1 = True
badu1 = True
badd1 = True

bad2speed = boxspeed
bad2dir = "up"
badl2 = True
badr2 = True
badu2 = True
badd2 = True
baddy2.Enabled = True

bad3speed = boxspeed
bad3dir = "up"
badl3 = True
badr3 = True
badu3 = True
badd3 = True
baddy3.Enabled = True
End Sub

'
' END FORM LOAD
'
'

Private Sub Timer1_Timer()
Call okPAC
If dir = "left" And left1 = True Then
box.Left = box.Left - boxspeed
ElseIf dir = "right" And right1 = True Then
box.Left = box.Left + boxspeed
ElseIf dir = "up" And up1 = True Then
box.Top = box.Top - boxspeed
ElseIf dir = "down" And down1 = True Then
box.Top = box.Top + boxspeed
End If

End Sub

'******************************************************

'END PAC MOVEMENT
'BEGIN BADDY 1

'******************************************************

Private Sub baddy1_Timer()
Call okBAD1
Call BestDirBaddy1

If bad1dir = "left" And badl1 = True Then
bad1.Left = bad1.Left - bad1speed
ElseIf bad1dir = "right" And badr1 = True Then
bad1.Left = bad1.Left + bad1speed
ElseIf bad1dir = "up" And badu1 = True Then
bad1.Top = bad1.Top - bad1speed
ElseIf bad1dir = "down" And badd1 = True Then
bad1.Top = bad1.Top + bad1speed
End If
End Sub

Private Sub okBAD1()
Dim int1 As Integer
Dim num As Integer
Dim bad1Right As Double
Dim bad1Bot As Double

bad1Right = (bad1.Left + bad1.Width)
bad1Bot = (bad1.Top + bad1.Height)

badl1 = True
badr1 = True
badu1 = True
badd1 = True

Do
    If int1 = 0 Then
        int1 = Shape1.LBound
    Else
        int1 = int1 + 1
    End If

'check all indexes of the shapes

For num = 0 To bad1speed

'check for approaching walls

    If bad1.Left = Shape1(int1).Left + num And bad1Bot >= Shape1(int1).Top And (bad1.Top) <= (Shape1(int1).Top + Shape1(int1).Height) Then
        'left wall
        badl1 = False
    ElseIf bad1Right = Shape1(int1).Left + num And bad1Bot >= Shape1(int1).Top And (bad1.Top) <= (Shape1(int1).Top + Shape1(int1).Height) Then
        'right wall, right point
       badr1 = False
    ElseIf bad1.Top = Shape1(int1).Top + num And (bad1Right) >= Shape1(int1).Left And bad1.Left <= (Shape1(int1).Left + Shape1(int1).Width) Then
        'top wall
        badu1 = False
    ElseIf (bad1Bot) = Shape1(int1).Top + num And (bad1Right) >= Shape1(int1).Left And bad1.Left <= (Shape1(int1).Left + Shape1(int1).Width) Then
        'bottom wall, bottom point
        badd1 = False
    ElseIf bad1.Left = (Shape1(int1).Left + Shape1(int1).Width) + num And bad1Bot >= Shape1(int1).Top And (bad1.Top) <= (Shape1(int1).Top + Shape1(int1).Height) Then
        'left point
        badl1 = False
    ElseIf bad1.Top = (Shape1(int1).Top + Shape1(int1).Height) + num And (bad1Right) >= Shape1(int1).Left And bad1.Left <= (Shape1(int1).Left + Shape1(int1).Width) Then
        'top point
        badu1 = False
    End If
   
    Next num

Loop While int1 < Shape1.UBound

End Sub

Private Sub BestDirBaddy1()
Dim xlength As Integer
Dim ylength As Integer
Dim shape1bot As Integer
Dim xdir

xlength = (bad1.Left - box.Left)
ylength = (bad1.Top - box.Top)

If Abs(xlength) > Abs(ylength) And Sgn(xlength) = 1 Then 'going left
    If badl1 = False Then
        If Sgn(ylength) = 1 Then 'move in the vert dir closer to pac
            If badu1 = True Then
                bad1dir = "up"
            Else
                bad1dir = "down"
            End If
        ElseIf Sgn(ylength) = -1 Then
            If badd1 = True Then
                bad1dir = "down"
            Else
                bad1dir = "up"
            End If
        ElseIf Sgn(ylength) = 0 Then
           
        Call findrightbad1("left") 'finding the shape index of the shape in it's path
        If ((Shape1(wallindexbad1).Top + Shape1(wallindexbad1).Height) - bad1.Top) < ((bad1.Top + bad1.Height) - (Shape1(wallindexbad1).Top)) Then
            bad1dir = "down"
        Else
            bad1dir = "up"
        End If
               
        End If
    Else
        bad1dir = "left"
    End If
   
ElseIf Abs(xlength) > Abs(ylength) And Sgn(xlength) = -1 Then 'going right
   
    If badr1 = False Then
   
'Tells baddy to move up, then corrects Y distance by moving back down,
'creating a wavering motion. Need AI to move around walls

        If Sgn(ylength) = 1 Then 'move in the vert dir closer to pac
            If badu1 = True Then
                bad1dir = "up"
            Else
                bad1dir = "down"
            End If
        ElseIf Sgn(ylength) = -1 Then
            If badd1 = True Then
                bad1dir = "down"
            Else
                bad1dir = "up"
            End If
        ElseIf Sgn(ylength) = 0 Then
        Call findrightbad1("right")
        If ((Shape1(wallindexbad1).Top + Shape1(wallindexbad1).Height) - bad1.Top) < ((bad1.Top + bad1.Height) - (Shape1(wallindexbad1).Top)) Then
            bad1dir = "down"
        Else
            bad1dir = "up"
        End If
    End If
'*****************************************************************
    Else
        bad1dir = "right"
    End If
   
ElseIf Abs(ylength) > Abs(xlength) And Sgn(ylength) = 1 Then 'going up
    If badu1 = False Then
            If Sgn(xlength) = 1 Then 'move in the horiz dir closer to pac
            If badl1 = True Then
                bad1dir = "left"
            Else
                bad1dir = "right"
            End If
        ElseIf Sgn(xlength) = -1 Then
            If badr1 = True Then
                bad1dir = "right"
            Else
                bad1dir = "down"
            End If
        ElseIf Sgn(ylength) = 0 Then
       
        Call findrightbad1("up")
        If ((bad1.Left + bad1.Width) - (Shape1(wallindexbad1).Left)) > ((Shape1(wallindexbad1).Left + Shape1(wallindexbad1).Width) - bad1.Left) Then
            bad1dir = "right"
        Else
            bad1dir = "left"
        End If
    End If
    Else
        bad1dir = "up"
    End If
   
ElseIf Abs(ylength) > Abs(xlength) And Sgn(ylength) = -1 Then 'going down
    If badd1 = False Then
        If Sgn(xlength) = 1 Then 'move in the horiz dir closer to pac
            If badl1 = True Then
                bad1dir = "left"
            Else
                bad1dir = "right"
            End If
        ElseIf Sgn(xlength) = -1 Then
            If badr1 = True Then
                bad1dir = "right"
            Else
                bad1dir = "down"
            End If
        ElseIf Sgn(ylength) = 0 Then
    Call findrightbad1("down")
        If ((bad1.Left + bad1.Width) - (Shape1(wallindexbad1).Left)) > ((Shape1(wallindexbad1).Left + Shape1(wallindexbad1).Width) - bad1.Left) Then
            bad1dir = "right"
        Else
            bad1dir = "left"
        End If
        End If
    Else
        bad1dir = "down"
    End If


'SQUARE **********************************

ElseIf Abs(xlength) = Abs(ylength) Then
    If Sgn(ylength) = 1 And badu1 = True Then
        bad1dir = "up"
    ElseIf Sgn(ylength) = 1 And badu1 = False Then
        If Sgn(xlength) = 1 Then
            bad1dir = "left"
        Else
            bad1dir = "right"
        End If
    ElseIf Sgn(ylength) = -1 And badd1 = True Then
        bad1dir = "down"
    ElseIf Sgn(ylength) = -1 And badd1 = False Then
        If Sgn(xlength) = 1 Then
            bad1dir = "left"
        Else
            bad1dir = "right"
        End If
    End If
End If

End Sub

Private Sub findrightbad1(ByVal bad1side As String)
Dim int1 As Integer
Dim num As Integer
Dim bad1Right As Double
Dim bad1Bot As Double

bad1Right = (bad1.Left + bad1.Width)
bad1Bot = (bad1.Top + bad1.Height)


badl1 = True
badr1 = True
badu1 = True
badd1 = True

Do
    If int1 = 0 Then
        int1 = Shape1.LBound
    Else
        int1 = int1 + 1
    End If
For num = -bad1speed To bad1speed

    If bad1side = "right" Then

        If Shape1(int1).Left + num = bad1Right Then
            wallindexbad1 = int1
        End If
    ElseIf bad1side = "left" Then
        If Shape1(int1).Left + num = bad1.Left Then
            wallindexbad1 = int1
        End If
    ElseIf bad1side = "up" Then
        If Shape1(int1).Top + num = bad1.Top Then
            wallindexbad1 = int1
        End If
    ElseIf bad1side = "down" Then
        If Shape1(int1).Top + num = bad1Bot Then
            wallindexbad1 = int1
        End If
    End If
Next num

Loop While int1 < Shape1.UBound

End Sub

'****************************************************************
'****************************************************************

'       END OF BADDY 1
'
'       BEGIN BADDY 2
'
'*****************************************************************
'*****************************************************************

Private Sub baddy2_Timer()
Call okBAD2
Call BestDirBaddy2

Debug.Print (bad2.Left)
If bad2dir = "left" And badl2 = True Then
bad2.Left = bad2.Left - bad2speed
ElseIf bad2dir = "right" And badr2 = True Then
bad2.Left = bad2.Left + bad2speed
ElseIf bad2dir = "up" And badu2 = True Then
bad2.Top = bad2.Top - bad2speed
ElseIf bad2dir = "down" And badd2 = True Then
bad2.Top = bad2.Top + bad2speed
End If
End Sub

Private Sub okBAD2()
Dim int1 As Integer
Dim num As Integer
Dim bad2Right As Double
Dim bad2Bot As Double

bad2Right = (bad2.Left + bad2.Width)
bad2Bot = (bad2.Top + bad2.Height)

badl2 = True
badr2 = True
badu2 = True
badd2 = True

Do
    If int1 = 0 Then
        int1 = Shape1.LBound
    Else
        int1 = int1 + 1
    End If

'check all indexes of the shapes

For num = 0 To bad2speed

'check for approaching walls

    If bad2.Left = Shape1(int1).Left + num And bad2Bot >= Shape1(int1).Top And (bad2.Top) <= (Shape1(int1).Top + Shape1(int1).Height) Then
        'left wall
        badl2 = False
    ElseIf bad2Right = Shape1(int1).Left + num And bad2Bot >= Shape1(int1).Top And (bad2.Top) <= (Shape1(int1).Top + Shape1(int1).Height) Then
        'right wall, right point
       badr2 = False
    ElseIf bad2.Top = Shape1(int1).Top + num And (bad2Right) >= Shape1(int1).Left And bad2.Left <= (Shape1(int1).Left + Shape1(int1).Width) Then
        'top wall
        badu2 = False
    ElseIf (bad2Bot) = Shape1(int1).Top + num And (bad2Right) >= Shape1(int1).Left And bad2.Left <= (Shape1(int1).Left + Shape1(int1).Width) Then
        'bottom wall, bottom point
        badd2 = False
    ElseIf bad2.Left = (Shape1(int1).Left + Shape1(int1).Width) + num And bad2Bot >= Shape1(int1).Top And (bad2.Top) <= (Shape1(int1).Top + Shape1(int1).Height) Then
        'left point
        badl2 = False
    ElseIf bad2.Top = (Shape1(int1).Top + Shape1(int1).Height) + num And (bad2Right) >= Shape1(int1).Left And bad2.Left <= (Shape1(int1).Left + Shape1(int1).Width) Then
        'top point
        badu2 = False
    End If
   
    Next num

Loop While int1 < Shape1.UBound

End Sub

Private Sub BestDirBaddy2()
Dim xlength As Integer
Dim ylength As Integer
Dim shape1bot As Integer
Dim xdir

xlength = (bad2.Left - box.Left)
ylength = (bad2.Top - box.Top)

If Abs(xlength) > Abs(ylength) And Sgn(xlength) = 1 Then 'going left
    If badl2 = False Then
        If Sgn(ylength) = 1 Then 'move in the vert dir closer to pac
            If badu2 = True Then
                bad2dir = "up"
            Else
                bad2dir = "down"
            End If
        ElseIf Sgn(ylength) = -1 Then
            If badd2 = True Then
                bad2dir = "down"
            Else
                bad2dir = "up"
            End If
        ElseIf Sgn(ylength) = 0 Then
           
        Call findrightbad2("left") 'finding the shape index of the shape in it's path
        If ((Shape1(wallindexbad2).Top + Shape1(wallindexbad2).Height) - bad2.Top) < ((bad2.Top + bad2.Height) - (Shape1(wallindexbad2).Top)) Then
            bad2dir = "down"
        Else
            bad2dir = "up"
        End If
               
        End If
    Else
        bad2dir = "left"
    End If
   
ElseIf Abs(xlength) > Abs(ylength) And Sgn(xlength) = -1 Then 'going right
   
    If badr2 = False Then
   
'Tells baddy to move up, then corrects Y distance by moving back down,
'creating a wavering motion. Need AI to move around walls

        If Sgn(ylength) = 1 Then 'move in the vert dir closer to pac
            If badu2 = True Then
                bad2dir = "up"
            Else
                bad2dir = "down"
            End If
        ElseIf Sgn(ylength) = -1 Then
            If badd2 = True Then
                bad2dir = "down"
            Else
                bad2dir = "up"
            End If
        ElseIf Sgn(ylength) = 0 Then
        Call findrightbad2("right")
        If ((Shape1(wallindexbad2).Top + Shape1(wallindexbad2).Height) - bad2.Top) < ((bad2.Top + bad2.Height) - (Shape1(wallindexbad2).Top)) Then
            bad2dir = "down"
        Else
            bad2dir = "up"
        End If
    End If
'*****************************************************************
    Else
        bad2dir = "right"
    End If
   
ElseIf Abs(ylength) > Abs(xlength) And Sgn(ylength) = 1 Then 'going up
    If badu2 = False Then
            If Sgn(xlength) = 1 Then 'move in the horiz dir closer to pac
            If badl2 = True Then
                bad2dir = "left"
            Else
                bad2dir = "right"
            End If
        ElseIf Sgn(xlength) = -1 Then
            If badr2 = True Then
                bad2dir = "right"
            Else
                bad2dir = "down"
            End If
        ElseIf Sgn(ylength) = 0 Then
       
        Call findrightbad2("up")
        If ((bad2.Left + bad2.Width) - (Shape1(wallindexbad2).Left)) > ((Shape1(wallindexbad2).Left + Shape1(wallindexbad2).Width) - bad2.Left) Then
            bad2dir = "right"
        Else
            bad2dir = "left"
        End If
    End If
    Else
        bad2dir = "up"
    End If
   
ElseIf Abs(ylength) > Abs(xlength) And Sgn(ylength) = -1 Then 'going down
    If badd2 = False Then
        If Sgn(xlength) = 1 Then 'move in the horiz dir closer to pac
            If badl2 = True Then
                bad2dir = "left"
            Else
                bad2dir = "right"
            End If
        ElseIf Sgn(xlength) = -1 Then
            If badr2 = True Then
                bad2dir = "right"
            Else
                bad2dir = "down"
            End If
        ElseIf Sgn(ylength) = 0 Then
    Call findrightbad2("down")
        If ((bad2.Left + bad2.Width) - (Shape1(wallindexbad2).Left)) > ((Shape1(wallindexbad2).Left + Shape1(wallindexbad2).Width) - bad1.Left) Then
            bad2dir = "right"
        Else
            bad2dir = "left"
        End If
        End If
    Else
        bad2dir = "down"
    End If


'SQUARE **********************************

ElseIf Abs(xlength) = Abs(ylength) Then
    If Sgn(ylength) = 1 And badu2 = True Then
        bad2dir = "up"
    ElseIf Sgn(ylength) = 1 And badu2 = False Then
        If Sgn(xlength) = 1 Then
            bad2dir = "left"
        Else
            bad2dir = "right"
        End If
    ElseIf Sgn(ylength) = -1 And badd2 = True Then
        bad2dir = "down"
    ElseIf Sgn(ylength) = -1 And badd2 = False Then
        If Sgn(xlength) = 1 Then
            bad2dir = "left"
        Else
            bad2dir = "right"
        End If
    End If
End If

End Sub

Private Sub findrightbad2(ByVal bad2side As String)
Dim int1 As Integer
Dim num As Integer
Dim bad2Right As Double
Dim bad2Bot As Double

bad2Right = (bad2.Left + bad2.Width)
bad2Bot = (bad2.Top + bad2.Height)


badl2 = True
badr2 = True
badu2 = True
badd2 = True

Do
    If int1 = 0 Then
        int1 = Shape1.LBound
    Else
        int1 = int1 + 1
    End If
For num = -bad2speed To bad2speed

    If bad2side = "right" Then

        If Shape1(int1).Left + num = bad2Right Then
            wallindexbad2 = int1
        End If
    ElseIf bad2side = "left" Then
        If Shape1(int1).Left + num = bad2.Left Then
            wallindexbad2 = int1
        End If
    ElseIf bad2side = "up" Then
        If Shape1(int1).Top + num = bad2.Top Then
            wallindexbad2 = int1
        End If
    ElseIf bad2side = "down" Then
        If Shape1(int1).Top + num = bad2Bot Then
            wallindexbad2 = int1
        End If
    End If
Next num

Loop While int1 < Shape1.UBound

End Sub



'****************************************************************
'****************************************************************

'       END OF BADDY 2     THREE
'                          THREE
'       BEGIN BADDY 3      THREE
'
'*****************************************************************
'*****************************************************************

Private Sub baddy3_Timer()
Call okBAD3
Call BestDirBaddy3


If bad3dir = "left" And badl3 = True Then
bad3.Left = bad3.Left - bad3speed
ElseIf bad3dir = "right" And badr3 = True Then
bad3.Left = bad3.Left + bad3speed
ElseIf bad3dir = "up" And badu3 = True Then
bad3.Top = bad3.Top - bad3speed
ElseIf bad3dir = "down" And badd3 = True Then
bad3.Top = bad3.Top + bad3speed
End If
End Sub

Private Sub okBAD3()
Dim int1 As Integer
Dim num As Integer
Dim bad3Right As Double
Dim bad3Bot As Double

bad3Right = (bad3.Left + bad3.Width)
bad3Bot = (bad3.Top + bad3.Height)

badl3 = True
badr3 = True
badu3 = True
badd3 = True

Do
    If int1 = 0 Then
        int1 = Shape1.LBound
    Else
        int1 = int1 + 1
    End If

'check all indexes of the shapes

For num = 0 To bad3speed

'check for approaching walls

    If bad3.Left = Shape1(int1).Left + num And bad3Bot >= Shape1(int1).Top And (bad3.Top) <= (Shape1(int1).Top + Shape1(int1).Height) Then
        'left wall
        badl3 = False
    ElseIf bad3Right = Shape1(int1).Left + num And bad3Bot >= Shape1(int1).Top And (bad3.Top) <= (Shape1(int1).Top + Shape1(int1).Height) Then
        'right wall, right point
       badr3 = False
    ElseIf bad3.Top = Shape1(int1).Top + num And (bad3Right) >= Shape1(int1).Left And bad3.Left <= (Shape1(int1).Left + Shape1(int1).Width) Then
        'top wall
        badu3 = False
    ElseIf (bad3Bot) = Shape1(int1).Top + num And (bad3Right) >= Shape1(int1).Left And bad3.Left <= (Shape1(int1).Left + Shape1(int1).Width) Then
        'bottom wall, bottom point
        badd3 = False
    ElseIf bad3.Left = (Shape1(int1).Left + Shape1(int1).Width) + num And bad3Bot >= Shape1(int1).Top And (bad3.Top) <= (Shape1(int1).Top + Shape1(int1).Height) Then
        'left point
        badl3 = False
    ElseIf bad3.Top = (Shape1(int1).Top + Shape1(int1).Height) + num And (bad3Right) >= Shape1(int1).Left And bad3.Left <= (Shape1(int1).Left + Shape1(int1).Width) Then
        'top point
        badu3 = False
    End If
   
    Next num

Loop While int1 < Shape1.UBound

End Sub

Private Sub BestDirBaddy3()
Dim xlength As Integer
Dim ylength As Integer
Dim shape1bot As Integer
Dim xdir

xlength = (bad3.Left - box.Left)
ylength = (bad3.Top - box.Top)

If Abs(xlength) > Abs(ylength) And Sgn(xlength) = 1 Then 'going left
    If badl3 = False Then
        If Sgn(ylength) = 1 Then 'move in the vert dir closer to pac
            If badu3 = True Then
                bad3dir = "up"
            Else
                bad3dir = "down"
            End If
        ElseIf Sgn(ylength) = -1 Then
            If badd3 = True Then
                bad3dir = "down"
            Else
                bad3dir = "up"
            End If
        ElseIf Sgn(ylength) = 0 Then
           
        Call findrightbad3("left") 'finding the shape index of the shape in it's path
        If ((Shape1(wallindexbad3).Top + Shape1(wallindexbad3).Height) - bad3.Top) < ((bad3.Top + bad3.Height) - (Shape1(wallindexbad3).Top)) Then
            bad3dir = "down"
        Else
            bad3dir = "up"
        End If
               
        End If
    Else
        bad3dir = "left"
    End If
   
ElseIf Abs(xlength) > Abs(ylength) And Sgn(xlength) = -1 Then 'going right
   
    If badr3 = False Then
   
'Tells baddy to move up, then corrects Y distance by moving back down,
'creating a wavering motion. Need AI to move around walls

        If Sgn(ylength) = 1 Then 'move in the vert dir closer to pac
            If badu3 = True Then
                bad3dir = "up"
            Else
                bad3dir = "down"
            End If
        ElseIf Sgn(ylength) = -1 Then
            If badd3 = True Then
                bad3dir = "down"
            Else
                bad3dir = "up"
            End If
        ElseIf Sgn(ylength) = 0 Then
        Call findrightbad3("right")
        If ((Shape1(wallindexbad3).Top + Shape1(wallindexbad3).Height) - bad3.Top) < ((bad3.Top + bad3.Height) - (Shape1(wallindexbad3).Top)) Then
            bad3dir = "down"
        Else
            bad3dir = "up"
        End If
    End If
'*****************************************************************
    Else
        bad3dir = "right"
    End If
   
ElseIf Abs(ylength) > Abs(xlength) And Sgn(ylength) = 1 Then 'going up
    If badu3 = False Then
            If Sgn(xlength) = 1 Then 'move in the horiz dir closer to pac
            If badl3 = True Then
                bad3dir = "left"
            Else
                bad3dir = "right"
            End If
        ElseIf Sgn(xlength) = -1 Then
            If badr3 = True Then
                bad3dir = "right"
            Else
                bad3dir = "down"
            End If
        ElseIf Sgn(ylength) = 0 Then
       
        Call findrightbad3("up")
        If ((bad3.Left + bad3.Width) - (Shape1(wallindexbad3).Left)) > ((Shape1(wallindexbad3).Left + Shape1(wallindexbad3).Width) - bad3.Left) Then
            bad3dir = "right"
        Else
            bad3dir = "left"
        End If
    End If
    Else
        bad3dir = "up"
    End If
   
ElseIf Abs(ylength) > Abs(xlength) And Sgn(ylength) = -1 Then 'going down
    If badd3 = False Then
        If Sgn(xlength) = 1 Then 'move in the horiz dir closer to pac
            If badl3 = True Then
                bad3dir = "left"
            Else
                bad3dir = "right"
            End If
        ElseIf Sgn(xlength) = -1 Then
            If badr3 = True Then
                bad3dir = "right"
            Else
                bad3dir = "down"
            End If
        ElseIf Sgn(ylength) = 0 Then
    Call findrightbad3("down")
        If ((bad3.Left + bad3.Width) - (Shape1(wallindexbad3).Left)) > ((Shape1(wallindexbad3).Left + Shape1(wallindexbad3).Width) - bad1.Left) Then
            bad3dir = "right"
        Else
            bad3dir = "left"
        End If
        End If
    Else
        bad3dir = "down"
    End If


'SQUARE **********************************

ElseIf Abs(xlength) = Abs(ylength) Then
    If Sgn(ylength) = 1 And badu3 = True Then
        bad3dir = "up"
    ElseIf Sgn(ylength) = 1 And badu3 = False Then
        If Sgn(xlength) = 1 Then
            bad3dir = "left"
        Else
            bad3dir = "right"
        End If
    ElseIf Sgn(ylength) = -1 And badd3 = True Then
        bad3dir = "down"
    ElseIf Sgn(ylength) = -1 And badd3 = False Then
        If Sgn(xlength) = 1 Then
            bad3dir = "left"
        Else
            bad3dir = "right"
        End If
    End If
End If

End Sub

Private Sub findrightbad3(ByVal bad3side As String)
Dim int1 As Integer
Dim num As Integer
Dim bad3Right As Double
Dim bad3Bot As Double

bad3Right = (bad3.Left + bad3.Width)
bad3Bot = (bad3.Top + bad3.Height)


badl3 = True
badr3 = True
badu3 = True
badd3 = True

Do
    If int1 = 0 Then
        int1 = Shape1.LBound
    Else
        int1 = int1 + 1
    End If
For num = -bad3speed To bad3speed

    If bad3side = "right" Then

        If Shape1(int1).Left + num = bad3Right Then
            wallindexbad3 = int1
        End If
    ElseIf bad3side = "left" Then
        If Shape1(int1).Left + num = bad3.Left Then
            wallindexbad3 = int1
        End If
    ElseIf bad3side = "up" Then
        If Shape1(int1).Top + num = bad3.Top Then
            wallindexbad3 = int1
        End If
    ElseIf bad3side = "down" Then
        If Shape1(int1).Top + num = bad3Bot Then
            wallindexbad3 = int1
        End If
    End If
Next num

Loop While int1 < Shape1.UBound

End Sub
Avatar of hvdberg
hvdberg

Could you open the .FRM file in notepad, select all text in it and post that as well? That would be helpful in recreating the form that you're using.

If you have more than one form, post all the forms, please.
Avatar of thehegemon

ASKER

VERSION 5.00
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   7305
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   9795
   LinkTopic       =   "Form1"
   ScaleHeight     =   7305
   ScaleWidth      =   9795
   StartUpPosition =   3  'Windows Default
   Begin VB.Timer baddy3
      Interval        =   1
      Left            =   5520
      Top             =   4080
   End
   Begin VB.Timer baddy2
      Interval        =   1
      Left            =   4920
      Top             =   3360
   End
   Begin VB.Timer baddy1
      Interval        =   1
      Left            =   4680
      Top             =   4080
   End
   Begin VB.Timer Timer1
      Interval        =   1
      Left            =   3000
      Top             =   1800
   End
   Begin VB.Shape bad3
      Height          =   255
      Left            =   5520
      Shape           =   3  'Circle
      Top             =   3840
      Width           =   375
   End
   Begin VB.Shape bad2
      Height          =   255
      Left            =   5160
      Shape           =   3  'Circle
      Top             =   3840
      Width           =   375
   End
   Begin VB.Shape bad1
      Height          =   255
      Left            =   4800
      Shape           =   3  'Circle
      Top             =   3840
      Width           =   375
   End
   Begin VB.Shape Shape1
      Height          =   15
      Index           =   12
      Left            =   6120
      Top             =   2400
      Width           =   2175
   End
   Begin VB.Shape Shape1
      Height          =   2895
      Index           =   11
      Left            =   4200
      Top             =   1560
      Width           =   15
   End
   Begin VB.Shape Shape1
      Height          =   3495
      Index           =   13
      Left            =   2160
      Top             =   960
      Width           =   15
   End
   Begin VB.Shape box
      Height          =   255
      Left            =   3720
      Top             =   2880
      Width           =   255
   End
   Begin VB.Shape Shape1
      Height          =   15
      Index           =   9
      Left            =   6960
      Top             =   4440
      Width           =   2175
   End
   Begin VB.Shape Shape1
      Height          =   3495
      Index           =   8
      Left            =   6120
      Top             =   960
      Width           =   15
   End
   Begin VB.Shape Shape1
      Height          =   15
      Index           =   7
      Left            =   4200
      Top             =   5160
      Width           =   3255
   End
   Begin VB.Shape Shape1
      Height          =   15
      Index           =   6
      Left            =   6000
      Top             =   5760
      Width           =   2895
   End
   Begin VB.Shape Shape1
      Height          =   15
      Index           =   5
      Left            =   1080
      Top             =   5160
      Width           =   2175
   End
   Begin VB.Shape Shape1
      Height          =   15
      Index           =   4
      Left            =   600
      Top             =   960
      Width           =   8775
   End
   Begin VB.Shape Shape1
      Height          =   5535
      Index           =   3
      Left            =   9360
      Top             =   960
      Width           =   15
   End
   Begin VB.Shape Shape1
      Height          =   15
      Index           =   10
      Left            =   1320
      Top             =   5760
      Width           =   3735
   End
   Begin VB.Shape Shape1
      Height          =   5535
      Index           =   1
      Left            =   600
      Top             =   960
      Width           =   15
   End
   Begin VB.Shape Shape1
      Height          =   15
      Index           =   2
      Left            =   600
      Top             =   6480
      Width           =   8775
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
What is the program supposed to do? I ran it for 3 minutes straight. No timer was disabled, although I did notice that one of the circles never moved. Once two of the circles where in the box, they stayed there and followed it when I moved the box around the screen. Also, when I moved the box to the not moving circle, I noticed that this circle didn't start following the box when it was captured by the box.
All three of the circles are supposed to follow the box. When the program runs, only two of the timers will run (they aren't technically disabled)- leaving either one circle and the box not moving, or two circles. I can't figure out why the timers stop working.
ASKER CERTIFIED SOLUTION
Avatar of FunkyMeister
FunkyMeister

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh yes, I forgot.  Reviving Pac Man are you?  :)
Ah ... kickass ... thanks dude.

And yes, it is pacman, however, I'm going to make the three ghosts have unbeatable AI.

(The whole point isn't pacman, but AI)
I actually wrote a Pacman for my assembler course in school (umm, decades ago) and the AI in those things were hard back then (meaning there WERE tricks to get out of it, but if they came at you at all 4 directions, you were toast).

Just figured doing it in a structured way would make your life a LOT easier.  For the baddies, perhaps use any value above 0 for the mobile and 0 for the player, that way, the movement routine could check on 0 player, for a key press.  And anything above 0, the AI would look at 0's data.  :)

Another idea, map out the area using an array, so the ghosts (baddies) can map a path.  Kind of like those old mouse maze runner programs in the ol' days.