Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <allegro5/allegro.h>
- #include <allegro5/allegro_font.h>
- #include <allegro5/allegro_primitives.h>
- template <class M = const char*, class E = int>
- E log(M msg, E error = 0)
- {
- printf(msg);
- return error;
- }
- int screenW = 640;
- int screenH = 360;
- int scaleWin = 2;
- bool quit = false;
- int xMouse = 0;
- int yMouse = 0;
- ALLEGRO_KEYBOARD_STATE keyState;
- ALLEGRO_MOUSE_STATE mouseState;
- ALLEGRO_FONT *font = nullptr;
- ALLEGRO_DISPLAY *display = nullptr;
- ALLEGRO_BITMAP *buffer = nullptr;
- void update()
- {
- al_get_keyboard_state(&keyState);
- al_get_mouse_state(&mouseState);
- xMouse = mouseState.x / scaleWin;
- yMouse = mouseState.y / scaleWin;
- if (al_key_down(&keyState, ALLEGRO_KEY_ESCAPE))
- quit = true;
- }
- void render()
- {
- al_set_target_bitmap(buffer);
- al_clear_to_color(al_map_rgb(0, 32, 64));
- al_draw_text(font, al_map_rgb(255, 255, 255), screenW/2, screenH-12, ALLEGRO_ALIGN_CENTER, "- PathFinding AStar -");
- al_draw_line(0, yMouse + .5,
- screenW, yMouse + .5,
- al_map_rgba(55, 125, 100, 25), 0);
- al_draw_line(xMouse + .5, 0,
- xMouse + .5, screenH,
- al_map_rgba(55, 125, 100, 25), 0);
- al_set_target_backbuffer(display);
- al_draw_scaled_bitmap(
- buffer,
- 0,0,
- screenW,screenH,
- 0,0,
- screenW*scaleWin, screenH*scaleWin,
- 0);
- al_flip_display();
- }
- int init()
- {
- al_init();
- al_init_font_addon();
- al_init_primitives_addon();
- al_install_keyboard();
- al_install_mouse();
- display = al_create_display(screenW*scaleWin, screenH*scaleWin);
- buffer = al_create_bitmap(screenW, screenH);
- font = al_create_builtin_font();
- return log("init OK !\n");
- }
- int done()
- {
- al_destroy_bitmap(buffer);
- al_destroy_display(display);
- al_destroy_font(font);
- return log("done OK !\n");
- }
- int run()
- {
- if (init())
- quit = true;
- while (!quit)
- {
- update();
- render();
- }
- if (done())
- return log("done ERROR !\n");
- return log("End of Run !\n");
- }
- int main()
- {
- if (run())
- return log("run ERROR !\n");
- return log("END of MAIN !\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement