[Visualbasic] Need a check to look for bouncing in my movement

Discussion in 'Mixed Languages' started by stevemk14ebr, Sep 25, 2011.

  1. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    #1 stevemk14ebr, Sep 25, 2011
    Last edited: Sep 26, 2011
    i have a simple movement-sub that if i set direction = to a number 1 through 4 and if the location that it will be moved to is = to 0 then move there but if one of it's points is =1 then switch to the opposite direction:

    Dim point1 As New Point(pacface.Left, pacface.Top)
    Dim point2 As New Point(pacface.Right, pacface.Top)
    Dim point3 As New Point(pacface.Left, pacface.Bottom)
    Dim point4 As New Point(pacface.Right, pacface.Bottom)
    '5,6,7,8 for the middle of pacman for the smaller blocks
    Dim point5 As New Point(pacface.Left, pacface.Top + (pacface.Height / 2))
    Dim point6 As New Point(pacface.Right, pacface.Top + (pacface.Height / 2))
    Dim point7 As New Point(pacface.Left + (pacface.Width / 2), pacface.Top)
    Dim point8 As New Point(pacface.Left + (pacface.Width / 2), pacface.Bottom)

    'right
    If direction1 = 2 And board(point1.X + 1, point1.Y) = 0 And board(point2.X + 1, point2.Y) = 0 And board(point3.X + 1, point3.Y) = 0 And board(point4.X + 1, point4.Y) = 0 And board(point5.X + 1, point5.Y) = 0 And board(point6.X + 1, point6.Y) = 0 And board(point7.X + 1, point7.Y) = 0 And board(point8.X + 1, point8.Y) = 0 Then
    pacface.Left += 1
    leftorright = True
    upordown = False
    ElseIf direction1 = 2 And board(point1.X + 1, point1.Y) = 1 Or board(point2.X + 1, point2.Y) = 1 Or board(point3.X + 1, point3.Y) = 1 Or board(point4.X + 1, point4.Y) = 1 Or board(point5.X + 1, point5.Y) = 1 Or board(point6.X + 1, point6.Y) = 1 Or board(point7.X + 1, point7.Y) = 1 Or board(point8.X + 1, point8.Y) = 1 Then
    direction1 = 1
    leftorright = True
    upordown = False
    End If

    'left
    If direction1 = 1 And board(point1.X - 1, point1.Y) = 0 And board(point2.X - 1, point2.Y) = 0 And board(point3.X - 1, point3.Y) = 0 And board(point4.X - 1, point4.Y) = 0 And board(point5.X - 1, point5.Y) = 0 And board(point6.X - 1, point6.Y) = 0 And board(point7.X - 1, point7.Y) = 0 And board(point8.X - 1, point8.Y) = 0 Then
    pacface.left-=1
    leftorright = True
    upordown = False
    ElseIf direction1 = 1 And board(point1.X - 1, point1.Y) = 1 Or board(point2.X - 1, point2.Y) = 1 Or board(point3.X - 1, point3.Y) = 1 Or board(point4.X - 1, point4.Y) = 1 Or board(point5.X - 1, point5.Y) = 1 Or board(point6.X - 1, point6.Y) = 1 Or board(point7.X - 1, point7.Y) = 1 Or board(point8.X - 1, point8.Y) = 1 Then
    direction1 = 2
    leftorright = True
    upordown = False
    End If

    'up
    If direction1 = 3 And board(point1.X, point1.Y - 1) = 0 And board(point2.X, point2.Y - 1) = 0 And board(point3.X, point3.Y - 1) = 0 And board(point4.X, point4.Y - 1) = 0 And board(point5.X, point5.Y - 1) = 0 And board(point6.X, point6.Y - 1) = 0 And board(point7.X, point7.Y - 1) = 0 And board(point8.X, point8.Y - 1) = 0 Then
    pacface.Top -= 1


    upordown = True
    leftorright = False
    ElseIf direction1 = 3 And board(point1.X, point1.Y - 1) = 1 Or board(point2.X, point2.Y - 1) = 1 Or board(point3.X, point3.Y - 1) = 1 Or board(point4.X, point4.Y - 1) = 1 Or board(point5.X, point5.Y - 1) = 1 Or board(point6.X, point6.Y - 1) = 1 Or board(point7.X, point7.Y - 1) = 1 Or board(point8.X, point8.Y - 1) = 1 Then
    direction1 = 4
    upordown = True
    leftorright = False
    End If

    'down
    If direction1 = 4 And board(point1.X, point1.Y + 1) = 0 And board(point2.X, point2.Y + 1) = 0 And board(point3.X, point3.Y + 1) = 0 And board(point4.X, point4.Y + 1) = 0 And board(point5.X, point5.Y + 1) = 0 And board(point6.X, point6.Y + 1) = 0 And board(point7.X, point7.Y + 1) = 0 And board(point8.X, point8.Y + 1) = 0 Then
    pacface.Top += 1

    upd = False

    ElseIf direction1 = 4 And board(point1.X, point1.Y + 1) = 1 Or board(point2.X, point2.Y + 1) = 1 Or board(point3.X, point3.Y + 1) = 1 Or board(point4.X, point4.Y + 1) = 1 Or board(point5.X, point5.Y + 1) = 1 Or board(point6.X, point6.Y + 1) = 1 Or board(point7.X, point7.Y + 1) = 1 Or board(point8.X, point8.Y + 1) = 1 Then
    direction1 = 3
    upordown = True
    leftorright = False
    End If


    just ignore the leftorright and upordown booleans. my problem is that when i enter a passageway and my direction is switch to up it just bounces up and own in that passage i need a way to check if it's just bouncing back and forth and have it go to the left or right instead of bouncing:

    ooooooooooooooooooooooooooo
    p
    00000000000000000000000000

    it will just bounce up and down
    btw board is my 2d array consisting of all x and y values and my map on the form