# Thread: A HARD GAME MATH PROBLEM - PLEASE ONLY EXPIRIENCED PROGRAMMERS

1. ## ok , i have a trail on the background map
and i want a ball to follow it
if its a straight line u can find the angle of the line
tan a = X
and find a and do x=x+r*cos a , y=y+r*sin a
but if its not a straight line
a trail
a wierd path
how can i make the ball follow it ?  Reply With Quote

2. I might be clutching at straws here, but since you've had no reply yet, I thought I might have ago.

Instead of trying to do this using maths, why not use the object.Point or GetPixel API to return the color of the pixel and follow the trail.

eg.

At point X, check the surrounding pixels and move to the appropriate one.

This is assuming that the trail is a completely different colour for the background image.

Just another angle to try

Regards
Terry  Reply With Quote

3. ## i think this will do what you want it to..

here is what this dos
a ball follows your mouse when a menu item is hovered over
you can put the code on formmove and it will move when the mouse is anywhere on the form.. and i think you knwo the possibilities from there

Code:
```Option Explicit

Dim Xp1, Xp2, Yp1, Yp2, destXPoint, destYpoint As Integer
Dim XPoint As Integer
Dim YPoint As Integer
Dim Slope As Double
Dim YIntercept As Double
Dim UpDown As Boolean

Private Sub CoordinateCalc()
UpDown = (Xp1 = Xp2)
If Not UpDown Then
Slope = (Yp1 - Yp2) / (Xp1 - Xp2)
YIntercept = Slope * Xp1 - Yp1
End If
End Sub

Private Sub MoveBall(x1 As Integer, x2 As Integer, y1 As Integer, y2 As Integer, dest As Integer)
If (x1 = x2) And (y1 = y2) Then Exit Sub
Xp1 = x1
Xp2 = x2
Yp1 = y1
Yp2 = y2
destXPoint = dest
destYpoint = Yp2
Call CoordinateCalc
imgBall.Visible = True
TmrDrop.Enabled = True
End Sub

Private Sub Form_Initialize()
XPoint = 3
YPoint = 3
End Sub

Call OpenDB
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
imgBall.Visible = False
End Sub

frmMaitenance.Show
End Sub

Private Sub imgAdministrator_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call MoveBall(XPoint, 2970, YPoint, 5505, 2970)
End Sub

Private Sub imgScrap_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call MoveBall(XPoint, 7375, YPoint, 6000, 7375)
End Sub

Private Sub TmrDrop_Timer()
imgBall.Left = imgBall.Left + 50 * Sgn(Xp2 - Xp1) ' -50 or +0 or +50 depending on situation
If UpDown Then
imgBall.Top = imgBall.Top + 50 * Sgn(Yp2 - Yp1)
Else
imgBall.Top = imgBall.Left * Slope - YIntercept
End If

If Not UpDown Then
Select Case Sgn(Xp2 - Xp1)
Case -1 ' Moves backwards
If imgBall.Left <= Xp2 Then
imgBall.Left = Xp2
imgBall.Top = Yp2
TmrDrop.Enabled = False
End If
Case 1 ' Moves forwards
If imgBall.Left >= Xp2 Then
imgBall.Left = Xp2
imgBall.Top = Yp2
TmrDrop.Enabled = False
End If
End Select
Else ' UpDown
Select Case Sgn(Yp2 - Yp1)
Case -1 ' Moves up
If imgBall.Top <= Yp2 Then
imgBall.Left = Xp2
imgBall.Top = Yp2
TmrDrop.Enabled = False
End If
Case 1 ' Moves down
If imgBall.Top >= Yp2 Then
imgBall.Left = Xp2
imgBall.Top = Yp2
TmrDrop.Enabled = False
End If
End Select
End If
End Sub

Private Sub tmrPosition_Timer()
XPoint = imgBall.Left
YPoint = imgBall.Top
End Sub```
//this was possible with help of Yonatan  Reply With Quote

4. First Of All , Thank you for the replies

now ... for the color trick
it work coz the path is thick and changes and alot of colors are being used in the background

but maybe an array of positions can be recored
and then the ball can be directed to ...
ofcourse its ANTS WORK

with the other tehnicque , i must be honset , i didnt understand it , sorry  Reply With Quote

#### Posting Permissions

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