Im making a sidescroller. When the character drops into a bottomless pit, I want to display a gameover screen, but instead the game crashes.
Im using MappyAL and Allegro 4.2 to make this game. Here is the key algorithm:
//Keep the character from crashing the game if he goes out of screen 750*20
if(player->x < 0) player->x = 0;
if(player->y < 0) player->y = 0;
if((player->x + player->width) > (mapwidth * mapblockwidth))
player->x = (mapwidth * mapblockwidth) - player->width;
if((player->y + player->height) > (mapheight * mapblockheight))
{
player->y = (mapheight * mapblockheight) - player->height;
blit(gameover, buffer, 0, 0, 0, 0, WIDTH, HEIGHT);
}
The 750 * 20 basically means how many blocks there are horizontally and vertically respectively. Each block is 32 * 32 pixels. So mapheight(20) * mapblockheight(32) gives me my vertical level dimensions. If the player crosses this limit, than blit the gameover screen. But that doesn't happen. Can someone point me in the right direction?