AI Seeker w/ Wall

Discussion in 'Visual Basic ( VB )' started by Ches, Mar 7, 2007.

  1. Ches

    Ches New Member

    Joined:
    Jan 31, 2007
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Hey its me again... This time my problem is a little more advanced....
    I need to create an Ai that seeks out an opponent(think Ghosts on PacMan kinda thing. )

    they wil have ap points and eveytime the move they'll lose an ap point, when these points are 0 it ened their "turn"
    ....These enemies i have dubbed enemy(x) and i need it to move, then check if it is in range to attack me(That area being enemymelee(x) )...Im stuck on a proper ai...because they will seek my character out that not run ingto walls...however, they sometimes warp or fly offsreeen........Please Help...Thanks
     
  2. Ches

    Ches New Member

    Joined:
    Jan 31, 2007
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    This is What I have right now...but for some reason its doesn't stop them from hitting walls(enemy border) :confused:

    Code:
     ' go left
      If knight.Top > Enemymelee(x).Top And (knight.Top + knight.Height) > (Enemymelee(x).Top + Enemymelee(x).Height) And (knight.Width + knight.Left) < Enemymelee(x).Left Then Enemy(x).Left = Val(Enemy(x).Left) - 160: enemymovement(x).Caption = "Left1":  Goblinap(x).Caption = Val(Goblinap(x).Caption) - 1: GoTo checkers
        'go right
      If knight.Top > Enemymelee(x).Top And (knight.Top + knight.Height) > (Enemymelee(x).Top + Enemymelee(x).Height) And knight.Left > (Enemymelee(x).Left + Enemymelee(x).Width) Then Enemy(x).Left = Val(Enemy(x).Left) + 160: enemymovement(x).Caption = "right1": Goblinap(x).Caption = Val(Goblinap(x).Caption) - 1: GoTo checkers
       'go up
       If knight.Left > Enemymelee(x).Left And (knight.Left + knight.Width) < (Enemymelee(x).Left + Enemymelee(x).Width) And knight.Top < Enemymelee(x).Top Then Enemy(x).Top = Val(Enemy(x).Top) - 270: enemymovement(x).Caption = "up1": Goblinap(x).Caption = Val(Goblinap(x).Caption) - 1: GoTo checkers
      'go down
       If knight.Left > Enemymelee(x).Left And (knight.Left + knight.Width) < (Enemymelee(x).Left + Enemymelee(x).Width) And knight.Top > Enemymelee(x).Top Then Enemy(x).Top = Val(Enemy(x).Top) + 270: enemymovement(x).Caption = "down1": Goblinap(x).Caption = Val(Goblinap(x).Caption) - 1: GoTo checkers
      ' Moveupleft1
     If knight.Left < Enemymelee(x).Left And knight.Top < Enemymelee(x).Top Then If Val(Goblinap(x).Caption) > 0 Then Enemy(x).Left = Val(Enemy(x).Left) - 160: Enemy(x).Top = Val(Enemy(x).Top) - 270: enemymovement(x).Caption = "Moveupleft1": Goblinap(x).Caption = Val(Goblinap(x).Caption) - 1: GoTo checkers
    ' Movedownright1
     If knight.Left > Enemymelee(x).Left And knight.Top > Enemymelee(x).Top Then If Val(Goblinap(x).Caption) > 0 Then Enemy(x).Left = Val(Enemy(x).Left) + 160:  Enemy(x).Top = Val(Enemy(x).Top) + 270: enemymovement(x).Caption = "Movedownright1": Goblinap(x).Caption = Val(Goblinap(x).Caption) - 1: GoTo checkers
    ' moveDownleft1
     If knight.Left < Enemymelee(x).Left And knight.Top > Enemymelee(x).Top Then If Val(Goblinap(x).Caption) > 0 Then Enemy(x).Left = Val(Enemy(x).Left) - 160: Enemy(x).Top = Val(Enemy(x).Top) + 270: enemymovement(x).Caption = "moveDownleft1": Goblinap(x).Caption = Val(Goblinap(x).Caption) - 1: GoTo checkers
       ' Moveupright1
       If knight.Left > Enemymelee(x).Width And knight.Top < Enemymelee(x).Top Then If Val(Goblinap(x).Caption) > 0 Then Enemy(x).Left = Val(Enemy(x).Left) + 160: Enemy(x).Top = Val(Enemy(x).Top) - 270: enemymovement(x).Caption = "Moveupright1": Goblinap(x).Caption = Val(Goblinap(x).Caption) - 1: GoTo checkers
    checkers:
    
      Dim Q As Integer
        For Q = 0 To enemyborder.ubound
         
    If Enemy(x).Left < Val(enemyborder(Q).Left + enemyborder(Q).Width) And _
     enemyborder(Q).Left < Val(Enemy(x).Left + Enemy(x).Width) And _
     Enemy(x).Top < enemyborder(Q).Top + enemyborder(Q).Height And _
     enemyborder(Q).Top < Enemy(x).Top + Enemy(x).Height Then enemywallCollision = True
             Next
             
             Q = Q + 1
             
          If enemywallCollision = True Then GoTo falalalal Else GoTo huh2
                
                    
            
    falalalal:
    
       If enemywallCollision = True Then If enemymovement(x).Caption = "Moveupright1" Then GoTo Moveupright1: If enemymovement(x).Caption = "Movedownright1" Then GoTo Movedownright1: If enemymovement(x).Caption = "moveDownleft1" Then GoTo moveDownleft1:      If enemymovement(x).Caption = "Moveupleft1" Then GoTo Moveupleft1: If enemymovement(x).Caption = "left1" Then GoTo Left1: If enemymovement(x).Caption = "up" Then GoTo up1: If enemymovement(x).Caption = "right1" Then GoTo Right1: If enemymovement(x).Caption = "down1" Then GoTo down1
                                
    Left1: If enemywallCollision = True Then Enemy(x).Left = Val(Enemy(x).Left) + 160: enemywallCollision = False: GoTo huh2
    Right1: If enemywallCollision = True Then Enemy(x).Left = Val(Enemy(x).Left) - 160: enemywallCollision = False: GoTo huh2
    up1: If enemywallCollision = True Then Enemy(x).Top = Val(Enemy(x).Top) + 270: enemywallCollision = False: GoTo huh2
    down1: If enemywallCollision = True Then Enemy(x).Top = Val(Enemy(x).Top) - 270: enemywallCollision = False: GoTo huh2
    Moveupright1: If enemywallCollision = True Then Enemy(x).Left = Val(Enemy(x).Left) - 160: Enemy(x).Top = Val(Enemy(x).Top) + 270: enemywallCollision = False: GoTo huh2
    Movedownright1: If enemywallCollision = True Then Enemy(x).Left = Val(Enemy(x).Left) - 160: Enemy(x).Top = Val(Enemy(x).Top) - 270: enemywallCollision = False: GoTo huh2
    moveDownleft1: If enemywallCollision = True Then Enemy(x).Left = Val(Enemy(x).Left) + 160: Enemy(x).Top = Val(Enemy(x).Top) - 270: enemywallCollision = False: GoTo huh2
    Moveupleft1: If enemywallCollision = True Then Enemy(x).Left = Val(Enemy(x).Left) + 160: Enemy(x).Top = Val(Enemy(x).Top) + 270: enemywallCollision = False: GoTo huh2
    ____________________________________________________________

    ...........also how would i slow the movement down a little ...make their movements more singularily visible...instead of just seeing the final result.....? Thanks......*ches
     
    Last edited by a moderator: Apr 8, 2007
  3. riffz

    riffz New Member

    Joined:
    Apr 7, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Canada
    Funny you should ask... I just completed a Pacman game in VB6!

    I used the A* Pathfinding Algorithm to give the ghosts AI to move around walls and stuff. Here's a tutorial:
    A* Tutorial
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    [COMMENT]Use the CODE block when you have code in the posts.[/COMMENT]
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice