Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
August 29th, 2006, 05:13 PM
 william_nagels
Contributing User

Join Date: Aug 2006
Location: belgium
Posts: 116
Time spent in forums: 1 Day 7 h 2 m 45 sec
Reputation Power: 8
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
August 30th, 2006, 03:26 AM
 Hugh of Borg
Contributing User

Join Date: Jun 2004
Location: Switzerland
Posts: 1,152
Time spent in forums: 2 Weeks 1 Day 19 h 1 m 52 sec
Reputation Power: 1901
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!

#3
August 30th, 2006, 02:33 PM
 william_nagels
Contributing User

Join Date: Aug 2006
Location: belgium
Posts: 116
Time spent in forums: 1 Day 7 h 2 m 45 sec
Reputation Power: 8
and how would i do that :s

Quote:
 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)

#4
August 31st, 2006, 02:35 AM
 Hugh of Borg
Contributing User

Join Date: Jun 2004
Location: Switzerland
Posts: 1,152
Time spent in forums: 2 Weeks 1 Day 19 h 1 m 52 sec
Reputation Power: 1901
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.

william_nagels agrees: it helped me so much
Viper_SB agrees: informative

#5
August 31st, 2006, 11:19 AM
 william_nagels
Contributing User

Join Date: Aug 2006
Location: belgium
Posts: 116
Time spent in forums: 1 Day 7 h 2 m 45 sec
Reputation Power: 8
Ow man thanks for the help I get it now.

 Viewing: Dev Shed Forums > Programming Languages > Game Development > Java applets games