CellTyran Temat założony przez niniejszego użytkownika |
[C++, Allegro] Problem ze scrollowaniem mapy. » 2015-03-16 19:40:39 Witajcie! Mój problem polega na tym, że mapa nie scrolluje się w górę i w dół. Szukałem odpowiedzi prawie wszędzie lecz nigdzie jej nie znalazłem. Może wy mi pomożecie ;) Kodzik: #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( 16 ); set_gfx_mode( GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0 ); install_timer(); install_int_ex( increment_speed, BPS_TO_TIMER( 100 ) ); clear_to_color( screen, makecol( 128, 128, 128 ) ); BITMAP * kafel01 = NULL; BITMAP * kafel02 = NULL; BITMAP * bufor = NULL; BITMAP * ludek = NULL; bufor = create_bitmap( 640, 480 ); kafel01 = load_bmp( "kafel1.bmp", default_palette ); kafel02 = load_bmp( "kafel2.bmp", default_palette ); ludek = load_bmp( "ludek.bmp", default_palette ); if(( !kafel01 ) ||( !kafel02 ) ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "Popsules jakis obrazek/bufora" ); allegro_exit(); return 0; } if( !ludek ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "Nie mo¿na za³adowaæ obrazka : ludek !" ); allegro_exit(); return 0; } int mapa[ 20 ][ 20 ] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 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( speed > 0 ) { for( int x = 0; x < 20; x++ ) { for( int y = 0; y < 20; y++ ) { if( mapa[ x ][ y ] == 0 ) blit( kafel01, bufor, 0, 0, map_x + x * szerokosc_kafla, y * wysokosc_kafla, szerokosc_kafla, wysokosc_kafla ); if( mapa[ x ][ y ] == 1 ) blit( kafel02, bufor, 0, 0, map_x + x * szerokosc_kafla, y * wysokosc_kafla, szerokosc_kafla, wysokosc_kafla ); } } if( key[ KEY_RIGHT ] ) map_x--; if( key[ KEY_LEFT ] ) map_x++; if( key[ KEY_DOWN ] ) map_y++; if( key[ KEY_UP ] ) map_y--; speed--; masked_blit( ludek, bufor, 0, 0, ludek_x, ludek_y, ludek->w, ludek->h ); blit( bufor, screen, 0, 0, 0, 0, 640, 480 ); clear_to_color( bufor, makecol( 150, 150, 150 ) ); } } remove_int( increment_speed ); destroy_bitmap( ludek ); destroy_bitmap( kafel01 ); destroy_bitmap( kafel02 ); destroy_bitmap( bufor ); allegro_exit(); return 0; } END_OF_MAIN(); |