Compare commits
10 Commits
92e406bc74
...
8924741937
Author | SHA1 | Date | |
---|---|---|---|
|
8924741937 | ||
|
63f950e26b | ||
|
349848ebf6 | ||
|
395c3c854f | ||
|
a93e9a7b73 | ||
|
29219bbc2c | ||
|
d343c5e5a0 | ||
|
17777e2178 | ||
|
609d197227 | ||
|
e29a0bc7a3 |
@ -34,7 +34,7 @@ set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O3 -ffast-math")
|
|||||||
set(CMAKE_C_FLAGS_MINSIZEREL "-Os")
|
set(CMAKE_C_FLAGS_MINSIZEREL "-Os")
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
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-PRIM REQUIRED allegro_primitives-5)
|
||||||
pkg_check_modules(ALLEG5-FONT REQUIRED allegro_font-5)
|
pkg_check_modules(ALLEG5-FONT REQUIRED allegro_font-5)
|
||||||
|
|
||||||
|
3
TODO
Normal file
3
TODO
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
TODO:
|
||||||
|
- Add a fullscreen mode.
|
||||||
|
- Add presets with stellar masses (for gravity simulation).
|
@ -101,6 +101,9 @@ void set_key(int keycode, int value) {
|
|||||||
case ALLEGRO_KEY_F:
|
case ALLEGRO_KEY_F:
|
||||||
keys[KEY_FULLSCREEN] = value;
|
keys[KEY_FULLSCREEN] = value;
|
||||||
break;
|
break;
|
||||||
|
case ALLEGRO_KEY_P:
|
||||||
|
keys[KEY_PAUSE] = value;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,8 @@ enum {
|
|||||||
KEY_RIGHT = 0x3,
|
KEY_RIGHT = 0x3,
|
||||||
KEY_RESET = 0x4,
|
KEY_RESET = 0x4,
|
||||||
KEY_FULLSCREEN = 0x5,
|
KEY_FULLSCREEN = 0x5,
|
||||||
KEY_MAX = 0x6
|
KEY_PAUSE = 0x6,
|
||||||
|
KEY_MAX = 0x7
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
# define FPS 60.0f
|
# define FPS 60.0f
|
||||||
#endif
|
#endif
|
||||||
#ifndef ACCEL
|
#ifndef ACCEL
|
||||||
# define ACCEL 0.5f
|
# define ACCEL 0.1f
|
||||||
#endif
|
#endif
|
||||||
#ifndef TURN_ACCEL
|
#ifndef TURN_ACCEL
|
||||||
# define TURN_ACCEL (M_PI / FPS) // turn at pi radians / sec
|
# define TURN_ACCEL (M_PI / FPS) // turn at pi radians / sec
|
||||||
|
27
src/main.c
27
src/main.c
@ -33,7 +33,7 @@ int show_info;
|
|||||||
const char *help =
|
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/reverse accelerate\n"
|
||||||
"R - reset the simulation\n"
|
"R - reset the simulation\n"
|
||||||
"I - show/hide simulation information\n"
|
"I - show/hide simulation information\n"
|
||||||
"H - show/hide this help information\n"
|
"H - show/hide this help information\n"
|
||||||
@ -104,6 +104,8 @@ int main() {
|
|||||||
redraw = 1;
|
redraw = 1;
|
||||||
show_help = 1;
|
show_help = 1;
|
||||||
show_info = 1;
|
show_info = 1;
|
||||||
|
int paused = 0;
|
||||||
|
int old_paused = 0;
|
||||||
while(run)
|
while(run)
|
||||||
{
|
{
|
||||||
handle_event();
|
handle_event();
|
||||||
@ -111,14 +113,19 @@ int main() {
|
|||||||
// only redraw or run simulation if the timer event has occurred
|
// only redraw or run simulation if the timer event has occurred
|
||||||
if(redraw)
|
if(redraw)
|
||||||
{
|
{
|
||||||
if(key_is_down(KEY_RESET))
|
if(paused == old_paused && key_is_down(KEY_PAUSE))
|
||||||
ship_init(&ship, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2);
|
paused = !paused;
|
||||||
/*
|
else if(paused != old_paused && !key_is_down(KEY_PAUSE))
|
||||||
* We only run the simulation when the timer goes off so it's
|
old_paused = paused;
|
||||||
* running at a consistent rate, rather than dependent on random
|
|
||||||
* events.
|
if(!paused)
|
||||||
*/
|
{
|
||||||
ship_update(&ship);
|
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));
|
al_clear_to_color(al_map_rgb(0, 0, 0));
|
||||||
ship_draw(&ship);
|
ship_draw(&ship);
|
||||||
if(show_info)
|
if(show_info)
|
||||||
@ -140,7 +147,7 @@ int main() {
|
|||||||
{
|
{
|
||||||
al_draw_multiline_text(font,
|
al_draw_multiline_text(font,
|
||||||
al_map_rgb(0xFF, 0xFF, 0xFF),
|
al_map_rgb(0xFF, 0xFF, 0xFF),
|
||||||
WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2,
|
WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2 - 50,
|
||||||
WINDOW_WIDTH, 10.0f,
|
WINDOW_WIDTH, 10.0f,
|
||||||
ALLEGRO_ALIGN_CENTRE,
|
ALLEGRO_ALIGN_CENTRE,
|
||||||
help);
|
help);
|
||||||
|
Loading…
Reference in New Issue
Block a user