fix segfaults in pause

This commit is contained in:
Sebastian Krzyszkowiak 2012-03-04 16:52:05 +01:00
parent 87dbd1f04b
commit cb33ac763d
4 changed files with 15 additions and 15 deletions

View file

@ -111,7 +111,7 @@ void Level_Unload(struct Game *game) {
ALLEGRO_EVENT ev; ALLEGRO_EVENT ev;
game->level.fade_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display)); game->level.fade_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display));
al_set_target_bitmap(game->level.fade_bitmap); al_set_target_bitmap(game->level.fade_bitmap);
al_draw_scaled_bitmap(game->level.image,0,0,al_get_bitmap_width(game->level.image),al_get_bitmap_height(game->level.image),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0); al_draw_bitmap(game->level.image,0,0,0);
al_draw_bitmap(game->level.derpy, game->level.derpy_pos*al_get_display_width(game->display), al_get_display_height(game->display)-al_get_bitmap_height(game->level.derpy), ALLEGRO_FLIP_HORIZONTAL); al_draw_bitmap(game->level.derpy, game->level.derpy_pos*al_get_display_width(game->display), al_get_display_height(game->display)-al_get_bitmap_height(game->level.derpy), ALLEGRO_FLIP_HORIZONTAL);
al_draw_textf(game->font, al_map_rgb(255,255,255), al_get_display_width(game->display)/2, al_get_display_height(game->display)/2.2, ALLEGRO_ALIGN_CENTRE, "Level %d: Not implemented yet!", game->level.current_level); al_draw_textf(game->font, al_map_rgb(255,255,255), al_get_display_width(game->display)/2, al_get_display_height(game->display)/2.2, ALLEGRO_ALIGN_CENTRE, "Level %d: Not implemented yet!", game->level.current_level);
al_draw_text(game->font, al_map_rgb(255,255,255), al_get_display_width(game->display)/2, al_get_display_height(game->display)/1.8, ALLEGRO_ALIGN_CENTRE, "Have some moonwalk instead."); al_draw_text(game->font, al_map_rgb(255,255,255), al_get_display_width(game->display)/2, al_get_display_height(game->display)/1.8, ALLEGRO_ALIGN_CENTRE, "Have some moonwalk instead.");

View file

@ -104,12 +104,18 @@ void Map_Preload(struct Game *game) {
PrintConsole(game, "Last level available: %d", game->map.selected); PrintConsole(game, "Last level available: %d", game->map.selected);
game->map.arrowpos = 0; game->map.arrowpos = 0;
PrintConsole(game, "Loading background...");
game->map.map_bg = LoadScaledBitmap("map/background.png", al_get_display_width(game->display), al_get_display_height(game->display)); game->map.map_bg = LoadScaledBitmap("map/background.png", al_get_display_width(game->display), al_get_display_height(game->display));
PrintConsole(game, "Setting up highlight...");
char filename[30] = { }; char filename[30] = { };
sprintf(filename, "map/highlight%d.png", game->map.available); sprintf(filename, "map/highlight%d.png", game->map.available);
PrintConsole(game, "Loading highlight...");
game->map.highlight = LoadScaledBitmap(filename, al_get_display_width(game->display), al_get_display_height(game->display)); game->map.highlight = LoadScaledBitmap(filename, al_get_display_width(game->display), al_get_display_height(game->display));
PrintConsole(game, "Loading arrow...");
game->map.arrow = al_load_bitmap( "data/arrow.png" ); game->map.arrow = al_load_bitmap( "data/arrow.png" );
PrintConsole(game, "Loading samples...");
game->map.click_sample = al_load_sample( "data/click.flac" ); game->map.click_sample = al_load_sample( "data/click.flac" );
game->map.sample = al_load_sample( "data/map.flac" ); game->map.sample = al_load_sample( "data/map.flac" );
@ -122,7 +128,9 @@ void Map_Preload(struct Game *game) {
exit(-1); exit(-1);
} }
PrintConsole(game, "Loading table...");
game->map.map = LoadScaledBitmap("table.png", al_get_display_width(game->display), al_get_display_height(game->display)); game->map.map = LoadScaledBitmap("table.png", al_get_display_width(game->display), al_get_display_height(game->display));
PrintConsole(game, "Drawing...");
al_set_target_bitmap(game->map.map); al_set_target_bitmap(game->map.map);
al_draw_bitmap(game->map.map_bg, 0, 0 ,0); al_draw_bitmap(game->map.map_bg, 0, 0 ,0);
al_draw_bitmap(game->map.highlight, 0, 0 ,0); al_draw_bitmap(game->map.highlight, 0, 0 ,0);

