#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    belgium
    Posts
    116
    Rep Power
    9

    Java applets games


    can someone tell me how to register 2 objects who hit each other?
    I mean when they hit each other.

    what i'm meaning is that.
    you got a rectangele
    g.drawRect(...,...,...,...);
    and an oval
    g.drawOval(...,...,...,...,);

    the oval moves up.
    and hit's the rectangel on any spot
    then it goes back.
    if the oval misses the rectangle
    it passes the border of the applet and is gone

    sry for my bad English but I'm a foreigner
  2. #2
  3. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2004
    Location
    Switzerland
    Posts
    1,152
    Rep Power
    1902
    You're looking for collision detection algorithms.

    An easy way would be to think of the oval as a rectangle too and if one of the 2 object's corners are inside the other object you have a collision.
    - Hugh of Borg

    The first thing young borg are taught: Keep away from Microsoft software!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    belgium
    Posts
    116
    Rep Power
    9

    and how would i do that :s


    Originally Posted by Hugh of Borg
    An easy way would be to think of the oval as a rectangle too and if one of the 2 object's corners are inside the other object you have a collision.
    tnx for reply but how can i do that?

    ypos_rect - ypos_circ && xpos_rect-xpos_circ ?!

    or

    if (ypos_rect<ypos_circ && xpos_rect < xpos_cir)
  6. #4
  7. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2004
    Location
    Switzerland
    Posts
    1,152
    Rep Power
    1902
    I put some more time into it. The easiest way (from the code perspective) would be to create an Area object for both objects then use the "void intersect(Area)" method and test the object with "boolean isEmpty()" to see if they did collide. This might not be the most efficient way but it should work.

    for more information i recommend this link.

    Comments on this post

    • william_nagels agrees : it helped me so much
    • Viper_SB agrees : informative
    - Hugh of Borg

    The first thing young borg are taught: Keep away from Microsoft software!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    belgium
    Posts
    116
    Rep Power
    9
    Ow man thanks for the help I get it now.

IMN logo majestic logo threadwatch logo seochat tools logo