PDA

Click to See Complete Forum and Search --> : Slope


Allanon
Nov 1st, 2000, 06:59 PM
All right heres the problem, I have tried numerous times and each time it doesn't work right. My goal is to have your guy on a map move to where you click the mouse in a straight line. When I do it I can get the guy to move in a basic line, but he jumps to where the mouse is. So my question is how can I move my guy in a straight line, while on each step he takes place a new animation for the guy, without him jumping or skipping around.

THANKS

kedaman
Nov 2nd, 2000, 07:17 AM
How does your movement algoritm look like? how fast does it update? Is there a graphical problem or a problem with arranging the coordinates for the guy? What are you using to specify the coordinates for him?

Allanon
Nov 2nd, 2000, 03:56 PM
Private Sub Map_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
rx = x
ry = y
DeltaX = Xpos - rx
DeltaY = Ypos - ry
holdx = WalkIcon.Left
holdy = WalkIcon.Top
If rx >= Xpos Then
NegX = 1
Else
NegX = -1
End If
If ry >= Ypos Then
NegY = 1
Else
NegY = -1
End If
If DeltaX > DeltaY Then ' run greater than rise
XSlope = 1 * NegX
If DeltaX <> 0 Then
YSlope = DeltaY / DeltaX * NegX
Else
XSlope = 0
End If
ElseIf DeltaX < DeltaY Then
YSlope = 1 * NegY
If DeltaY <> 0 Then
XSlope = DeltaX / DeltaY * NegY
Else
YSlope = 0
End If
Else
XSlope = 1 * NegX
YSlope = 1 * NegY
End If
Do Until holdx = rx Or holdy = ry
DoEvents
holdx = holdx + XSlope
holdy = holdy + YSlope
' draw in the animations and others ect..
walkicon.left = holdx
walkicon.top = holdy
WalkIcon.Picture = LoadPicture(App.Path & "\Graphics\Animation\KnightR1.gif") ' this part has more code to determine which frame it is on, but too lengthy too place

' below this no problems here
loop

Okay heres what I have looking at I know I could probaly make it more efficient but the problem is when I click the mouse down and hold it, the guy(walkicon) is suppose to move to that location, but when he is moving towards the destination he sometimes just jumps right there without moving in the inbetween parts. I think the problem has something to do with processor speed running the loop, I added a gettickcount to combat this, but sometimes the guy moves fast and other times slower. It has something to do with the slope code and how it evaluates where he is on each loop. Maybe someone could come up with better code that moves the guy on a straight line and has the guy move smoothly and with the same speed to each destination.

Thanks for your Time

kedaman
Nov 4th, 2000, 06:58 AM
I think you need to make some real changes to your game, for instance having vectors instead of lot of x and y variables, btw what are all those variables? also you could post that again indented inside code tags, you post code inside code tags by doing:

your code goes here

then maybe we could understand it better :)