Fully functional simulation.
I still need to add the restart feature.
This commit is contained in:
parent
85435fef8d
commit
c51f34c888
@ -39,6 +39,13 @@
|
|||||||
# define WINDOW_HEIGHT 600
|
# define WINDOW_HEIGHT 600
|
||||||
#endif
|
#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>
|
#include <allegro5/allegro.h>
|
||||||
|
|
||||||
extern int redraw; ///< Whether or not to redraw the screen.
|
extern int redraw; ///< Whether or not to redraw the screen.
|
||||||
|
21
src/main.c
21
src/main.c
@ -34,9 +34,18 @@ const char *help =
|
|||||||
"HELP:\n"
|
"HELP:\n"
|
||||||
"LEFT/RIGHT - turn the ship\n"
|
"LEFT/RIGHT - turn the ship\n"
|
||||||
"UP/DOWN - accelerate/decelerate\n"
|
"UP/DOWN - accelerate/decelerate\n"
|
||||||
|
"I - show/hide simulation information\n"
|
||||||
"H - show/hide this help information\n"
|
"H - show/hide this help information\n"
|
||||||
"Q/ESC - quit";
|
"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() {
|
int main() {
|
||||||
printf("SpaceShipSim v%s\n", VERSION);
|
printf("SpaceShipSim v%s\n", VERSION);
|
||||||
|
|
||||||
@ -108,7 +117,17 @@ int main() {
|
|||||||
ship_draw(&ship);
|
ship_draw(&ship);
|
||||||
if(show_info)
|
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)
|
if(show_help)
|
||||||
|
@ -25,10 +25,6 @@
|
|||||||
#include <allegro5/allegro_primitives.h>
|
#include <allegro5/allegro_primitives.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifndef M_PI
|
|
||||||
# define M_PI 3.14159265f
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SHIP_RADIUS 10.0f // radius of the ship in pixels
|
#define SHIP_RADIUS 10.0f // radius of the ship in pixels
|
||||||
|
|
||||||
void ship_init(struct ship *ship, int x, int y) {
|
void ship_init(struct ship *ship, int x, int y) {
|
||||||
|
Loading…
Reference in New Issue
Block a user