implement fullscreen setting from pause menu

This commit is contained in:
Sebastian Krzyszkowiak 2012-03-08 22:21:02 +01:00
parent 7f4c4f9fb5
commit 00f4c409e6
6 changed files with 89 additions and 38 deletions

View file

@ -81,20 +81,9 @@ int Level_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
return 0; return 0;
} }
void Level_Preload(struct Game *game) { void Level_PreloadBitmaps(struct Game *game) {
PrintConsole(game, "Initializing level %d...", game->level.current_level);
game->level.image =LoadScaledBitmap("table.png", al_get_display_width(game->display), al_get_display_height(game->display)); game->level.image =LoadScaledBitmap("table.png", al_get_display_width(game->display), al_get_display_height(game->display));
game->level.sample = al_load_sample( "data/moonwalk.flac" );
game->level.derpy_walkcycle = LoadScaledBitmap("derpcycle.png", al_get_display_width(game->display)*0.1953125*6, al_get_display_height(game->display)*0.25*4); game->level.derpy_walkcycle = LoadScaledBitmap("derpcycle.png", al_get_display_width(game->display)*0.1953125*6, al_get_display_height(game->display)*0.25*4);
if (!game->level.sample){
fprintf(stderr, "Audio clip sample not loaded!\n" );
exit(-1);
}
game->level.music = al_create_sample_instance(game->level.sample);
al_attach_sample_instance_to_mixer(game->level.music, game->audio.music);
al_set_sample_instance_playmode(game->level.music, ALLEGRO_PLAYMODE_LOOP);
game->level.derpy = al_create_bitmap(al_get_display_width(game->display)*0.1953125, al_get_display_height(game->display)*0.25); game->level.derpy = al_create_bitmap(al_get_display_width(game->display)*0.1953125, al_get_display_height(game->display)*0.25);
@ -104,9 +93,30 @@ void Level_Preload(struct Game *game) {
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.");
al_set_target_bitmap(al_get_backbuffer(game->display)); al_set_target_bitmap(al_get_backbuffer(game->display));
}
void Level_Preload(struct Game *game) {
PrintConsole(game, "Initializing level %d...", game->level.current_level);
game->level.sample = al_load_sample( "data/moonwalk.flac" );
game->level.music = al_create_sample_instance(game->level.sample);
al_attach_sample_instance_to_mixer(game->level.music, game->audio.music);
al_set_sample_instance_playmode(game->level.music, ALLEGRO_PLAYMODE_LOOP);
if (!game->level.sample){
fprintf(stderr, "Audio clip sample not loaded!\n" );
exit(-1);
}
Level_PreloadBitmaps(game);
Pause_Preload(game); Pause_Preload(game);
} }
void Level_UnloadBitmaps(struct Game *game) {
al_destroy_bitmap(game->level.image);
al_destroy_bitmap(game->level.derpy);
al_destroy_bitmap(game->level.derpy_walkcycle);
}
void Level_Unload(struct Game *game) { void Level_Unload(struct Game *game) {
Pause_Unload_Real(game); Pause_Unload_Real(game);
ALLEGRO_EVENT ev; ALLEGRO_EVENT ev;
@ -124,9 +134,7 @@ void Level_Unload(struct Game *game) {
DrawConsole(game); DrawConsole(game);
al_flip_display(); al_flip_display();
} }
al_destroy_bitmap(game->level.image); Level_UnloadBitmaps(game);
al_destroy_bitmap(game->level.derpy);
al_destroy_bitmap(game->level.derpy_walkcycle);
al_destroy_bitmap(game->level.fade_bitmap); al_destroy_bitmap(game->level.fade_bitmap);
al_destroy_sample_instance(game->level.music); al_destroy_sample_instance(game->level.music);
al_destroy_sample(game->level.sample); al_destroy_sample(game->level.sample);

View file

@ -25,3 +25,5 @@ void Level_Preload(struct Game *game);
void Level_Unload(struct Game *game); void Level_Unload(struct Game *game);
void Level_Load(struct Game *game); void Level_Load(struct Game *game);
int Level_Keydown(struct Game *game, ALLEGRO_EVENT *ev); int Level_Keydown(struct Game *game, ALLEGRO_EVENT *ev);
void Level_UnloadBitmaps(struct Game *game);
void Level_PreloadBitmaps(struct Game *game);

View file

@ -240,6 +240,30 @@ float tps(struct Game *game, float t) {
return t/game->fps; return t/game->fps;
} }
int Shared_Load(struct Game *game) {
game->font = al_load_ttf_font("data/ShadowsIntoLight.ttf",al_get_display_height(game->display)*0.09,0 );
if(!game->font) {
fprintf(stderr, "failed to load game font!\n");
return -1;
}
game->font_console = al_load_ttf_font("data/DejaVuSansMono.ttf",al_get_display_height(game->display)*0.018,0 );
if(!game->font_console) {
fprintf(stderr, "failed to load console font!\n");
return -1;
}
game->console = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display)*0.12);
al_set_target_bitmap(game->console);
al_clear_to_color(al_map_rgba(0,0,0,80));
al_set_target_bitmap(al_get_backbuffer(game->display));
return 0;
}
void Shared_Unload(struct Game *game) {
al_destroy_font(game->font);
al_destroy_font(game->font_console);
al_destroy_bitmap(game->console);
}
int main(int argc, char **argv){ int main(int argc, char **argv){
srand(time(NULL)); srand(time(NULL));
@ -321,17 +345,9 @@ int main(int argc, char **argv){
al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_MIN_LINEAR); al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_MIN_LINEAR);
//al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA); //al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA);
game.font = al_load_ttf_font("data/ShadowsIntoLight.ttf",al_get_display_height(game.display)*0.09,0 ); int ret = Shared_Load(&game);
if(!game.font) { if (ret!=0) return ret;
fprintf(stderr, "failed to load game font!\n");
return -1;
}
game.font_console = al_load_ttf_font("data/DejaVuSansMono.ttf",al_get_display_height(game.display)*0.018,0 );
if(!game.font_console) {
fprintf(stderr, "failed to load console font!\n");
return -1;
}
game.event_queue = al_create_event_queue(); game.event_queue = al_create_event_queue();
if(!game.event_queue) { if(!game.event_queue) {
fprintf(stderr, "failed to create event_queue!\n"); fprintf(stderr, "failed to create event_queue!\n");
@ -354,10 +370,6 @@ int main(int argc, char **argv){
al_register_event_source(game.event_queue, al_get_keyboard_event_source()); al_register_event_source(game.event_queue, al_get_keyboard_event_source());
game.showconsole = game.debug; game.showconsole = game.debug;
game.console = al_create_bitmap(al_get_display_width(game.display), al_get_display_height(game.display)*0.12);
al_set_target_bitmap(game.console);
al_clear_to_color(al_map_rgba(0,0,0,80));
al_set_target_bitmap(al_get_backbuffer(game.display));
al_clear_to_color(al_map_rgb(0,0,0)); al_clear_to_color(al_map_rgb(0,0,0));
al_flip_display(); al_flip_display();
@ -370,7 +382,7 @@ int main(int argc, char **argv){
game.loadstate = GAMESTATE_LOADING; game.loadstate = GAMESTATE_LOADING;
PreloadGameState(&game); PreloadGameState(&game);
LoadGameState(&game); LoadGameState(&game);
game.loadstate = GAMESTATE_MENU; game.loadstate = GAMESTATE_LEVEL;
while(1) { while(1) {
ALLEGRO_EVENT ev; ALLEGRO_EVENT ev;
al_wait_for_event(game.event_queue, &ev); al_wait_for_event(game.event_queue, &ev);
@ -423,18 +435,19 @@ int main(int argc, char **argv){
al_flip_display(); al_flip_display();
al_rest(0.1); al_rest(0.1);
al_destroy_timer(game.timer); al_destroy_timer(game.timer);
Shared_Unload(&game);
al_destroy_display(game.display); al_destroy_display(game.display);
al_destroy_event_queue(game.event_queue); al_destroy_event_queue(game.event_queue);
al_destroy_font(game.font);
al_destroy_font(game.font_console);
al_destroy_mixer(game.audio.fx); al_destroy_mixer(game.audio.fx);
al_destroy_mixer(game.audio.music); al_destroy_mixer(game.audio.music);
al_destroy_mixer(game.audio.mixer); al_destroy_mixer(game.audio.mixer);
al_destroy_voice(game.audio.voice); al_destroy_voice(game.audio.voice);
al_uninstall_audio(); al_uninstall_audio();
al_shutdown_ttf_addon();
al_shutdown_font_addon();
DeinitConfig(); DeinitConfig();
if (game.restart) return main(argc, argv); if (game.restart) {
al_shutdown_ttf_addon();
al_shutdown_font_addon();
return main(argc, argv);
}
return 0; return 0;
} }

View file

@ -223,4 +223,7 @@ float tps(struct Game *game, float t);
void DrawGameState(struct Game *game); void DrawGameState(struct Game *game);
int Shared_Load(struct Game *game);
void Shared_Unload(struct Game *game);
#endif #endif

View file

@ -223,11 +223,12 @@ void Menu_Stop(struct Game* game) {
} }
al_stop_sample_instance(game->menu.music); al_stop_sample_instance(game->menu.music);
al_stop_sample_instance(game->menu.rain_sound); al_stop_sample_instance(game->menu.rain_sound);
al_destroy_bitmap(game->menu.menu_fade_bitmap);
} }
void Menu_Unload(struct Game *game) { void Menu_Unload(struct Game *game) {
if (!game->menu.loaded) return;
if (game->gamestate==GAMESTATE_MENU) Menu_Stop(game); if (game->gamestate==GAMESTATE_MENU) Menu_Stop(game);
al_destroy_bitmap(game->menu.menu_fade_bitmap);
al_destroy_bitmap(game->menu.pinkcloud); al_destroy_bitmap(game->menu.pinkcloud);
al_destroy_bitmap(game->menu.image); al_destroy_bitmap(game->menu.image);
al_destroy_bitmap(game->menu.cloud); al_destroy_bitmap(game->menu.cloud);

View file

@ -22,6 +22,8 @@
#include "config.h" #include "config.h"
#include "pause.h" #include "pause.h"
#include "menu.h" #include "menu.h"
#include "level.h"
#include "loading.h"
int Pause_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { int Pause_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
if ((game->menu.menustate==MENUSTATE_OPTIONS) && ((ev->keyboard.keycode==ALLEGRO_KEY_ESCAPE) || ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->menu.selected==3)))) { if ((game->menu.menustate==MENUSTATE_OPTIONS) && ((ev->keyboard.keycode==ALLEGRO_KEY_ESCAPE) || ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->menu.selected==3)))) {
@ -34,6 +36,25 @@ int Pause_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
game->menu.menustate=MENUSTATE_OPTIONS; game->menu.menustate=MENUSTATE_OPTIONS;
game->menu.selected=0; game->menu.selected=0;
PrintConsole(game, "menu state changed %d", game->menu.menustate); PrintConsole(game, "menu state changed %d", game->menu.menustate);
if (game->menu.options.fullscreen!=game->fullscreen) {
al_toggle_display_flag(game->display, ALLEGRO_FULLSCREEN_WINDOW, game->menu.options.fullscreen);
al_clear_to_color(al_map_rgb(0,0,0));
al_flip_display();
game->fullscreen = game->menu.options.fullscreen;
if (game->fullscreen) al_hide_mouse_cursor(game->display);
else al_show_mouse_cursor(game->display);
Shared_Unload(game);
Shared_Load(game);
Loading_Unload(game);
Loading_Load(game);
Menu_Unload(game);
Menu_Preload(game);
Level_UnloadBitmaps(game);
Level_PreloadBitmaps(game);
Pause_Unload_Real(game);
Pause_Preload(game);
Pause_Load(game);
}
} else return Menu_Keydown(game, ev); } else return Menu_Keydown(game, ev);
return 0; return 0;
} }
@ -42,7 +63,10 @@ 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);
PrintConsole(game,"Pause preloaded."); PrintConsole(game,"Pause preloaded.");
if (!game->menu.loaded) Menu_Preload(game); if (!game->menu.loaded) {
PrintConsole(game,"Pause: Preloading GAMESTATE_MENU...");
Menu_Preload(game);
}
} }
void Pause_Load(struct Game* game) { void Pause_Load(struct Game* game) {