Compare commits

...

12 Commits
v0.3 ... master

Author SHA1 Message Date
Nicolás Ortega Froysa
8924741937
Remove from the TODO 2018-04-13 08:02:55 +02:00
Nicolás Ortega Froysa
63f950e26b
Implement pause functionality. 2018-04-13 08:02:34 +02:00
Nicolás Ortega Froysa
349848ebf6
Remove extra 5.0 stuff (fix later). 2018-04-13 08:01:53 +02:00
Nicolás Ortega Froysa
395c3c854f
Require minimum version of Allegro. 2018-04-04 11:55:02 +02:00
Nicolás Ortega Froysa
a93e9a7b73
For compatibility with Debian systems.
For some reason they specify the minor version too, which is retarded.
2018-04-04 11:51:20 +02:00
Nicolás Ortega Froysa
29219bbc2c
Added a TODO list. 2018-03-29 13:04:35 +02:00
Nicolás Ortega Froysa
d343c5e5a0
Move help information further up. 2018-03-29 13:01:09 +02:00
Nicolás Ortega Froysa
17777e2178
No need to update the ship if we reset. 2018-03-29 12:58:37 +02:00
Nicolás Ortega Froysa
609d197227
Better description. 2018-03-29 12:56:01 +02:00
Nicolás Ortega Froysa
e29a0bc7a3
Slower acceleration. 2018-03-29 12:55:48 +02:00
Nicolás Ortega Froysa
92e406bc74
Measure by pixel/second 2018-03-29 11:57:17 +02:00
Nicolás Ortega Froysa
2d64adf476
Put version in window title. 2018-03-29 01:06:15 +02:00
6 changed files with 34 additions and 17 deletions

View File

@ -34,7 +34,7 @@ set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O3 -ffast-math")
set(CMAKE_C_FLAGS_MINSIZEREL "-Os")
find_package(PkgConfig REQUIRED)
pkg_check_modules(ALLEG5 REQUIRED allegro-5)
pkg_check_modules(ALLEG5 REQUIRED allegro-5>=5.1.9)
pkg_check_modules(ALLEG5-PRIM REQUIRED allegro_primitives-5)
pkg_check_modules(ALLEG5-FONT REQUIRED allegro_font-5)

3
TODO Normal file
View File

@ -0,0 +1,3 @@
TODO:
- Add a fullscreen mode.
- Add presets with stellar masses (for gravity simulation).

View File

@ -101,6 +101,9 @@ void set_key(int keycode, int value) {
case ALLEGRO_KEY_F:
keys[KEY_FULLSCREEN] = value;
break;
case ALLEGRO_KEY_P:
keys[KEY_PAUSE] = value;
break;
default:
break;
}

View File

@ -27,7 +27,8 @@ enum {
KEY_RIGHT = 0x3,
KEY_RESET = 0x4,
KEY_FULLSCREEN = 0x5,
KEY_MAX = 0x6
KEY_PAUSE = 0x6,
KEY_MAX = 0x7
};
/**

View File

@ -26,7 +26,7 @@
# define FPS 60.0f
#endif
#ifndef ACCEL
# define ACCEL 0.5f
# define ACCEL 0.1f
#endif
#ifndef TURN_ACCEL
# define TURN_ACCEL (M_PI / FPS) // turn at pi radians / sec

View File

@ -33,7 +33,7 @@ int show_info;
const char *help =
"HELP:\n"
"LEFT/RIGHT - turn the ship\n"
"UP/DOWN - accelerate/decelerate\n"
"UP/DOWN - accelerate/reverse accelerate\n"
"R - reset the simulation\n"
"I - show/hide simulation information\n"
"H - show/hide this help information\n"
@ -44,11 +44,13 @@ const char *info_format =
"x: %f\n"
"y: %f\n"
"angle: %f (%f degrees)\n"
"velX: %f\n"
"velY: %f";
"velX: %f px/sec\n"
"velY: %f px/sec";
int main() {
printf("SpaceShipSim v%s\n", VERSION);
char title[32];
sprintf(title, "SpaceShipSim v%s", VERSION);
puts(title);
if(!al_init())
{
@ -79,6 +81,7 @@ int main() {
fprintf(stderr, "alleg5: failed to initialize display.\n");
return 1;
}
al_set_window_title(display, title);
#ifdef DEBUG
puts("Created display.");
#endif
@ -101,6 +104,8 @@ int main() {
redraw = 1;
show_help = 1;
show_info = 1;
int paused = 0;
int old_paused = 0;
while(run)
{
handle_event();
@ -108,14 +113,19 @@ int main() {
// only redraw or run simulation if the timer event has occurred
if(redraw)
{
if(key_is_down(KEY_RESET))
ship_init(&ship, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2);
/*
* We only run the simulation when the timer goes off so it's
* running at a consistent rate, rather than dependent on random
* events.
*/
ship_update(&ship);
if(paused == old_paused && key_is_down(KEY_PAUSE))
paused = !paused;
else if(paused != old_paused && !key_is_down(KEY_PAUSE))
old_paused = paused;
if(!paused)
{
if(key_is_down(KEY_RESET))
ship_init(&ship, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2);
else
ship_update(&ship);
}
al_clear_to_color(al_map_rgb(0, 0, 0));
ship_draw(&ship);
if(show_info)
@ -125,7 +135,7 @@ int main() {
ship.x, ship.y,
ship.direction,
RAD_TO_DEG(ship.direction),
ship.velX, ship.velY);
ship.velX * FPS, ship.velY * FPS);
al_draw_multiline_text(font,
al_map_rgb(0xFF, 0xFF, 0xFF),
5, 5, WINDOW_WIDTH, 10.0f,
@ -137,7 +147,7 @@ int main() {
{
al_draw_multiline_text(font,
al_map_rgb(0xFF, 0xFF, 0xFF),
WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2,
WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2 - 50,
WINDOW_WIDTH, 10.0f,
ALLEGRO_ALIGN_CENTRE,
help);