• Create Account

# Game crashes when character goes out of screen

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

### #1ISDCaptain01  Members   -  Reputation: 903

Like
0Likes
Like

Posted 06 October 2013 - 10:03 PM

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?

### #2Shane C  Members   -  Reputation: 727

Like
0Likes
Like

Posted 07 October 2013 - 12:07 AM

Do you need to turn gravity off?

### #3GDMega6  Members   -  Reputation: 128

Like
0Likes
Like

Posted 07 October 2013 - 12:33 AM

Does it crash when the player falls off screen or when Allegro attempts to draw gameover to buffer?

### #4ankhd  Members   -  Reputation: 672

Like
0Likes
Like

Posted 07 October 2013 - 05:24 AM

Hi there.

Does it have a grid of cells may be it does a memory look up with the X, Y and when there out of range so is the lookup address.

### #5farmdve  Members   -  Reputation: 194

Like
0Likes
Like

Posted 07 October 2013 - 05:45 AM

Haha, I got absolutely the same problem. For me the case was that the calculation of the player's position led to an array of out bounds error that caused a crash for me as well. I sort of fixed it, but Super Mario Bros from 1985 did it much better than I did.

However I am also now getting some edge-case bugs that I am not sure how to resolve. So yeah, I would also love to see how to fix this better.

### #6ISDCaptain01  Members   -  Reputation: 903

Like
0Likes
Like

Posted 07 October 2013 - 01:06 PM

Does it crash when the player falls off screen or when Allegro attempts to draw gameover to buffer?

crash when the player falls off the screen

### #7Cosmic314  Members   -  Reputation: 921

Like
0Likes
Like

Posted 07 October 2013 - 01:52 PM

I assume your lowest point is y = 0 as you clamp to this value if the character's coordinates ever go less than 0.

mapheight * mapblockehight = 640.  Based on your y=0 position clamp, 640 represents a place "off" the screen.  Pixel 639 is 'on' the screen.  With just the '>' symbol you're skipping the very first line of pixels off the screen.  This means, possibly, that the very top of your character's pixel row will be rendered offscreen, depending on how you define player->y and player->height.  If player->y represents the first vertical pixel and player->height represents the number of pixels in height your player is, you'll have an "off by one" issue in the above checking code.

In your position update code, do you ever clamp the y value?

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS