Public Declare Function IntersectRect Lib "user32" (lpDestRect As RECT, lpSrc1Rect As RECT, lpSrc2Rect As RECT) As Long
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
' For forms using ScaleMode 1 - Twips
Public Function RectFromControlTwips(Ctl As Control) As RECT
Dim CtlRect As RECT
With CtlRect
.Left = Ctl.Left \ Screen.TwipsPerPixelX
.Top = Ctl.Top \ Screen.TwipsPerPixelY
.Right = (Ctl.Left + Ctl.Width) \ Screen.TwipsPerPixelX
.Bottom = (Ctl.Top + Ctl.Bottom) \ Screen.TwipsPerPixelY
End With
End Function
' For forms using ScaleMode 3 - Pixels
Public Function RectFromControl(Ctl As Control) As RECT
Dim CtlRect As RECT
With CtlRect
.Left = Ctl.Left
.Top = Ctl.Top
.Right = Ctl.Left + Ctl.Width
.Bottom = Ctl.Top + Ctl.Bottom
End With
End Function
I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
Posts
1,457
Hum I'd do it the old VB way
VB Code:
If Img1.Left + Img1.Width >= Img2.Left And _
Img1.Top + Img1.Height >= Img2.Top And _
Img1.Left <= Img2.Left + Img2.Width And _
Img1.Top <= Img2.Top + Img2.Height Then
'We've got a collision!
End If
You can do this:
1) Remember the position (Left/Top) of the image BEFORE you move it, using variables
2) Move the image
3) If it collides with a platform, move it back to the position you saved in the variables
Last edited by Jotaf98; Oct 7th, 2001 at 02:44 PM.
To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systemshere.
Jotaf's Theories!
"Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."
I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
Posts
1,457
Btw, you should have 1 variable (boolean) for each key; in the KeyDown event, you set it to True; in the KeyUp event, you set it to False. Then, in the Timer, for example, just check if the Left key is being pressed (the boolean variable is True) and move the image to the left
To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systemshere.
Jotaf's Theories!
"Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."