|
-
Sep 12th, 2000, 02:55 PM
#1
Thread Starter
Frenzied Member
Looks like moving my ball requires some cool math
moving to different points at a certain degree
moving from point 100,100 to 500,700 requires a slope of 53.13 Degree
i want to move a object from 100,100 to 500, 700
using the slope
and showing this object moving along this direction in a timer
anyone can help greatly appreciated
-
Sep 12th, 2000, 03:08 PM
#2
Guru
The equation of the line that goes through (100, 100) and (500, 700) is:
Code:
700 - 100
y - 100 = --------- (x - 100)
500 - 100
y - 100 = 600/400 * (x - 100)
y - 100 = 3/2 * x - 150
y = 3/2 * x - 50
So whenever we add one to x, we have to calculate y with 3/2 * x - 50.
Timer code:
Code:
picBall.Left = picBall.Left + 1
picBall.Top = picBall.Left * 3 / 2 - 50
If picBall.Left = 700 Then tmrBall.Enabled = False
Worth a shot!
-
Sep 13th, 2000, 10:01 AM
#3
Thread Starter
Frenzied Member
pulling all my hair
still with that damn moving problem crap..
some how this doesnt want to move the img back to the original point it started moving from
here is the code if any one can see something i am not seeing please let me know, i changed orders of them like a million times, changed different subs..
still doesnt want to move backwards
grr
Code:
Option Explicit
Dim Slope As Double
Dim EndPoint As Integer
Dim x1, x2, y1, y2 As Integer
Private Sub imgOverDueMeters_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call UpCordinates(3960, 2, 750, 2, 2)
End Sub
Private Sub imgPresentDueMeters_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call DropCordinates(2, 3960, 2, 750, 3960)
End Sub
Private Sub tmrBack_Timer()
imgBall.Left = imgBall.Left - 50
imgBall.Top = (imgBall.Left * (y1 - y2) / (x1 - x2) + ((((y1 - y2) / (x1 - x2)) * (x1)) - y1))
If imgBall.Left <= EndPoint Then tmrBack.Enabled = False
End Sub
Private Sub TmrDrop_Timer()
imgBall.Left = imgBall.Left + 50
imgBall.Top = (imgBall.Left * (y2 - y1) / (x2 - x1) - ((((y2 - y1) / (x2 - x1)) * (x1)) - y1))
If imgBall.Left >= EndPoint Then TmrDrop.Enabled = False
End Sub
Private Sub SetCordinates(Xp1 As Integer, Xp2 As Integer, Yp1 As Integer, Yp2 As Integer, endP As Integer)
x1 = Xp1
x2 = Xp2
y1 = Yp1
y2 = Yp2
EndPoint = endP
End Sub
Private Sub DropCordinates(x1 As Integer, x2 As Integer, y1 As Integer, y2 As Integer, endP As Integer)
If imgBall.Left >= endP Then
Exit Sub
Else
Call SetCordinates(x1, x2, y1, y2, x2)
TmrDrop.Enabled = True
End If
End Sub
Private Sub UpCordinates(x1 As Integer, x2 As Integer, y1 As Integer, y2 As Integer, endP As Integer)
If imgBall.Left <= endP Then
Exit Sub
Else
Call SetCordinates(x2, x1, y2, y1, x1)
TmrDrop.Enabled = True
End If
End Sub
-
Sep 13th, 2000, 10:31 AM
#4
Guru
Um, I'm not sure, but I think it has to do with the fact that you never enabled the tmrBack timer.
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
|