|
-
Sep 29th, 2000, 10:49 AM
#1
Thread Starter
Frenzied Member
I am making a game in which a ship shoots with lasers on other objects.The laser and the target are both picture boxes.I want to know how can i know when one picture "touches" another i.e. when the target is hit.
Thanks!
-
Sep 29th, 2000, 11:04 AM
#2
Frenzied Member
use the intersectrect API function. no time to describe in detail, try msdn or api forums
-
Sep 29th, 2000, 11:05 AM
#3
Addicted Member
I'm not going to actually code it but:
Heres basicly what your need to do:
using the bottom, right, top and left properties of the pictureboxes, you can tell if an object is within the box.
To get the boxes right value use
Code:
picbox.left+picbox.left
to get the bottom value use
Code:
picbox.top + picbox.height
Then check to see if the 'laser' is within the actual picbox's values. Also I would recommend you use a image control instead of a picturebox. They take MUCH less memory and contain all the properties you'll need. Also define the values BEFORE you check if a hit so that your code executes faster. Hope this helps
-
Sep 29th, 2000, 11:11 AM
#4
Frenzied Member
nahh, intersectrect is better. faster, cleaner, never lies, easy to understand.
-
Sep 29th, 2000, 12:49 PM
#5
Addicted Member
BUT...
Yes intersect is mostly better(btw I typed mine at te same time as you so I didnt see yours), BUT he(she?) seemed to be a beginning programmer so learning how to do things like that is crucial.
-
Sep 29th, 2000, 12:53 PM
#6
Addicted Member
Also
Also, if he is newer, it would have probably helped to have given him the API declare, I have included both IntersectRect and IntersectClipRect for your convience
Code:
Declare Function IntersectClipRect Lib "gdi32" Alias "IntersectClipRect" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Declare Function IntersectRect Lib "user32" Alias "IntersectRect" (lpDestRect As RECT, lpSrc1Rect As RECT, lpSrc2Rect As RECT) As Long
-
Sep 29th, 2000, 03:00 PM
#7
Frenzied Member
Code:
If Abs(PicLaser.Left - picEnemy.Left) < PicLaser.Width And Abs(PicLaser.Top - picEnemy.Top) < PicLaser.Height Then 'collided
-
Sep 29th, 2000, 03:06 PM
#8
Thread Starter
Frenzied Member
Thanks for the code-I used the IntersectRect API function and it worked just fine.
P.S.
I am not a begginer just a bit rusty because of learning other languages at this time so some things get messed up for me.
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
|