A Quick and Dirty VCL Sprite Engine - Part VI

By: John Ray Thomas

Abstract: Provide clipping against the playing area and other sprites.

Provide clipping against the playing area and other sprites.

For this example the only thing we need to clip against is the background borders. This is a seperate function from clipping against other sprites and boils down to ensuring your rectangle does not pass the Top, Left, Width or Height of the playing area.
bool TankSprite::ClipPlayingArea(TRect rect)
{
    if (clipRect.Top < rect.Top || clipRect.Bottom > rect.Bottom ||
               clipRect.Left < rect.Left || clipRect.Right > rect.Right)
            return true;
    return false;
}
In this example if the sprite clips against the playing area it gets set to it's last position. This gives the impression that the sprite cannot move past that area.

Server Response from: ETNASC03