Results 1 to 6 of 6

Thread: Smart Monster Engine - Help!

  1. #1

    Thread Starter
    PowerPoster Arbiter's Avatar
    Join Date
    Sep 2000
    Location
    Manchester
    Posts
    2,276
    You'd need a pathfinding algorithm (such as A*) to find the best route to get there, and to hold at 2 squares away, you'd simply check before the monster took its next move how far away it was.
    Gentile or Jew,
    O you who turn the wheel and look to windward,
    Consider Phlebas, who was once handsome and tall as you...

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    Could you write it?
    These are the variables:
    Player(1).X Player(1).Y Player(2).X Player(2).Y
    Monster(m).mX Monster(m).mY

    Thank you,
    Arie.

  3. #3

    Thread Starter
    PowerPoster Arbiter's Avatar
    Join Date
    Sep 2000
    Location
    Manchester
    Posts
    2,276
    No.

    Writing a pathfinding routine is not a small task. You'd need to research it. If you check out the 'get shortest distance' thread I posted a link to good tutorial site there.

    Good luck
    Gentile or Jew,
    O you who turn the wheel and look to windward,
    Consider Phlebas, who was once handsome and tall as you...

  4. #4
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    Does anyone have a sample for this?

    Arie.

  5. #5
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Well I've an idea.
    You draw a line between the monster and the player. Convert the line into the closest connected blocks on the grid. Then if any of the boxes you've chosen have a block on them, then try going around it either side to reconnect up the line again.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  6. #6
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    I made this code but it doesn't work in the best way...

    here it is:
    Code:
         Dim Flag1 As Boolean
         Flag1 = False
         If Abs(Player(1).X - .mX) + Abs(Player(1).Y - .mY) > _
            Abs(Player(2).X - .mX) + Abs(Player(2).Y - .mY) Or NumberOfPlayers = 1 Then
            If Abs(Player(1).X - .mX) > Abs(Player(1).Y - .mY) Then
               If Player(1).X > .mX Or mBlock(.mX - 1, .mY, rmMonster) Then .mDirection = dRight Else .mDirection = dLeft
               Flag1 = True
            Else
              If (Player(1).Y < .mY And mBlock(.mX, .mY - 1, rmMonster)) Or _
                 (Player(1).Y > .mY And mBlock(.mX, .mY + 1, rmMonster)) Then
                 If Player(1).X > .mX Then .mDirection = dRight Else .mDirection = dLeft
                 Flag1 = True
                 GoTo NextIf
              End If
            End If
            
            If Abs(Player(1).X - .mX) <= Abs(Player(1).Y - .mY) Then
               If Player(1).Y > .mY Or mBlock(.mX, .mY - 1, rmMonster) Then Debug.Print "Hey!": .mDirection = dDown Else .mDirection = dUp
               Flag1 = True
            Else
              If (Player(1).X < .mX And mBlock(.mX - 1, .mY, rmMonster)) Or _
                 (Player(1).X > .mX And mBlock(.mX + 1, .mY, rmMonster)) Then
                 If Player(1).Y > .mY Then .mDirection = dDown Else .mDirection = dUp
                 Flag1 = True
                 GoTo NextIf
              End If
            End If
    
    NextIf:
         End If
         
         If Abs(Player(1).X - .mX) + Abs(Player(1).Y - .mY) <= _
            Abs(Player(2).X - .mX) + Abs(Player(2).Y - .mY) And Flag1 = False Then
            If Abs(Player(2).X - .mX) > Abs(Player(2).Y - .mY) Then
               If Player(2).X > .mX Then .mDirection = dRight Else .mDirection = dLeft
               Flag1 = True
            Else
              If (Player(2).Y < .mY And mBlock(.mX, .mY - 1, rmMonster)) Or _
                 (Player(2).Y > .mY And mBlock(.mX, .mY + 1, rmMonster)) Then
                 If Player(2).X > .mX Then .mDirection = dRight Else .mDirection = dLeft
                 Flag1 = True
                 GoTo NextIf2
              End If
            End If
            
            If Abs(Player(2).X - .mX) <= Abs(Player(2).Y - .mY) Then
               If Player(2).Y > .mY Then .mDirection = dDown Else .mDirection = dUp
               Flag1 = True
            Else
              If (Player(2).X < .mX And mBlock(.mX - 1, .mY, rmMonster)) Or _
                 (Player(2).X > .mX And mBlock(.mX + 1, .mY, rmMonster)) Then
                 If Player(2).Y > .mY Then .mDirection = dDown Else .mDirection = dUp
                 Flag1 = True
                 GoTo NextIf2
              End If
            End If
    
    NextIf2:
         End If
         .mMoving = Flag1
    Tell me what's wrong...
    Thank you,
    Arie.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width