Guest User

Untitled

a guest
May 21st, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. /***************
  2. Bart Olsthoorn 2008
  3. This code is licenced with the WTFPL.
  4. ****************/
  5.  
  6. #include <allegro.h>
  7. //#include <semaphore.h>
  8. #include <winalleg.h>
  9. #include <stddef.h>
  10. #include <windows.h>
  11. #include <stdio.h>
  12. #include <sstream>
  13.  
  14. #include <stdlib.h>
  15. #include <time.h>
  16.  
  17. // Get Screen size:
  18. const int scrx = GetSystemMetrics(SM_CXSCREEN);
  19. const int scry = GetSystemMetrics(SM_CYSCREEN);
  20. // Music config:
  21. const char *cfg_path;
  22. PACKFILE *packfile;
  23. SAMPLE *musicsample;
  24. // Timer Set:
  25. int sticks=0;
  26. int SecondTick=0;
  27. void changePosImage();
  28. void Seconds_Tick(void)
  29. {
  30. sticks++;
  31. changePosImage();
  32. }
  33. END_OF_FUNCTION(Seconds_Tick);
  34. // Init random seed:
  35. int randomNumx;
  36. int randomNumy;
  37. // Set default mouse positions:
  38. int mx = 0;
  39. int my = 0;
  40. // Global BITMAPS
  41. BITMAP *buffer;
  42. BITMAP *logo;
  43. // Foreground bool set:
  44. static int foreground = TRUE;
  45.  
  46. static void dispsw_callback(void)
  47. {
  48. foreground = FALSE;
  49. }
  50. // Announce Functions:
  51. void init();
  52. void deinit();
  53.  
  54. int main() {
  55. init();
  56. srand (time(NULL)); // Random Seed
  57. mx = mouse_x; // Mouse Pos
  58. my = mouse_y; // Mouse Pos
  59. changePosImage(); // Show image on startup, avoid boring black screens
  60.  
  61. while (!keypressed() && foreground && (!mouse_b) && (mouse_x == mx) && (mouse_y == my)) {
  62.  
  63. //while (!key[KEY_ESC]) { //DEBUG MODE
  64. // Show buffer:
  65. blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
  66. //clear_
  67. rest(1);
  68. }
  69.  
  70. deinit();
  71. return 0;
  72. }
  73. END_OF_MAIN()
  74.  
  75. void init() {
  76. int depth, res;
  77. allegro_init();
  78.  
  79. depth = desktop_color_depth();
  80. if (depth == 0) depth = 32;
  81. set_color_depth(depth);
  82. res = set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, scrx, scry, 0, 0);
  83. if (res != 0) {
  84. allegro_message(allegro_error);
  85. exit(-1);
  86. }
  87.  
  88. SetPriorityClass(GetCurrentProcess() ,IDLE_PRIORITY_CLASS); // IDLE_PRIORITY_CLASS
  89.  
  90. set_display_switch_mode(SWITCH_BACKAMNESIA); /* not SWITCH_AMNESIA */
  91. set_display_switch_callback(SWITCH_OUT, dispsw_callback);
  92.  
  93. install_timer();
  94. install_keyboard();
  95. install_mouse();
  96. install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, cfg_path);
  97. /* add other initializations here */
  98. buffer = create_bitmap(scrx, scry); // Create buffer
  99. logo = load_bitmap("logo.bmp", NULL);
  100. if (logo == NULL) {
  101. set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
  102. allegro_message("Kon Logo.bmp niet vinden");
  103. allegro_exit();
  104. }
  105. install_timer();
  106.  
  107. LOCK_VARIABLE(sticks);
  108. LOCK_FUNCTION(Seconds_Tick);
  109. install_int_ex(&Seconds_Tick, SECS_TO_TIMER(5));
  110. }
  111.  
  112. void deinit() {
  113. clear_bitmap(logo);
  114. destroy_bitmap(logo);
  115. clear_bitmap(buffer);
  116. destroy_bitmap(buffer);
  117. clear_keybuf();
  118. allegro_exit();
  119. /* add other deinitializations here */
  120. }
  121.  
  122. void changePosImage() {
  123. randomNumx = rand() % (SCREEN_W-(logo->w));
  124. randomNumy = rand() % (SCREEN_H-(logo->h));
  125. clear_bitmap(buffer);
  126. blit(logo, buffer, 0, 0, randomNumx, randomNumy, logo->w, logo->h);
  127. }
Add Comment
Please, Sign In to add comment