Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Allegro 4.2.2 Syntax*/
  2. // https://phoxis.org/2009/02/13/allegro-422/
  3. // Dostêp: 2017-10-29
  4. #include <stdio.h>
  5. #include <allegro.h>
  6.  
  7. #define RED makecol(255,0,0)
  8. #define GREEN makecol(0,255,0)
  9. #define BLUE makecol(0,0,255)
  10. #define BLACK makecol(0,0,0)
  11. #define WHITE makecol(255,255,255)
  12. #define RADIUS 10
  13. #define MOVE_DISTANCE 20
  14.  
  15. int main(void)
  16. {
  17.  
  18. allegro_init();
  19. install_keyboard();
  20. install_mouse();
  21. install_timer();
  22.  
  23. allegro_message("This is the first allegro program (Press OK)");
  24. set_color_depth(8);
  25. if(set_gfx_mode(GFX_AUTODETECT_WINDOWED,800,600,0,0))
  26. {
  27. allegro_message(allegro_error);
  28. exit(0);
  29. }
  30.  
  31. int width = SCREEN_W/2;
  32. int heigth = SCREEN_H/2;
  33.  
  34. textprintf(screen,font,10,10,WHITE,"Screen Resolution %dx%d",SCREEN_W,SCREEN_H);
  35. rect(screen,20,20,300,130,GREEN);
  36. putpixel(screen,SCREEN_W/2,SCREEN_H/2,RED);
  37. line(screen,300,300,200,200,GREEN);
  38. triangle(screen,500,500,500,550,300,550,BLUE);
  39.  
  40. show_mouse(screen);
  41.  
  42. while(!key[KEY_ESC])
  43. {
  44. textprintf(screen,font,30,30,RED,"Mouse Pos x:y=%3d:%3d",mouse_x,mouse_y);
  45. textprintf(screen,font,30,50,BLUE,"Mouse Scroll Pos: %3d",mouse_z);
  46. textprintf(screen,font,30,70,GREEN,"Mouse Left Button Pressed:%3s",((mouse_b&1)?"Yes":"No"));
  47. textprintf(screen,font,30,90,GREEN,"Mouse Right Button Pressed:%3s",((mouse_b&2)?"Yes":"No"));
  48. textprintf(screen,font,30,110,GREEN,"Mouse Middle Button Pressed:%3s",((mouse_b&4)?"Yes":"No"));
  49. textprintf(screen,font,30,200,GREEN,"Raw Mouse :%d",mouse_b);
  50.  
  51. circle(screen,width,heigth,RADIUS,WHITE);
  52.  
  53. if (mouse_x > width) {
  54. width += RADIUS;
  55. } else if (mouse_x < width) {
  56. width -= RADIUS;
  57.  
  58. if (mouse_y > heigth) {
  59. heigth += RADIUS:
  60. } else if (mouse_y < heigth) {
  61. heigth -= RADIUS;
  62. }
  63.  
  64. if (width < 0) {
  65. width = RADIUS;
  66. } else if (width > SCREEN_W) {
  67. width = SCREEN_W - RADIUS;
  68. }
  69.  
  70. if (heigth < 0) {
  71. heigth = RADIUS:
  72. } else if (heigth > SCREEN_H) {
  73. heigth = SCREEN_H - RADIUS;
  74. }
  75.  
  76. rest(5);
  77. }
  78.  
  79. allegro_exit();
  80. return 0;
  81. }
  82. END_OF_MAIN();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement