36int main(
int argc,
char* argv[]) {
48 n_abort(
"Could not init Allegro.\n");
50 if (!al_install_audio()) {
51 n_abort(
"Unable to initialize audio addon\n");
53 if (!al_init_acodec_addon()) {
54 n_abort(
"Unable to initialize acoded addon\n");
56 if (!al_init_image_addon()) {
57 n_abort(
"Unable to initialize image addon\n");
59 if (!al_init_primitives_addon()) {
60 n_abort(
"Unable to initialize primitives addon\n");
62 if (!al_init_font_addon()) {
63 n_abort(
"Unable to initialize font addon\n");
65 if (!al_init_ttf_addon()) {
66 n_abort(
"Unable to initialize ttf_font addon\n");
68 if (!al_install_keyboard()) {
69 n_abort(
"Unable to initialize keyboard handler\n");
71 if (!al_install_mouse()) {
72 n_abort(
"Unable to initialize mouse handler\n");
74 ALLEGRO_EVENT_QUEUE* event_queue = NULL;
76 event_queue = al_create_event_queue();
78 fprintf(stderr,
"failed to create event_queue!\n");
83 char ver_str[128] =
"";
84 while ((
getoptret = getopt(argc, argv,
"hvV:L:")) != EOF) {
87 n_log(
LOG_NOTICE,
"\n %s -h help -v version -V DEBUGLEVEL (NOLOG,VERBOSE,NOTICE,ERROR,DEBUG)", argv[0]);
90 sprintf(ver_str,
"%s %s", __DATE__, __TIME__);
94 if (!strncmp(
"NOTICE", optarg, 6)) {
97 if (!strncmp(
"VERBOSE", optarg, 7)) {
100 if (!strncmp(
"ERROR", optarg, 5)) {
103 if (!strncmp(
"DEBUG", optarg, 5)) {
122 n_log(
LOG_ERR,
"\nPlease specify a log level after -V. \nAvailable values: NOLOG,VERBOSE,NOTICE,ERROR,DEBUG");
132 n_log(
LOG_ERR,
"\n %s -h help -v version -V DEBUGLEVEL (NOLOG,VERBOSE,NOTICE,ERROR,DEBUG) -L logfile", argv[0]);
140 al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_WINDOWED);
143 n_abort(
"Unable to create display\n");
145 al_set_window_title(
display, argv[0]);
147 al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);
162 int key[7] = {
false,
false,
false,
false,
false,
false,
false};
164 al_register_event_source(event_queue, al_get_display_event_source(
display));
168 al_register_event_source(event_queue, al_get_timer_event_source(
fps_timer));
169 al_register_event_source(event_queue, al_get_timer_event_source(
logic_timer));
171 al_register_event_source(event_queue, al_get_keyboard_event_source());
172 al_register_event_source(event_queue, al_get_mouse_event_source());
174 ALLEGRO_BITMAP* scrbuf = al_create_bitmap(
WIDTH,
HEIGHT);
180 int mx = 0, my = 0, mouse_b1 = 0, mouse_b2 = 0;
181 int do_draw = 0, do_logic = 0;
183 al_clear_keyboard_state(NULL);
184 al_flush_event_queue(event_queue);
189 al_wait_for_event(event_queue, &ev);
191 if (ev.type == ALLEGRO_EVENT_KEY_DOWN) {
192 switch (ev.keyboard.keycode) {
196 case ALLEGRO_KEY_DOWN:
199 case ALLEGRO_KEY_LEFT:
202 case ALLEGRO_KEY_RIGHT:
205 case ALLEGRO_KEY_ESCAPE:
208 case ALLEGRO_KEY_SPACE:
211 case ALLEGRO_KEY_LCTRL:
212 case ALLEGRO_KEY_RCTRL:
217 }
else if (ev.type == ALLEGRO_EVENT_KEY_UP) {
218 switch (ev.keyboard.keycode) {
222 case ALLEGRO_KEY_DOWN:
225 case ALLEGRO_KEY_LEFT:
228 case ALLEGRO_KEY_RIGHT:
231 case ALLEGRO_KEY_ESCAPE:
234 case ALLEGRO_KEY_SPACE:
237 case ALLEGRO_KEY_LCTRL:
238 case ALLEGRO_KEY_RCTRL:
243 }
else if (ev.type == ALLEGRO_EVENT_TIMER) {
244 if (al_get_timer_event_source(
fps_timer) == ev.any.source) {
246 }
else if (al_get_timer_event_source(
logic_timer) == ev.any.source) {
249 }
else if (ev.type == ALLEGRO_EVENT_MOUSE_AXES) {
252 }
else if (ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) {
253 if (ev.mouse.button == 1)
255 if (ev.mouse.button == 2)
257 }
else if (ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
258 if (ev.mouse.button == 1)
260 if (ev.mouse.button == 2)
262 }
else if (ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_IN || ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT) {
263 al_clear_keyboard_state(
display);
264 al_flush_event_queue(event_queue);
269 }
while (!al_is_event_queue_empty(event_queue));
273 int mouse_button = -1;
281 if (mouse_button == 1) {
284 for (
int it = 0; it < 100; it++) {
293 al_map_rgba(55 + rand() % 200, 55 + rand() % 200, 55 + rand() % 200, 10 + rand() % 245), tmp_part);
300 al_acknowledge_resize(
display);
301 int w = al_get_display_width(
display);
302 int h = al_get_display_height(
display);
304 al_set_target_bitmap(scrbuf);
305 al_clear_to_color(al_map_rgba(0, 0, 0, 255));
308 al_set_target_bitmap(al_get_backbuffer(
display));
310 al_clear_to_color(al_map_rgba(0, 0, 0, 255));
311 al_draw_bitmap(scrbuf, 0, 0, 0);
314 al_draw_line(mx - 5, my, mx + 5, my, al_map_rgb(255, 0, 0), 1);
315 al_draw_line(mx, my + 5, mx, my - 5, al_map_rgb(255, 0, 0), 1);
321 }
while (!
key[KEY_ESC] && !
DONE);
327 al_uninstall_system();
PARTICLE_SYSTEM * particle_system_effects
int add_particle(PARTICLE_SYSTEM *psys, int spr, int mode, int lifetime, int size, ALLEGRO_COLOR color, PHYSICS object)
add a particle to a particle system