Rebounding objects off moving objects.
Dont worry guys, its resolved :)
[32 byte] By [
Mackiv] at [2007-11-20 8:07:40]

# 1 Re: Rebounding objects off moving objects.
First thing you need is a way to determine if any of the crowd objects collides with the user controlled object. Dont know if you have that code somewhere else, but not in what you listed.
Dunno if there are better ways to achieving this, but I would use a synchronized central managing class, that knows the position of each object at any time. Then it runs a comparison x times a second, seeing if any objects collide with each other, figures out the next point in space the object(s) will have, and tells the object to update itself. For this the Objects need to know where they were (preferrably like last two points) and their direction of movement (preferrably in radians).
As to the colliding, usually in games like Breakout or Arkanoid, or Pong, it is handled only in 45 degree angles. Makes maths way simpler. So knowing where the object was before, knowing at what point in space the collision takes place, you can calculate the angle object is to take after collision and thus deduct the next point where the object is to move.
Codevise... I would make an abtract class, GameObject, that the user controlled thingie and the other thingies would extend. That way you have far less pains in building managing class and the overall structure becomes easier to control and maintain. If you want some object to not respond to collision, or respond differently than others, make an interface Collissable (or something), that the things that do respond to collision implement. Some could explode to a horde of smaller items, while others could digest the colliding object and grow bigger... or what ever.
So instead of building a legion of classes that have nothing in common. Always is better to try to nest them in an object hierarchy, where new ones are extensions of the older (more generic) ones. This way your code grows in a controlled way, and objects tend to have a sensible shared context, with which you can address them in, say collections. If all this is new, google "Java inheritance" and "Java interface".
# 2 Re: Rebounding objects off moving objects.
Dont worry guys, its resolved :)OK, but it's better not to delete the original question, because others may find it and the later posts useful themselves. We now have a thread that has an answer, but no question visible...
Programs must be written for people to read, and only incidentally for machines to execute...
H. Abelson and G. Sussman
dlorde at 2007-11-10 2:16:35 >
