diff --git a/src/config.c b/src/config.c index b3ce398..aa0e67e 100644 --- a/src/config.c +++ b/src/config.c @@ -58,12 +58,12 @@ void InitConfig() { FILE *file = fopen("SuperDerpy.ini","r+"); if (! file) { return; } char string[255]; - char section[255] = "[MuffinAttack]"; + char section[255] = "[SuperDerpy]"; struct ConfigOption *old = NULL; while ( fgets (string , 255 , file) != NULL ) { - if (string[0]=='#') { continue; } + if ((string[0]=='#') || (string[0]=='\n')) { continue; } if (string[strlen(string)-1]=='\n') string[strlen(string)-1]='\0'; - if (string[0]=='[') { strcpy(section, string); continue; } + if (string[0]=='[') { strcpy(section, string); continue; } bool before=true; struct ConfigOption *new = malloc(sizeof(struct ConfigOption)); if (old==NULL) { diff --git a/src/loading.c b/src/loading.c index 799d187..04bf5b3 100644 --- a/src/loading.c +++ b/src/loading.c @@ -44,4 +44,4 @@ void Loading_Load(struct Game *game) { int Loading_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { return 0; } void Loading_Preload(struct Game *game) {} -void Loading_Unload(struct Game *game) {} +void Loading_Unload(struct Game *game) { al_destroy_bitmap(game->loading.loading_bitmap); } diff --git a/src/main.c b/src/main.c index 116fdef..4209abf 100644 --- a/src/main.c +++ b/src/main.c @@ -17,12 +17,6 @@ #define DRAW_STATE(state, name) case state:\ name ## _Draw(&game); break; -float FPS = 60; -int DISPLAY_WIDTH = 800; -int DISPLAY_HEIGHT = 500; -bool FULLSCREEN = true; -bool DEBUG_MODE = true; - void al_draw_text_with_shadow(ALLEGRO_FONT *font, ALLEGRO_COLOR color, float x, float y, int flags, char const *text) { al_draw_text(font, al_map_rgba(0,0,0,128), x+1, y+1, flags, text); al_draw_text(font, color, x, y, flags, text); @@ -34,7 +28,7 @@ void PrintConsole(struct Game *game, char* format, ...) { char text[255] = {}; vsprintf(text, format, vl); va_end(vl); - if (DEBUG_MODE) printf("%s\n", text); + if (game->debug) printf("%s\n", text); ALLEGRO_BITMAP *con = al_create_bitmap(al_get_bitmap_width(game->console), al_get_bitmap_height(game->console)); al_set_target_bitmap(con); al_clear_to_color(al_map_rgba(0,0,0,80)); @@ -107,6 +101,17 @@ int main(int argc, char **argv){ struct Game game; + game.fullscreen = atoi(GetConfigOptionDefault("[SuperDerpy]", "fullscreen", "1")); + game.music = atoi(GetConfigOptionDefault("[SuperDerpy]", "music", "1")); + game.fx = atoi(GetConfigOptionDefault("[SuperDerpy]", "fx", "1")); + game.fps = atoi(GetConfigOptionDefault("[SuperDerpy]", "fps", "60")); + if (game.fps<1) game.fps=60; + game.debug = atoi(GetConfigOptionDefault("[SuperDerpy]", "debug", "0")); + game.width = atoi(GetConfigOptionDefault("[SuperDerpy]", "width", "800")); + if (game.width<320) game.width=320; + game.height = atoi(GetConfigOptionDefault("[SuperDerpy]", "height", "500")); + if (game.height<200) game.height=200; + if(!al_init()) { fprintf(stderr, "failed to initialize allegro!\n"); return -1; @@ -114,7 +119,7 @@ int main(int argc, char **argv){ al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR^ALLEGRO_MAG_LINEAR); - game.timer = al_create_timer(ALLEGRO_BPS_TO_SECS(FPS)); + game.timer = al_create_timer(ALLEGRO_BPS_TO_SECS(game.fps)); if(!game.timer) { fprintf(stderr, "failed to create timer!\n"); return -1; @@ -154,15 +159,15 @@ int main(int argc, char **argv){ return -1; } - if (FULLSCREEN) al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW); + if (game.fullscreen) al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW); al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST); - game.display = al_create_display(DISPLAY_WIDTH, DISPLAY_HEIGHT); + game.display = al_create_display(game.width, game.height); if(!game.display) { fprintf(stderr, "failed to create display!\n"); return -1; } al_set_window_title(game.display, "Super Derpy: Muffin Attack"); - if (FULLSCREEN) al_hide_mouse_cursor(game.display); + if (game.fullscreen) al_hide_mouse_cursor(game.display); game.font = al_load_ttf_font("data/ShadowsIntoLight.ttf",al_get_display_height(game.display)*0.09,0 ); game.font_console = al_load_ttf_font("data/DejaVuSansMono.ttf",al_get_display_height(game.display)*0.018,0 ); @@ -177,7 +182,7 @@ int main(int argc, char **argv){ al_register_event_source(game.event_queue, al_get_timer_event_source(game.timer)); al_register_event_source(game.event_queue, al_get_keyboard_event_source()); - game.showconsole = DEBUG_MODE; + 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)); @@ -260,7 +265,6 @@ int main(int argc, char **argv){ al_rest(0.1); al_destroy_timer(game.timer); al_destroy_display(game.display); - al_destroy_bitmap(game.loading.loading_bitmap); al_destroy_event_queue(game.event_queue); al_destroy_font(game.font); al_destroy_font(game.font_console); diff --git a/src/main.h b/src/main.h index d3a7cee..7cb22a7 100644 --- a/src/main.h +++ b/src/main.h @@ -72,7 +72,8 @@ struct Game { ALLEGRO_EVENT_QUEUE *event_queue; ALLEGRO_TIMER *timer; ALLEGRO_BITMAP *console; - bool showconsole, fx, music, fullscreen; + bool showconsole, fx, music, fullscreen, debug; + int fps, width, height; struct Menu menu; struct Loading loading; struct Intro intro; diff --git a/src/map.c b/src/map.c index 0385b03..72f56cc 100644 --- a/src/map.c +++ b/src/map.c @@ -1,5 +1,6 @@ #include #include +#include "config.h" #include "map.h" void Map_Draw(struct Game *game) { @@ -74,7 +75,8 @@ int Map_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { } void Map_Preload(struct Game *game) { - game->map.available = 6; + game->map.available = atoi(GetConfigOptionDefault("[MuffinAttack]", "level", "1")); + if ((game->map.available<1) || (game->map.available>6)) game->map.available=1; game->map.selected = game->map.available; PrintConsole(game, "Last level available: %d", game->map.selected); game->map.arrowpos = 0; @@ -101,7 +103,7 @@ void Map_Preload(struct Game *game) { al_draw_scaled_bitmap(game->map.background,0,0,al_get_bitmap_width(game->map.background),al_get_bitmap_height(game->map.background),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0); al_draw_scaled_bitmap(game->map.map_bg,0,0,al_get_bitmap_width(game->map.map_bg),al_get_bitmap_height(game->map.map_bg),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0); al_draw_scaled_bitmap(game->map.highlight,0,0,al_get_bitmap_width(game->map.highlight),al_get_bitmap_height(game->map.highlight),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0); - al_set_target_bitmap(al_get_backbuffer(game->display)); + al_set_target_bitmap(al_get_backbuffer(game->display)); } void Map_Unload(struct Game *game) {