Added help information.
This commit is contained in:
		| @@ -123,6 +123,9 @@ void handle_event() { | |||||||
| 				show_help = !show_help; | 				show_help = !show_help; | ||||||
| 			else if(evnt.keyboard.keycode == ALLEGRO_KEY_I) | 			else if(evnt.keyboard.keycode == ALLEGRO_KEY_I) | ||||||
| 				show_info = !show_info; | 				show_info = !show_info; | ||||||
|  | 			else if(evnt.keyboard.keycode == ALLEGRO_KEY_Q || | ||||||
|  | 					evnt.keyboard.keycode == ALLEGRO_KEY_ESCAPE) | ||||||
|  | 				run = 0; | ||||||
| 			else | 			else | ||||||
| 				set_key(evnt.keyboard.keycode, 1); | 				set_key(evnt.keyboard.keycode, 1); | ||||||
| 			break; | 			break; | ||||||
|   | |||||||
| @@ -25,6 +25,19 @@ | |||||||
| #ifndef FPS | #ifndef FPS | ||||||
| #	define FPS 60.0f | #	define FPS 60.0f | ||||||
| #endif | #endif | ||||||
|  | #ifndef ACCEL | ||||||
|  | #	define ACCEL 0.5f | ||||||
|  | #endif | ||||||
|  | #ifndef TURN_ACCEL | ||||||
|  | #	define TURN_ACCEL (M_PI / FPS)  // turn at pi radians / sec | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | #ifndef WINDOW_WIDTH | ||||||
|  | #	define WINDOW_WIDTH 800 | ||||||
|  | #endif | ||||||
|  | #ifndef WINDOW_HEIGHT | ||||||
|  | #	define WINDOW_HEIGHT 600 | ||||||
|  | #endif | ||||||
|  |  | ||||||
| #include <allegro5/allegro.h> | #include <allegro5/allegro.h> | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										30
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								src/main.c
									
									
									
									
									
								
							| @@ -28,6 +28,14 @@ int show_info; | |||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <allegro5/allegro.h> | #include <allegro5/allegro.h> | ||||||
| #include <allegro5/allegro_primitives.h> | #include <allegro5/allegro_primitives.h> | ||||||
|  | #include <allegro5/allegro_font.h> | ||||||
|  |  | ||||||
|  | const char *help = | ||||||
|  | 	"HELP:\n" | ||||||
|  | 	"LEFT/RIGHT - turn the ship\n" | ||||||
|  | 	"UP/DOWN - accelerate/decelerate\n" | ||||||
|  | 	"H - show/hide this help information\n" | ||||||
|  | 	"Q/ESC - quit"; | ||||||
|  |  | ||||||
| int main() { | int main() { | ||||||
| 	printf("SpaceShipSim v%s\n", VERSION); | 	printf("SpaceShipSim v%s\n", VERSION); | ||||||
| @@ -49,7 +57,13 @@ int main() { | |||||||
| 	puts("Initialized primitives addon."); | 	puts("Initialized primitives addon."); | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| 	ALLEGRO_DISPLAY *display = al_create_display(800, 600); | 	if(!al_init_font_addon()) | ||||||
|  | 	{ | ||||||
|  | 		fprintf(stderr, "alleg5: failed to initialize font addon.\n"); | ||||||
|  | 		return 1; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	ALLEGRO_DISPLAY *display = al_create_display(WINDOW_WIDTH, WINDOW_HEIGHT); | ||||||
| 	if(!display) | 	if(!display) | ||||||
| 	{ | 	{ | ||||||
| 		fprintf(stderr, "alleg5: failed to initialize display.\n"); | 		fprintf(stderr, "alleg5: failed to initialize display.\n"); | ||||||
| @@ -70,6 +84,8 @@ int main() { | |||||||
| 	struct ship ship; | 	struct ship ship; | ||||||
| 	ship_init(&ship, 400, 300); | 	ship_init(&ship, 400, 300); | ||||||
|  |  | ||||||
|  | 	ALLEGRO_FONT *font = al_create_builtin_font(); | ||||||
|  |  | ||||||
| 	// begin running the simulation | 	// begin running the simulation | ||||||
| 	run = 1; | 	run = 1; | ||||||
| 	redraw = 1; | 	redraw = 1; | ||||||
| @@ -97,17 +113,27 @@ int main() { | |||||||
|  |  | ||||||
| 			if(show_help) | 			if(show_help) | ||||||
| 			{ | 			{ | ||||||
| 				// TODO: draw help information | 				al_draw_multiline_text(font, | ||||||
|  | 						al_map_rgb(0xFF, 0xFF, 0xFF), | ||||||
|  | 						WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, | ||||||
|  | 						WINDOW_WIDTH, 10.0f, | ||||||
|  | 						ALLEGRO_ALIGN_CENTRE, | ||||||
|  | 						help); | ||||||
| 			} | 			} | ||||||
| 			al_flip_display(); | 			al_flip_display(); | ||||||
| 			redraw = 0; | 			redraw = 0; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	al_destroy_font(font); | ||||||
| 	evnt_mngr_deinit(); | 	evnt_mngr_deinit(); | ||||||
| 	al_destroy_display(display); | 	al_destroy_display(display); | ||||||
| #ifdef DEBUG | #ifdef DEBUG | ||||||
| 	puts("Destroyed display."); | 	puts("Destroyed display."); | ||||||
|  | #endif | ||||||
|  | 	al_shutdown_font_addon(); | ||||||
|  | #ifdef DEBUG | ||||||
|  | 	puts("Shutdown font addon."); | ||||||
| #endif | #endif | ||||||
| 	al_shutdown_primitives_addon(); | 	al_shutdown_primitives_addon(); | ||||||
| #ifdef DEBUG | #ifdef DEBUG | ||||||
|   | |||||||
| @@ -29,8 +29,6 @@ | |||||||
| #	define M_PI 3.14159265f | #	define M_PI 3.14159265f | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #define ACCEL 0.5f |  | ||||||
| #define TURN_ACCEL (M_PI / FPS)  // turn at pi radians / sec |  | ||||||
| #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) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user