Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // gcc -Wall 4.c -o 4 $(pkg-config --libs allegro-5.0 allegro_image-5.0 allegro_primitives-5.0)
- #define ALLEGRO_STATICLINK
- #include <allegro5/allegro.h>
- #include <allegro5/allegro_primitives.h>
- int main() {
- int win_x = 400;
- int win_y = 400;
- bool user_exit = false;
- int pos_x = win_x / 2;
- int pos_y = win_y / 2;
- ALLEGRO_DISPLAY *display;
- ALLEGRO_EVENT_QUEUE *event_queue = NULL;
- if(!al_init()) {
- return -1;
- }
- display = al_create_display(win_x, win_y);
- if(!display) {
- return -1;
- }
- al_init_primitives_addon();
- al_install_keyboard();
- event_queue = al_create_event_queue();
- al_register_event_source(event_queue, al_get_keyboard_event_source());
- while(!user_exit) {
- ALLEGRO_EVENT ev;
- al_wait_for_event(event_queue, &ev);
- if(ev.type == ALLEGRO_EVENT_KEY_DOWN) {
- switch(ev.keyboard.keycode) {
- case ALLEGRO_KEY_UP:
- pos_y -= 20;
- break;
- case ALLEGRO_KEY_DOWN:
- pos_y += 20;
- break;
- case ALLEGRO_KEY_RIGHT:
- pos_x += 20;
- break;
- case ALLEGRO_KEY_LEFT:
- pos_x -= 20;
- }
- } else if(ev.type == ALLEGRO_EVENT_KEY_UP) {
- if(ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
- user_exit = true;
- }
- }
- al_draw_filled_rectangle(pos_x, pos_y, pos_x + 50, pos_y + 50, al_map_rgb(0, 0, 255));
- al_flip_display();
- al_clear_to_color(al_map_rgb(0, 0, 0));
- al_destroy_event_queue(event_queue);
- al_uninstall_keyboard();
- al_destroy_display(display);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement