First i would like to ask how can i put the monsters moving randomly through the screen (There are no borders, example, if one monster hits the top it appears on the bot going top).
Last i would like to know what's the way to detect the collision between the ship and the monster and

if the ship hits the monster back, destroys them

if not it destroys the ship (in my game loses 1 up)

Thanks

Last edited by Norm; 12-22-2011 at 06:52 PM.
Reason: Moved out of Applets

Re: 2 polygons colliding

... Riiiight. Well it seems to be that you'll need to be comparing co-ordinates. If you thread this, and have one thread analysing the co-ordinates of the different objects, or for every movement, you can have each object announce it's co-ordinates and if there are any similarities then a collision is detected. If you want to know which side, then you'll have to split the object up into different sections that are governed differently. you could say, if the ship is hit by a monster then boolean shipHit = true, and if at one point, their co-ordinates are different, then at another point, within a time frame, the co-ordinates are the same or similar, then shipHitBack = true. Then at the end of all of it, a little if statement calling the "destroy()" method. Hope this helps.

Re: 2 ploygons colliding

what's the way to detect the collision between the ship and the monster

Perhaps one of the contains() methods could help. More reliable would be to create Area instances from them. Area has intersect() and isEmpty() methods.

Or, (and this could be faster) Line2D has a intersectsLine() method which tests for line segment intersection. Two triangles intersect iff no pair of sides intersect and no vertex of one is within the other. (I think)

how can i put the monsters moving randomly through the screen

Paint them onto the screen with the appropriate Graphics2D method.

Define "randomly". Most likely you want their movement to be continuous, so they should have a velocity which lets you determine their position from one instant to the next. There is rather more freedom with respect to how their velocity changes. Keep it simple to start with, you can always tweak it afterwards if it doesn't look realistic. As regards the "no borders" business (it sounds impressive to describe it as a "toroidal topology": in effect the world is shaped like a torus), the % operator is your friend.

Re: 2 ploygons colliding

Doing efficient collision detection also depends on the number of objects. If you only ever have 20 - 50 or so objects on the screen which you are checking, then a simple brute force might work just fine. However, if you intend to vomit particles all over the place like some of the old school shoot 'em ups, you'll need something better than a bunch of nested for-loops. Quad trees are often used for this, but this is a more advanced topic. I advise you keep your particle count low while you're learning this.