trojanxem

Untitled

Apr 7th, 2012
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.49 KB | None | 0 0
  1. #include <allegro.h>
  2.  
  3. volatile long speed = 0;
  4. void increment_speed()
  5. {
  6.     speed++;
  7. }
  8. END_OF_FUNCTION( increment_speed );
  9. LOCK_VARIABLE( speed );
  10. LOCK_FUNCTION( increment_speed );
  11. int main()
  12. {
  13.     allegro_init();
  14.     install_keyboard();
  15.     set_color_depth( 32 );
  16.     set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0 );
  17.     install_timer();
  18.     install_int_ex( increment_speed, BPS_TO_TIMER( 80 ) );
  19.    
  20. BITMAP * bufor = NULL;
  21. BITMAP * ludek0 = NULL;
  22. BITMAP * ludek1 = NULL;
  23. BITMAP * ludek2 = NULL;
  24. BITMAP * ludek3 = NULL;
  25. BITMAP * strzal = NULL;
  26.  
  27. bufor = create_bitmap( 640, 480 );
  28. if( !bufor )
  29. {
  30.     set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 );
  31.     allegro_message( "Nie mogę utworzyć bufora !" );
  32.     allegro_exit();
  33.     return 0;
  34. }
  35.  
  36. ludek0 = load_bmp( "ludek0.bmp", default_palette );
  37. ludek1 = load_bmp( "ludek1.bmp", default_palette );
  38. ludek2 = load_bmp( "ludek2.bmp", default_palette );
  39.  
  40. ludek3 = load_bmp( "ludek3.bmp", default_palette );
  41.  
  42.  
  43. int ludek_x = 100, ludek_y = 100;
  44.  
  45. int frame = 0;
  46.  
  47.  
  48.  
  49. while( !key[ KEY_ESC ] )
  50. {
  51.     while( speed > 0 )
  52.     {
  53.        
  54.         if( key[ KEY_LEFT ] ) ludek_x--;
  55.        
  56.         if( key[ KEY_RIGHT ] ) ludek_x++;
  57.        
  58.         if( key[ KEY_UP ] ) ludek_y--;
  59.        
  60.         if( key[ KEY_DOWN ] ) ludek_y++;
  61.        
  62.        
  63.        
  64.         speed--;
  65.        
  66.         frame++;
  67.         if( frame > 80 ) frame = 0;
  68.        
  69.     }
  70.    
  71.     clear_to_color( bufor, makecol( 150, 150, 150 ) );
  72.  
  73. if( frame < 20 ) { draw_sprite( bufor, ludek0, ludek_x, ludek_y ); }
  74. else if( frame >= 20 && frame < 40 ) { draw_sprite( bufor, ludek1, ludek_x, ludek_y ); }
  75. else if( frame >= 40 && frame < 60 ) { draw_sprite( bufor, ludek2, ludek_x, ludek_y ); }
  76. else if( frame >= 60 && frame < 80 ) { draw_sprite( bufor, ludek3, ludek_x, ludek_y ); }
  77.  
  78. blit( bufor, screen, 0, 0, 0, 0, 640, 480 );
  79. }
  80. int strzal_x = 100, strzal_y = 100;
  81. strzal = load_bmp( "strzal.bmp", default_palette );
  82. while( !key[ KEY_ESC ] )
  83. {
  84.  
  85.        if ( key[ KEY_W ] ) strzal_x++;
  86.        
  87.         if ( key[ KEY_S ] ) strzal_x--;
  88.        
  89.         if ( key[ KEY_A ] ) strzal_y++;
  90.        
  91.         if ( key[ KEY_D ] ) strzal_y--;
  92.        
  93.         blit( bufor, screen, 0, 0, 0, 0, 640, 480 );
  94.         }
  95.        
  96.  
  97. remove_int( increment_speed );
  98. destroy_bitmap( ludek0 );
  99. destroy_bitmap( ludek1 );
  100. destroy_bitmap( ludek2 );
  101. destroy_bitmap( ludek3 );
  102. destroy_bitmap( bufor );
  103. destroy_bitmap( strzal );
  104. allegro_exit();
  105. return 0;
  106. }
  107. END_OF_MAIN();
Advertisement
Add Comment
Please, Sign In to add comment