From c51f34c888d7691f557733b9a7f4341976db46c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Sun, 25 Mar 2018 18:43:06 +0200 Subject: [PATCH] Fully functional simulation. I still need to add the restart feature. --- src/globals.h | 7 +++++++ src/main.c | 21 ++++++++++++++++++++- src/ship.c | 4 ---- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/globals.h b/src/globals.h index ca18988..9e2596e 100644 --- a/src/globals.h +++ b/src/globals.h @@ -39,6 +39,13 @@ # define WINDOW_HEIGHT 600 #endif +#include +#ifndef M_PI +# define M_PI 3.14159265f +#endif + +#define RAD_TO_DEG(x) (x * 180 / M_PI) + #include extern int redraw; ///< Whether or not to redraw the screen. diff --git a/src/main.c b/src/main.c index 22558fc..29ca322 100644 --- a/src/main.c +++ b/src/main.c @@ -34,9 +34,18 @@ const char *help = "HELP:\n" "LEFT/RIGHT - turn the ship\n" "UP/DOWN - accelerate/decelerate\n" + "I - show/hide simulation information\n" "H - show/hide this help information\n" "Q/ESC - quit"; +const char *info_format = + "INFO:\n" + "x: %f\n" + "y: %f\n" + "angle: %f (%f degrees)\n" + "velX: %f\n" + "velY: %f"; + int main() { printf("SpaceShipSim v%s\n", VERSION); @@ -108,7 +117,17 @@ int main() { ship_draw(&ship); if(show_info) { - // TODO: draw simulation stats + char info[256]; + sprintf(info, info_format, + ship.x, ship.y, + ship.direction, + RAD_TO_DEG(ship.direction), + ship.velX, ship.velY); + al_draw_multiline_text(font, + al_map_rgb(0xFF, 0xFF, 0xFF), + 5, 5, WINDOW_WIDTH, 10.0f, + ALLEGRO_ALIGN_LEFT, + info); } if(show_help) diff --git a/src/ship.c b/src/ship.c index 6f7f8c7..42fc773 100644 --- a/src/ship.c +++ b/src/ship.c @@ -25,10 +25,6 @@ #include #include -#ifndef M_PI -# define M_PI 3.14159265f -#endif - #define SHIP_RADIUS 10.0f // radius of the ship in pixels void ship_init(struct ship *ship, int x, int y) {