Guest User

Untitled

a guest
Nov 30th, 2017
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.88 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5. #include "allegro5/allegro.h"
  6. #include "allegro5/allegro_font.h"
  7. #include "allegro5/allegro_ttf.h"
  8. #include "allegro5/allegro_image.h"
  9. #include "allegro5/allegro_primitives.h"
  10.  
  11.  
  12.  
  13. void DrawLight(int x , int y , int r);
  14. void DrawLight(int x , int y , int r) {
  15.    int rad = r;
  16.    while (rad > 0) {
  17.       int l = (r - rad)*255/r;
  18.       al_draw_filled_circle(x , y , rad , al_map_rgba(0,0,0,l));
  19.       rad -= 15;
  20.    }
  21. }
  22.  
  23. int main(int argc , char** argv) {
  24.    
  25.    (void)argc;
  26.    (void)argv;
  27.    
  28.    
  29.    if (!al_init()) {
  30.       return 1;
  31.    }
  32.    if (!al_init_image_addon()) {return 2;}
  33.    if (!al_init_font_addon()) {return 3;}
  34.    if (!al_init_ttf_addon()) {return 4;}
  35.    if (!al_init_primitives_addon()) {return 5;}
  36.    
  37.    al_install_keyboard();
  38.    al_install_mouse();
  39.    
  40.    al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_OPENGL);
  41.    ALLEGRO_DISPLAY* d = al_create_display(800,600);
  42.    
  43.    ALLEGRO_TIMER* t = al_create_timer(1.0/60.0);
  44.    
  45.    ALLEGRO_EVENT_QUEUE* q = al_create_event_queue();
  46.    
  47.    al_register_event_source(q , al_get_timer_event_source(t));
  48.    al_register_event_source(q , al_get_display_event_source(d));
  49.    al_register_event_source(q , al_get_keyboard_event_source());
  50.    al_register_event_source(q , al_get_mouse_event_source());
  51.    
  52.    ALLEGRO_BITMAP* lmap = al_create_bitmap(800,600);
  53.    ALLEGRO_BITMAP* bg = al_load_bitmap("BG.png");
  54.    
  55.    if (!bg || !lmap) {return 7;}
  56.    
  57.    int mx = 0;
  58.    int my = 0;
  59.    
  60.    bool run = true;
  61.    bool draw = true;
  62.    while (run) {
  63.       if (draw) {
  64.          /// draw our light map
  65.          al_set_target_bitmap(lmap);
  66.          
  67.          al_clear_to_color(al_map_rgba(0,0,0,0));
  68.          
  69.          al_set_separate_blender(ALLEGRO_ADD , ALLEGRO_ZERO , ALLEGRO_ZERO , ALLEGRO_ADD , ALLEGRO_ALPHA , ALLEGRO_ALPHA);
  70.          DrawLight(0 , 0 , 100);
  71.          DrawLight(mx , my , 100);
  72.            
  73.          al_set_target_backbuffer(d);
  74.          al_clear_to_color(al_map_rgb(0,0,0));
  75.          al_set_blender(ALLEGRO_ADD , ALLEGRO_ONE , ALLEGRO_ZERO);
  76.          al_draw_bitmap(bg , 0 , 0 , 0);
  77.          al_set_blender(ALLEGRO_ADD , ALLEGRO_ZERO , ALLEGRO_INVERSE_ALPHA);
  78.          al_draw_bitmap(lmap , 0 , 0 , 0);
  79.          al_flip_display();
  80.          draw = false;  
  81.       }
  82.      
  83.       do {
  84.          ALLEGRO_EVENT ev;
  85.          al_wait_for_event(q , &ev);
  86.          if (ev.type == ALLEGRO_EVENT_MOUSE_AXES) {
  87.             mx = ev.mouse.x;
  88.             my = ev.mouse.y;
  89.             draw = true;
  90.          }
  91.          if (ev.type == ALLEGRO_EVENT_KEY_DOWN && ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
  92.             run = false;
  93.          }
  94.          if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
  95.             run = false;
  96.          }
  97.          if (ev.type == ALLEGRO_EVENT_TIMER) {
  98.             draw = true;
  99.          }
  100.       } while (!al_is_event_queue_empty(q));
  101.          
  102.    }
  103.    return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment