|
-
Oct 11th, 2000, 05:09 AM
#1
Thread Starter
Lively Member
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 ?
-
Oct 11th, 2000, 07:18 AM
#2
New Member
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
-
Oct 11th, 2000, 07:44 AM
#3
Frenzied Member
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
Private Sub Form_Load()
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
Private Sub imgAdministrator_Click()
Unload Me
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
-
Oct 11th, 2000, 02:50 PM
#4
Thread Starter
Lively Member
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
but can be made
with the other tehnicque , i must be honset , i didnt understand it , sorry
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
|