|
-
Oct 5th, 2000, 02:17 PM
#1
Thread Starter
Frenzied Member
hello all, I'm making this game where food is flying a person, and I want to make it so that when the food touches the person, the food desappears, and a point is added to the score this is the code that I have so far:
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyLeft: Shape1.Left = Shape1.Left - 100
Case vbKeyRight: Shape1.Left = Shape1.Left + 100
End Select
End Sub
Private Sub Form_Load()
Timer1.Interval = 1
End Sub
Private Sub Timer1_Timer()
Shape2.Top = Shape2.Top + 10
End Sub
for now I'm just testing everything with shapes, then I'm gonna replace the shapes with images
NXSupport - Your one-stop source for computer help
-
Oct 5th, 2000, 02:32 PM
#2
How about the IntersectRect API?
Code:
Public Declare Function IntersectRect Lib "user32" Alias "IntersectRect" (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
Code:
Private Sub Timer1_Timer()
Dim rctShape As RECT
Dim rctPerson As RECT
Dim rctResult As RECT
Shape2.Top = Shape2.Top + 10
With rctShape
.Left = Shape2.Left
.Top = Shape2.Top
.Right = Shape2.Left + Shape2.Width
.Bottom = Shape2.Top + Shape2.Height
End With
'The same way fill the RECT of the person (rctPerson).
If (IntersectRect(rctShape, rctPerson, rctResult) <> 0) Then
'They intersect.
End If
End Sub
Let me know.
-
Oct 5th, 2000, 02:35 PM
#3
Fanatic Member
You can also use this code:
Code:
if shape2.top + shape2.height=> shape1.top then
if (shape2.left<(shape1.left+shape1.width)) _
and shape2.left>(shape1.left) then debug.print "Hit."
end if
-
Oct 5th, 2000, 02:36 PM
#4
Thread Starter
Frenzied Member
NXSupport - Your one-stop source for computer help
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
|