|
-
Jan 5th, 2002, 09:54 PM
#1
Thread Starter
Hyperactive Member
Get distance between two points for tile based game
Some people that are making tile based games might be interested in the distance formula. The formula returns how many tiles it takes to get from one point to another on a grid. Most of you probably know this already, but here it is anyway..
VB Code:
Private Function Distance(X1 As Long, Y1 As Long, X2 As Long, Y2 As Long) As Long
Distance = (X2 - X1) + (Y2 - Y1)
End Function
For instance, if you wanted to determine the distance between tiles (2,8) and (9,14), you would use the formula like this..
That would then return 13 which is how many tiles it takes to get from point (2, 8) to point (9, 14). So for those who care, there it is.
[vbcode]
' comment
Rem remark
[/vbcode]
-
Jan 6th, 2002, 09:56 AM
#2
PowerPoster
Uhm.. that's wrong isn't it?
VB Code:
Private Function Distance(X1 As Long, Y1 As Long, X2 As Long, Y2 As Long) As Long
Distance = Sqr( (X2 - X1)^2 + (Y2 - Y1)^2 )
End Function
Well this formula is the distance if you move straight on to point #2..
-
Jan 6th, 2002, 10:04 AM
#3
Good Ol' Platypus
That wouldn't matter if he's doing a typical grid-confinement RPG. I say good work on the function! If you are using a free-roaming (you can be on more than one tile at a time) then you should use Fox's.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Jan 6th, 2002, 12:52 PM
#4
Thread Starter
Hyperactive Member
Yeah, mine didn't incorporate diagonal movement.
[vbcode]
' comment
Rem remark
[/vbcode]
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
|