Ideas regarding flow control and loops

Bruce Adams tortoise_74 at yeah.who.co.uk
Sun Nov 4 01:20:23 PST 2007


Marco Aurélio Wrote:

> Daniel Keep Wrote:
> > else would also be nice.
> 
> This would be specially usefull for implementing collisions on 2D games with bitmap-based coldefs, something along the lines of:
> 
> while(object.isCollidingWithGround())
> {
>      object.moveUp();
> } finally {
>      object.stop();
> } else {
>      object.applyGravity();
> }
> 
> While the object is colliding with the ground, move it up... Then >stop it.. and if he wasn't colliding with the ground in the first place, >apply gravity.

What's wrong with:

if  (!object.isCollidingWithGround())
      object.applyGravity();
else do
{
     object.moveUp();
} while (object.isCollidingWithGround());
object.stop();

You've got one extra condition to write but its not really a big deal.



More information about the Digitalmars-d mailing list