Results 1 to 8 of 8

Thread: GAME Problem!!!!

  1. #1

    Thread Starter
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409

    Lightbulb

    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!
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  2. #2
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    use the intersectrect API function. no time to describe in detail, try msdn or api forums
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  3. #3
    Addicted Member
    Join Date
    Aug 2000
    Location
    Columbus Ohio
    Posts
    217

    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
    Chris

    [email protected]
    Windows XP RC2 B2526
    Visual Studio.Net Beta 2
    C++, VB, VB.Net, ASP, PHP

  4. #4
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    nahh, intersectrect is better. faster, cleaner, never lies, easy to understand.
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  5. #5
    Addicted Member
    Join Date
    Aug 2000
    Location
    Columbus Ohio
    Posts
    217

    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.
    Chris

    [email protected]
    Windows XP RC2 B2526
    Visual Studio.Net Beta 2
    C++, VB, VB.Net, ASP, PHP

  6. #6
    Addicted Member
    Join Date
    Aug 2000
    Location
    Columbus Ohio
    Posts
    217

    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
    Chris

    [email protected]
    Windows XP RC2 B2526
    Visual Studio.Net Beta 2
    C++, VB, VB.Net, ASP, PHP

  7. #7
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Code:
        If Abs(PicLaser.Left - picEnemy.Left) < PicLaser.Width And Abs(PicLaser.Top - picEnemy.Top) < PicLaser.Height Then 'collided

  8. #8

    Thread Starter
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    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.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width