Click to See Complete Forum and Search --> : Smart Monster Engine - Help!
Arbiter
Jan 2nd, 2002, 04:50 PM
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.
Arie
Jan 3rd, 2002, 04:56 AM
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.
Arbiter
Jan 3rd, 2002, 05:04 AM
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 :)
Arie
Jan 4th, 2002, 10:55 AM
Does anyone have a sample for this?
Arie.
plenderj
Jan 4th, 2002, 10:59 AM
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.
Arie
Jan 4th, 2002, 11:11 AM
I made this code but it doesn't work in the best way...
here it is:
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.