|
-
Jan 2nd, 2002, 05:50 PM
#1
Thread Starter
PowerPoster
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...
-
Jan 3rd, 2002, 05:56 AM
#2
Fanatic Member
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.
-
Jan 3rd, 2002, 06:04 AM
#3
Thread Starter
PowerPoster
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...
-
Jan 4th, 2002, 11:55 AM
#4
Fanatic Member
Does anyone have a sample for this?
Arie.
-
Jan 4th, 2002, 11:59 AM
#5
Retired VBF Adm1nistrator
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]
-
Jan 4th, 2002, 12:11 PM
#6
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|