robobunny has asked for the wisdom of the Perl Monks concerning the following question:
Each object has a callback routine that determines how it behaves, that is called each time through the loop. Among other things, the callback determines how the object moves. My first attempt to add collision detection was something like this:add_objects(); while(!$done) { run_callback_routines(); update_display(); }
The callback routines would have access to a list of all the objects they collided with. The problem with this is that the display is updated immediately after everything is moved, so collisions get drawn on the screen that have not been dealt with. With fast moving objects, it wouldn't be an issue, but when stuff is moving slower it is obvious something is screwy. So my next thought was something like:while(!$done) { check_for_collisions(); run_callback_routines(); update_display(); }
The difference here being that instead of handling collisions in the regular callback, there would be an additional callback routine that is called only for objects that have collided with something. But then, what do you do when the action taken by one of these causes an additional collision that you haven't detected?while(!$done) { run_callback_routines(); check_for_collisions(); update_display(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Collision detection quandry
by Abigail-II (Bishop) on Feb 06, 2004 at 00:58 UTC | |
|
Re: Collision detection quandry
by shotgunefx (Parson) on Feb 06, 2004 at 12:14 UTC | |
by robobunny (Friar) on Feb 06, 2004 at 19:30 UTC | |
by shotgunefx (Parson) on Feb 06, 2004 at 21:21 UTC | |
by robobunny (Friar) on Feb 06, 2004 at 22:04 UTC |