From 85435fef8d00bc1e719e4290858a2afe05620ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Sun, 25 Mar 2018 18:24:39 +0200 Subject: [PATCH] Added help information. --- src/event_manager.c | 3 +++ src/globals.h | 13 +++++++++++++ src/main.c | 30 ++++++++++++++++++++++++++++-- src/ship.c | 2 -- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/event_manager.c b/src/event_manager.c index 6c4e8eb..96b860e 100644 --- a/src/event_manager.c +++ b/src/event_manager.c @@ -123,6 +123,9 @@ void handle_event() { show_help = !show_help; else if(evnt.keyboard.keycode == ALLEGRO_KEY_I) show_info = !show_info; + else if(evnt.keyboard.keycode == ALLEGRO_KEY_Q || + evnt.keyboard.keycode == ALLEGRO_KEY_ESCAPE) + run = 0; else set_key(evnt.keyboard.keycode, 1); break; diff --git a/src/globals.h b/src/globals.h index b32a708..ca18988 100644 --- a/src/globals.h +++ b/src/globals.h @@ -25,6 +25,19 @@ #ifndef FPS # define FPS 60.0f #endif +#ifndef ACCEL +# define ACCEL 0.5f +#endif +#ifndef TURN_ACCEL +# define TURN_ACCEL (M_PI / FPS) // turn at pi radians / sec +#endif + +#ifndef WINDOW_WIDTH +# define WINDOW_WIDTH 800 +#endif +#ifndef WINDOW_HEIGHT +# define WINDOW_HEIGHT 600 +#endif #include diff --git a/src/main.c b/src/main.c index 5056159..22558fc 100644 --- a/src/main.c +++ b/src/main.c @@ -28,6 +28,14 @@ int show_info; #include #include #include +#include + +const char *help = + "HELP:\n" + "LEFT/RIGHT - turn the ship\n" + "UP/DOWN - accelerate/decelerate\n" + "H - show/hide this help information\n" + "Q/ESC - quit"; int main() { printf("SpaceShipSim v%s\n", VERSION); @@ -49,7 +57,13 @@ int main() { puts("Initialized primitives addon."); #endif - ALLEGRO_DISPLAY *display = al_create_display(800, 600); + if(!al_init_font_addon()) + { + fprintf(stderr, "alleg5: failed to initialize font addon.\n"); + return 1; + } + + ALLEGRO_DISPLAY *display = al_create_display(WINDOW_WIDTH, WINDOW_HEIGHT); if(!display) { fprintf(stderr, "alleg5: failed to initialize display.\n"); @@ -70,6 +84,8 @@ int main() { struct ship ship; ship_init(&ship, 400, 300); + ALLEGRO_FONT *font = al_create_builtin_font(); + // begin running the simulation run = 1; redraw = 1; @@ -97,17 +113,27 @@ int main() { if(show_help) { - // TODO: draw help information + al_draw_multiline_text(font, + al_map_rgb(0xFF, 0xFF, 0xFF), + WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, + WINDOW_WIDTH, 10.0f, + ALLEGRO_ALIGN_CENTRE, + help); } al_flip_display(); redraw = 0; } } + al_destroy_font(font); evnt_mngr_deinit(); al_destroy_display(display); #ifdef DEBUG puts("Destroyed display."); +#endif + al_shutdown_font_addon(); +#ifdef DEBUG + puts("Shutdown font addon."); #endif al_shutdown_primitives_addon(); #ifdef DEBUG diff --git a/src/ship.c b/src/ship.c index 02a4ea0..6f7f8c7 100644 --- a/src/ship.c +++ b/src/ship.c @@ -29,8 +29,6 @@ # define M_PI 3.14159265f #endif -#define ACCEL 0.5f -#define TURN_ACCEL (M_PI / FPS) // turn at pi radians / sec #define SHIP_RADIUS 10.0f // radius of the ship in pixels void ship_init(struct ship *ship, int x, int y) {