From edd4d79eb99ffe907e945785b6a6d3fb1389a412 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Sun, 19 Feb 2012 22:54:33 +0100 Subject: [PATCH] make string formatting in PrintConsole possible and use it --- bin/.gitignore | 2 +- src/intro.c | 7 +++---- src/main.c | 20 +++++++++++++------- src/main.h | 2 +- src/menu.c | 6 +++--- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/bin/.gitignore b/bin/.gitignore index 5761abc..72e8ffc 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1 +1 @@ -*.o +* diff --git a/src/intro.c b/src/intro.c index d3d5107..5b5dca9 100644 --- a/src/intro.c +++ b/src/intro.c @@ -49,9 +49,8 @@ int Intro_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { return 0; } if (!game->intro.in_animation) { - PrintConsole(game, "Animate page..."); + PrintConsole(game, "Animate page (was on %d)...", ++game->intro.page); game->intro.in_animation = true; - game->intro.page++; } return 0; } @@ -73,9 +72,9 @@ void Intro_Preload(struct Game *game) { //game->intro.table_bitmap = al_load_bitmap( "table.png" ); al_draw_scaled_bitmap(game->intro.table_bitmap, 0, 0, al_get_bitmap_width(game->intro.table_bitmap), al_get_bitmap_height(game->intro.table_bitmap), al_get_display_width(game->display), 0, al_get_display_width(game->display), al_get_display_height(game->display), ALLEGRO_FLIP_HORIZONTAL); //game->intro.table_bitmap = al_load_bitmap( "menu.png" ); - al_draw_scaled_bitmap(game->intro.table_bitmap, 0, 0, al_get_bitmap_width(game->intro.table_bitmap), al_get_bitmap_height(game->intro.table_bitmap), al_get_display_width(game->display)*2, 0, al_get_display_width(game->display), al_get_display_height(game->display), 0); + al_draw_scaled_bitmap(game->intro.table_bitmap, 0, 0, al_get_bitmap_width(game->intro.table_bitmap), al_get_bitmap_height(game->intro.table_bitmap), al_get_display_width(game->display)*2, 0, al_get_display_width(game->display), al_get_display_height(game->display), ALLEGRO_FLIP_VERTICAL); //game->intro.table_bitmap = al_load_bitmap( "table.png" ); - al_draw_scaled_bitmap(game->intro.table_bitmap, 0, 0, al_get_bitmap_width(game->intro.table_bitmap), al_get_bitmap_height(game->intro.table_bitmap), al_get_display_width(game->display)*3, 0, al_get_display_width(game->display), al_get_display_height(game->display), ALLEGRO_FLIP_HORIZONTAL); + al_draw_scaled_bitmap(game->intro.table_bitmap, 0, 0, al_get_bitmap_width(game->intro.table_bitmap), al_get_bitmap_height(game->intro.table_bitmap), al_get_display_width(game->display)*3, 0, al_get_display_width(game->display), al_get_display_height(game->display), ALLEGRO_FLIP_HORIZONTAL^ALLEGRO_FLIP_VERTICAL); al_draw_text(game->intro.font, al_map_rgb(255,255,255), al_get_bitmap_width(game->intro.table_bitmap)*0.5, al_get_bitmap_height(game->intro.table_bitmap)*0.3, ALLEGRO_ALIGN_LEFT, "Tekst."); al_draw_text(game->intro.font, al_map_rgb(255,255,255), al_get_bitmap_width(game->intro.table_bitmap)*0.5, al_get_bitmap_height(game->intro.table_bitmap)*0.37, ALLEGRO_ALIGN_LEFT, "Drugi tekst."); diff --git a/src/main.c b/src/main.c index 51fb218..6b93422 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,5 @@ #include +#include #include "menu.h" #include "loading.h" #include "about.h" @@ -11,7 +12,12 @@ int DISPLAY_HEIGHT = 500; bool FULLSCREEN = true; bool DEBUG_MODE = true; -void PrintConsole(struct Game *game, char* text) { +void PrintConsole(struct Game *game, char* format, ...) { + va_list vl; + va_start(vl, format); + char text[255] = {}; + vsprintf(text, format, vl); + va_end(vl); if (DEBUG_MODE) printf("%s\n", text); ALLEGRO_BITMAP *con = al_create_bitmap(al_get_bitmap_width(game->console), al_get_bitmap_height(game->console)*1.0); al_set_target_bitmap(con); @@ -61,7 +67,7 @@ void PreloadGameState(struct Game *game) { al_flip_display(); Map_Preload(game); } else { - PrintConsole(game, "ERROR: Attempted to preload unknown gamestate!"); + PrintConsole(game, "ERROR: Attempted to preload unknown gamestate %d!", game->gamestate); } PrintConsole(game, "finished"); } @@ -87,7 +93,7 @@ void UnloadGameState(struct Game *game) { PrintConsole(game, "Unload GAMESTATE_MAP..."); Map_Unload(game); } else { - PrintConsole(game, "ERROR: Attempted to unload unknown gamestate!"); + PrintConsole(game, "ERROR: Attempted to unload unknown gamestate %d!", game->gamestate); } PrintConsole(game, "finished"); } @@ -113,7 +119,7 @@ void LoadGameState(struct Game *game) { PrintConsole(game, "Load GAMESTATE_MAP..."); Map_Load(game); } else { - PrintConsole(game, "ERROR: Attempted to load unknown gamestate!"); + PrintConsole(game, "ERROR: Attempted to load unknown gamestate %d!", game->gamestate); } PrintConsole(game, "finished"); game->gamestate = game->loadstate; @@ -181,7 +187,7 @@ int main(int argc, char **argv){ return -1; } al_set_window_title(game.display, "Super Derpy: Muffin Attack"); - al_hide_mouse_cursor(game.display); + if (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 ); @@ -243,7 +249,7 @@ int main(int argc, char **argv){ } else { game.showconsole = true; - PrintConsole(&game, "ERROR: Keystroke in unknown gamestate! (5 sec sleep)"); + PrintConsole(&game, "ERROR: Keystroke in unknown (%d) gamestate! (5 sec sleep)", game.gamestate); DrawConsole(&game); al_flip_display(); al_rest(5.0); @@ -272,7 +278,7 @@ int main(int argc, char **argv){ } else { game.showconsole = true; - PrintConsole(&game, "ERROR: Unknown gamestate reached! (5 sec sleep)"); + PrintConsole(&game, "ERROR: Unknown gamestate %d reached! (5 sec sleep)", game.gamestate); DrawConsole(&game); al_flip_display(); al_rest(5.0); diff --git a/src/main.h b/src/main.h index 4a807bd..8baca87 100644 --- a/src/main.h +++ b/src/main.h @@ -72,7 +72,7 @@ struct Game { void PreloadGameState(struct Game *game); void UnloadGameState(struct Game *game); void LoadGameState(struct Game *game); -void PrintConsole(struct Game *game, char* text); +void PrintConsole(struct Game *game, char* format, ...); void DrawConsole(struct Game *game); #endif \ No newline at end of file diff --git a/src/menu.c b/src/menu.c index 3252a90..9ddbfbd 100644 --- a/src/menu.c +++ b/src/menu.c @@ -21,8 +21,8 @@ void Menu_Draw(struct Game *game) { al_set_target_bitmap(al_get_backbuffer(game->display)); al_clear_to_color(al_map_rgb(183,234,193)); - float tint = (sin((game->menu.cloud_position-30)/15)+1)/2; - if (tint < 0.0001) { PrintConsole(game, "random tint"); game->menu.mountain_position = (al_get_display_width(game->display)*(rand()/(float)RAND_MAX)/2)+al_get_display_width(game->display)/2; } + float tint = (sin((game->menu.cloud_position-80)/15)+1)/2; + if (tint < 0.000004) { PrintConsole(game, "random tint %f", tint); game->menu.mountain_position = (al_get_display_width(game->display)*(rand()/(float)RAND_MAX)/2)+al_get_display_width(game->display)/2; } al_draw_tinted_bitmap(game->menu.mountain_bitmap,al_map_rgba_f(tint,tint,tint,tint),game->menu.mountain_position, 0,0); al_draw_scaled_bitmap(game->menu.cloud_bitmap,0,0,al_get_bitmap_width(game->menu.cloud_bitmap), al_get_bitmap_height(game->menu.cloud_bitmap), al_get_display_width(game->display)*(sin((game->menu.cloud_position/40)-4.5)-0.3), al_get_display_height(game->display)*0.35, al_get_bitmap_width(game->menu.cloud_bitmap)/2, al_get_bitmap_height(game->menu.cloud_bitmap)/2,0); al_draw_bitmap(game->menu.cloud2_bitmap,al_get_display_width(game->display)*(game->menu.cloud2_position/100.0), al_get_display_height(game->display)/1.5,0); @@ -211,7 +211,7 @@ int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev) { al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL); game->menu.options=!game->menu.options; game->menu.selected=0; - PrintConsole(game, "options state changed"); + PrintConsole(game, "options state changed %d", game->menu.options); } if (game->menu.selected==-1) game->menu.selected=3; if (game->menu.selected==4) game->menu.selected=0;