Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <allegro.h>
- volatile long speed = 0;
- void increment_speed()
- {
- speed++;
- }
- END_OF_FUNCTION( increment_speed );
- LOCK_VARIABLE( speed );
- LOCK_FUNCTION( increment_speed );
- int main()
- {
- allegro_init();
- install_keyboard();
- set_color_depth( 32 );
- set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0 );
- install_timer();
- install_int_ex( increment_speed, BPS_TO_TIMER( 80 ) );
- BITMAP * bufor = NULL;
- BITMAP * ludek0 = NULL;
- BITMAP * ludek1 = NULL;
- BITMAP * ludek2 = NULL;
- BITMAP * ludek3 = NULL;
- BITMAP * strzal = NULL;
- bufor = create_bitmap( 640, 480 );
- if( !bufor )
- {
- set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 );
- allegro_message( "Nie mogę utworzyć bufora !" );
- allegro_exit();
- return 0;
- }
- ludek0 = load_bmp( "ludek0.bmp", default_palette );
- ludek1 = load_bmp( "ludek1.bmp", default_palette );
- ludek2 = load_bmp( "ludek2.bmp", default_palette );
- ludek3 = load_bmp( "ludek3.bmp", default_palette );
- int ludek_x = 100, ludek_y = 100;
- int frame = 0;
- while( !key[ KEY_ESC ] )
- {
- while( speed > 0 )
- {
- if( key[ KEY_LEFT ] ) ludek_x--;
- if( key[ KEY_RIGHT ] ) ludek_x++;
- if( key[ KEY_UP ] ) ludek_y--;
- if( key[ KEY_DOWN ] ) ludek_y++;
- speed--;
- frame++;
- if( frame > 80 ) frame = 0;
- }
- clear_to_color( bufor, makecol( 150, 150, 150 ) );
- if( frame < 20 ) { draw_sprite( bufor, ludek0, ludek_x, ludek_y ); }
- else if( frame >= 20 && frame < 40 ) { draw_sprite( bufor, ludek1, ludek_x, ludek_y ); }
- else if( frame >= 40 && frame < 60 ) { draw_sprite( bufor, ludek2, ludek_x, ludek_y ); }
- else if( frame >= 60 && frame < 80 ) { draw_sprite( bufor, ludek3, ludek_x, ludek_y ); }
- blit( bufor, screen, 0, 0, 0, 0, 640, 480 );
- }
- int strzal_x = 100, strzal_y = 100;
- strzal = load_bmp( "strzal.bmp", default_palette );
- while( !key[ KEY_ESC ] )
- {
- if ( key[ KEY_W ] ) strzal_x++;
- if ( key[ KEY_S ] ) strzal_x--;
- if ( key[ KEY_A ] ) strzal_y++;
- if ( key[ KEY_D ] ) strzal_y--;
- blit( bufor, screen, 0, 0, 0, 0, 640, 480 );
- }
- remove_int( increment_speed );
- destroy_bitmap( ludek0 );
- destroy_bitmap( ludek1 );
- destroy_bitmap( ludek2 );
- destroy_bitmap( ludek3 );
- destroy_bitmap( bufor );
- destroy_bitmap( strzal );
- allegro_exit();
- return 0;
- }
- END_OF_MAIN();
Advertisement
Add Comment
Please, Sign In to add comment