Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

John Edgar Congote Calle http://jcongote.blogspot.com

« Newer Snippets
Older Snippets »
Showing 21-22 of 22 total

Manejo de mouse en Allegro

Manejo de mouse en Allegro

   1  
   2  #include <allegro.h>
   3  
   4  void init();
   5  void deinit();
   6  
   7  int main() {
   8  	init();
   9  
  10  
  11      int x,y;
  12      show_mouse(screen);
  13  	while (!key[KEY_ESC]) {
  14  		/* put your code here */
  15    
  16         for (x=10;x<600;x+=50){
  17             for (y=10;y<420;y+=60){        
  18                 if (mouse_x > x && mouse_x < x+40 && mouse_y >y && mouse_y < y+50){
  19                    circlefill(screen, x+20,y+25,20,makecol(128,y%255,0));    
  20                 } else {
  21                    rectfill(screen, x,y,x+40,y+50,makecol(0,255,0));           
  22                 }
  23             }    
  24         }
  25  	}
  26  
  27  	deinit();
  28  	return 0;
  29  }
  30  END_OF_MAIN();
  31   
  32  void init() {
  33  	int depth, res;
  34  	allegro_init();
  35  	depth = desktop_color_depth();
  36  	if (depth == 0) depth = 32;
  37  	set_color_depth(depth);
  38  	res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
  39  	if (res != 0) {
  40  		allegro_message(allegro_error);
  41  		exit(-1);
  42  	}
  43  
  44  	install_timer();
  45  	install_keyboard();
  46  	install_mouse();
  47  	/* add other initializations here */
  48  }
  49  
  50  void deinit() {
  51  	clear_keybuf();
  52  	/* add other deinitializations here */
  53  }
  54  

Animacion en allegro

Codigo que muestra una pequena animacion en Allegro

   1  
   2  
   3  #include <allegro.h>
   4  
   5  void init();
   6  void deinit();
   7  
   8  int piramide(int a, int b, int c){
   9      line(screen,a+(c/2),b,a,b+c,makecol(0,128,0));    
  10      line(screen,a,b+c,a+c,b+c,makecol(0,128,0));
  11      line(screen,a+c,b+c,a+(c/2),b,makecol(0,128,0));    
  12  }
  13  
  14  int main() {
  15  	init();
  16  	int a,b,inca,incb;
  17  	a=0,b=0;
  18  	inca=1, incb=1;
  19  	while (!key[KEY_ESC]) {
  20            clear_to_color(screen,0);
  21              circlefill(screen,a,b,50,makecol(128,0,128));
  22              a=a+inca;
  23              b=b+incb;
  24              
  25              if (a==200){
  26                 inca=-1;            
  27              }
  28          rest(10);
  29  	}
  30  
  31  	deinit();
  32  	return 0;
  33  }
  34  END_OF_MAIN();
  35  
  36  void init() {
  37  	int depth, res;
  38  	allegro_init();
  39  	depth = desktop_color_depth();
  40  	if (depth == 0) depth = 32;
  41  	set_color_depth(depth);
  42  	res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
  43  	if (res != 0) {
  44  		allegro_message(allegro_error);
  45  		exit(-1);
  46  	}
  47  
  48  	install_timer();
  49  	install_keyboard();
  50  	install_mouse();
  51  	/* add other initializations here */
  52  }
  53  
  54  void deinit() {
  55  	clear_keybuf();
  56  	/* add other deinitializations here */
  57  }
« Newer Snippets
Older Snippets »
Showing 21-22 of 22 total