View file

@ -83,7 +83,6 @@ void Menu_Draw(struct Game *game) {
} }
void Menu_Preload(struct Game *game) { void Menu_Preload(struct Game *game) {
PrintConsole(game, "menu preload");
game->menu.loaded = true; game->menu.loaded = true;
game->menu.image = LoadScaledBitmap( "menu.png", al_get_display_width(game->display), al_get_display_height(game->display)*0.45); game->menu.image = LoadScaledBitmap( "menu.png", al_get_display_width(game->display), al_get_display_height(game->display)*0.45);
game->menu.mountain = LoadScaledBitmap( "mountain.png", al_get_display_width(game->display)*0.055, al_get_display_height(game->display)/9 ); game->menu.mountain = LoadScaledBitmap( "mountain.png", al_get_display_width(game->display)*0.055, al_get_display_height(game->display)/9 );

View file

@ -25,10 +25,13 @@
int Pause_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { int Pause_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
if ((ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE) || ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->pause.options==0) && (game->pause.selected==0))) { if ((ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE) || ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->pause.options==0) && (game->pause.selected==0))) {
Pause_Unload_Real(game); PrintConsole(game,"Game resumed.");
al_destroy_bitmap(game->pause.bitmap);
game->pause.bitmap = NULL;
game->gamestate = game->loadstate; game->gamestate = game->loadstate;
} }
else if ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->pause.options==0) && (game->pause.selected==1)) { else if ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->pause.options==0) && (game->pause.selected==1)) {
game->gamestate=game->loadstate;
UnloadGameState(game); UnloadGameState(game);
game->gamestate = GAMESTATE_LOADING; game->gamestate = GAMESTATE_LOADING;
game->loadstate = GAMESTATE_MAP; game->loadstate = GAMESTATE_MAP;
@ -63,21 +66,10 @@ int Pause_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
void Pause_Preload(struct Game* game) { void Pause_Preload(struct Game* game) {
game->pause.bitmap = NULL; game->pause.bitmap = NULL;
game->pause.derpy = LoadScaledBitmap("derpy_pause.png", al_get_display_width(game->display)*0.53, al_get_display_height(game->display)*0.604); game->pause.derpy = LoadScaledBitmap("derpy_pause.png", al_get_display_width(game->display)*0.53, al_get_display_height(game->display)*0.604);
/*(game->pause.derpy = al_create_bitmap(al_get_display_width(game->display)*0.53, al_get_display_height(game->display)*0.604); PrintConsole(game,"Pause preloaded.");
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
ALLEGRO_BITMAP *derpy = al_load_bitmap( "data/derpy_pause.png" );
al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_MIN_LINEAR);
al_set_target_bitmap(game->pause.derpy);
ScaleBitmap(derpy, al_get_display_width(game->display)*0.53, al_get_display_height(game->display)*0.604);
al_set_target_bitmap(al_get_backbuffer(game->display));
al_destroy_bitmap(derpy);*/
} }
void Pause_Load(struct Game* game) { void Pause_Load(struct Game* game) {
PrintConsole(game,"Pause loaded.");
game->gamestate=game->loadstate; game->gamestate=game->loadstate;
game->loadstate=GAMESTATE_PAUSE; game->loadstate=GAMESTATE_PAUSE;
DrawGameState(game); DrawGameState(game);
@ -97,6 +89,7 @@ void Pause_Load(struct Game* game) {
al_destroy_bitmap(fade); al_destroy_bitmap(fade);
game->pause.selected=0; game->pause.selected=0;
game->pause.options=0; game->pause.options=0;
PrintConsole(game,"Game paused.");
} }
void Pause_Draw(struct Game* game) { void Pause_Draw(struct Game* game) {