Fully functional simulation.

I still need to add the restart feature.
This commit is contained in:
Nicolás Ortega Froysa 2018-03-25 18:43:06 +02:00
parent 85435fef8d
commit c51f34c888
No known key found for this signature in database
GPG Key ID: FEC70E3BAE2E69BF
3 changed files with 27 additions and 5 deletions

View File

@ -39,6 +39,13 @@
# define WINDOW_HEIGHT 600
#endif
#include <math.h>
#ifndef M_PI
# define M_PI 3.14159265f
#endif
#define RAD_TO_DEG(x) (x * 180 / M_PI)
#include <allegro5/allegro.h>
extern int redraw; ///< Whether or not to redraw the screen.

View File

@ -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)

View File

@ -25,10 +25,6 @@
#include <allegro5/allegro_primitives.h>
#include <stdio.h>
#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) {