mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-01 11:06:44 +01:00
add video options, implement fullscreen switching
This commit is contained in:
parent
1f43af56f0
commit
d8a6106157
3 changed files with 93 additions and 2 deletions
|
@ -306,6 +306,7 @@ int main(int argc, char **argv){
|
|||
}
|
||||
|
||||
if (game.fullscreen) al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);
|
||||
else al_set_new_display_flags(ALLEGRO_WINDOWED);
|
||||
al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST);
|
||||
//al_set_new_display_option(ALLEGRO_OPENGL, 1, ALLEGRO_SUGGEST);
|
||||
game.display = al_create_display(game.width, game.height);
|
||||
|
@ -362,6 +363,7 @@ int main(int argc, char **argv){
|
|||
|
||||
game.shuttingdown = false;
|
||||
game.menu.loaded = false;
|
||||
game.restart = false;
|
||||
game.loadstate = GAMESTATE_LOADING;
|
||||
PreloadGameState(&game);
|
||||
LoadGameState(&game);
|
||||
|
@ -427,6 +429,9 @@ int main(int argc, char **argv){
|
|||
al_destroy_mixer(game.audio.mixer);
|
||||
al_destroy_voice(game.audio.voice);
|
||||
al_uninstall_audio();
|
||||
al_shutdown_ttf_addon();
|
||||
al_shutdown_font_addon();
|
||||
DeinitConfig();
|
||||
if (game.restart) return main(argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -94,6 +94,12 @@ struct Menu {
|
|||
int selected;
|
||||
enum menustate_enum menustate;
|
||||
bool loaded;
|
||||
struct {
|
||||
bool fullscreen;
|
||||
int fps;
|
||||
int width;
|
||||
int height;
|
||||
} options;
|
||||
};
|
||||
|
||||
/*! \brief Resources used by Loading state. */
|
||||
|
@ -168,6 +174,7 @@ struct Game {
|
|||
int width;
|
||||
int height;
|
||||
bool shuttingdown;
|
||||
bool restart;
|
||||
struct Menu menu;
|
||||
struct Loading loading;
|
||||
struct Intro intro;
|
||||
|
|
83
src/menu.c
83
src/menu.c
|
@ -25,7 +25,8 @@
|
|||
|
||||
void DrawMenuState(struct Game *game) {
|
||||
ALLEGRO_FONT *font;
|
||||
|
||||
char* text;
|
||||
struct ALLEGRO_COLOR color;
|
||||
switch (game->menu.menustate) {
|
||||
case MENUSTATE_MAIN:
|
||||
font = game->menu.font; if (game->menu.selected==0) font = game->menu.font_selected;
|
||||
|
@ -43,7 +44,6 @@ void DrawMenuState(struct Game *game) {
|
|||
font = game->menu.font; if (game->menu.selected==1) font = game->menu.font_selected;
|
||||
al_draw_text_with_shadow(font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.6, ALLEGRO_ALIGN_CENTRE, "Video settings");
|
||||
font = game->menu.font; if (game->menu.selected==2) font = game->menu.font_selected;
|
||||
char* text;
|
||||
if ((game->music) && (game->fx))
|
||||
text="Sounds: all";
|
||||
else if (game->music)
|
||||
|
@ -56,6 +56,24 @@ void DrawMenuState(struct Game *game) {
|
|||
font = game->menu.font; if (game->menu.selected==3) font = game->menu.font_selected;
|
||||
al_draw_text_with_shadow(font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.8, ALLEGRO_ALIGN_CENTRE, "Back");
|
||||
break;
|
||||
case MENUSTATE_VIDEO:
|
||||
if (game->menu.options.fullscreen) {
|
||||
text="Fullscreen: yes";
|
||||
color = al_map_rgba(0,0,0,128);
|
||||
}
|
||||
else {
|
||||
text="Fullscreen: no";
|
||||
color = al_map_rgba(255,255,255,255);
|
||||
}
|
||||
font = game->menu.font; if (game->menu.selected==0) font = game->menu.font_selected;
|
||||
al_draw_text_with_shadow(font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.5, ALLEGRO_ALIGN_CENTRE, text);
|
||||
font = game->menu.font; if (game->menu.selected==1) font = game->menu.font_selected;
|
||||
al_draw_text_with_shadow(font, color, al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.6, ALLEGRO_ALIGN_CENTRE, "Resolution: 800x500");
|
||||
font = game->menu.font; if (game->menu.selected==2) font = game->menu.font_selected;
|
||||
al_draw_text_with_shadow(font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.7, ALLEGRO_ALIGN_CENTRE, "FPS: 60");
|
||||
font = game->menu.font; if (game->menu.selected==3) font = game->menu.font_selected;
|
||||
al_draw_text_with_shadow(font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.8, ALLEGRO_ALIGN_CENTRE, "Back");
|
||||
break;
|
||||
case MENUSTATE_PAUSE:
|
||||
font = game->menu.font; if (game->menu.selected==0) font = game->menu.font_selected;
|
||||
al_draw_text_with_shadow(font, al_map_rgb(255,255,255), al_get_display_width(game->display)*0.5, al_get_display_height(game->display)*0.5, ALLEGRO_ALIGN_CENTRE, "Resume game");
|
||||
|
@ -117,6 +135,10 @@ void Menu_Draw(struct Game *game) {
|
|||
}
|
||||
|
||||
void Menu_Preload(struct Game *game) {
|
||||
game->menu.options.fullscreen = game->fullscreen;
|
||||
game->menu.options.fps = game->fps;
|
||||
game->menu.options.width = game->width;
|
||||
game->menu.options.height = game->height;
|
||||
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.mountain = LoadScaledBitmap( "mountain.png", al_get_display_width(game->display)*0.055, al_get_display_height(game->display)/9 );
|
||||
|
@ -258,9 +280,11 @@ int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
|||
|
||||
if (ev->keyboard.keycode==ALLEGRO_KEY_UP) {
|
||||
game->menu.selected--;
|
||||
if ((game->menu.menustate==MENUSTATE_VIDEO) && (game->menu.selected==1) && (game->menu.options.fullscreen)) game->menu.selected--;
|
||||
al_play_sample_instance(game->menu.click);
|
||||
} else if (ev->keyboard.keycode==ALLEGRO_KEY_DOWN) {
|
||||
game->menu.selected++;
|
||||
if ((game->menu.menustate==MENUSTATE_VIDEO) && (game->menu.selected==1) && (game->menu.options.fullscreen)) game->menu.selected++;
|
||||
al_play_sample_instance(game->menu.click);
|
||||
}
|
||||
|
||||
|
@ -291,6 +315,16 @@ int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
|||
break;
|
||||
case MENUSTATE_OPTIONS:
|
||||
switch (game->menu.selected) {
|
||||
case 0:
|
||||
game->menu.menustate=MENUSTATE_CONTROLS;
|
||||
game->menu.selected=0;
|
||||
PrintConsole(game, "menu state changed %d", game->menu.menustate);
|
||||
break;
|
||||
case 1:
|
||||
game->menu.menustate=MENUSTATE_VIDEO;
|
||||
game->menu.selected=0;
|
||||
PrintConsole(game, "menu state changed %d", game->menu.menustate);
|
||||
break;
|
||||
case 2:
|
||||
if ((game->music) && (game->fx)) { game->music=0; SetConfigOption("SuperDerpy", "music", "0");
|
||||
al_detach_mixer(game->audio.music);
|
||||
|
@ -341,6 +375,41 @@ int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
|||
break;
|
||||
}
|
||||
break;
|
||||
case MENUSTATE_CONTROLS:
|
||||
switch (game->menu.selected) {
|
||||
case 3:
|
||||
game->menu.menustate=MENUSTATE_OPTIONS;
|
||||
game->menu.selected=0;
|
||||
PrintConsole(game, "menu state changed %d", game->menu.menustate);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case MENUSTATE_VIDEO:
|
||||
switch (game->menu.selected) {
|
||||
case 0:
|
||||
game->menu.options.fullscreen = !game->menu.options.fullscreen;
|
||||
if (game->menu.options.fullscreen)
|
||||
SetConfigOption("SuperDerpy", "fullscreen", "1");
|
||||
else
|
||||
SetConfigOption("SuperDerpy", "fullscreen", "0");
|
||||
break;
|
||||
case 3:
|
||||
if ((game->menu.options.fullscreen==game->fullscreen) && (game->menu.options.fps==game->fps) && (game->menu.options.width==game->width) && (game->menu.options.height==game->height)) {
|
||||
game->menu.menustate=MENUSTATE_OPTIONS;
|
||||
game->menu.selected=0;
|
||||
PrintConsole(game, "menu state changed %d", game->menu.menustate);
|
||||
} else {
|
||||
PrintConsole(game, "video settings changed, restarting...");
|
||||
game->restart = true;
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
break;
|
||||
|
@ -352,6 +421,16 @@ int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
|||
game->menu.selected=0;
|
||||
PrintConsole(game, "menu state changed %d", game->menu.menustate);
|
||||
break;
|
||||
case MENUSTATE_VIDEO:
|
||||
game->menu.menustate=MENUSTATE_OPTIONS;
|
||||
game->menu.selected=0;
|
||||
PrintConsole(game, "menu state changed %d", game->menu.menustate);
|
||||
break;
|
||||
case MENUSTATE_CONTROLS:
|
||||
game->menu.menustate=MENUSTATE_OPTIONS;
|
||||
game->menu.selected=0;
|
||||
PrintConsole(game, "menu state changed %d", game->menu.menustate);
|
||||
break;
|
||||
case MENUSTATE_PAUSE:
|
||||
PrintConsole(game,"Game resumed.");
|
||||
al_destroy_bitmap(game->pause.bitmap);
|
||||
|
|
Loading…
Reference in a new issue