PhonniX Temat założony przez niniejszego użytkownika |
» 2009-02-22 16:52:38 Nie wiem, zrobiłem mniej wiecej to co napisałeś, ale nadal to samo co wcześniej :/ #include <allegro.h>
class Cpostac { public: int x, y; short int kierunek, klatka; };
Cpostac ludek;
volatile long speed = 0; void increment_speed() { speed++; } END_OF_FUNCTION( increment_speed ); LOCK_VARIABLE( speed ); LOCK_FUNCTION( increment_speed );
int mapa_x = 0, mapa_y = 0; int scrollX = 0; int scrollY = 0; BITMAP * teren = NULL; BITMAP * bufor = NULL;
short int map[ 40 ][ 20 ] = { 15, 15, 15, 15, 15, 7, 10, 10, 10, 10, 10, 10, 6, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 4, 9, 10, 10, 10, 8, 3, 5, 15, 0, 2, 2, 2, 1, 15, 2, 1, 15, 15, 15, 15, 7, 10, 10, 10, 6, 15, 15, 15, 7, 10, 10, 10, 6, 15, 10, 6, 15, 15, 15, 15, 4, 9, 10, 10, 6, 15, 15, 15, 4, 3, 3, 3, 5, 15, 10, 12, 2, 1, 15, 15, 15, 7, 10, 8, 5, 15, 15, 15, 15, 15, 15, 15, 15, 15, 10, 10, 10, 6, 15, 15, 15, 4, 3, 5, 15, 15, 15, 15, 15, 15, 15, 0, 2, 2, 10, 10, 10, 6, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 2, 2, 13, 10, 10, 3, 3, 3, 5, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 10, 10, 10, 8, 3, 15, 15, 15, 15, 15, 0, 1, 15, 15, 15, 15, 15, 0, 2, 13, 10, 10, 10, 6, 15, 15, 15, 15, 15, 15, 4, 5, 15, 15, 15, 15, 15, 7, 10, 10, 10, 10, 10, 6, 15, 15, 15, 15, 15, 15, 7, 10, 10, 10, 10, 10, 10, 6, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 4, 9, 10, 10, 10, 8, 3, 5, 15, 0, 2, 2, 2, 1, 15, 2, 1, 15, 15, 15, 15, 7, 10, 10, 10, 6, 15, 15, 15, 7, 10, 10, 10, 6, 15, 10, 6, 15, 15, 15, 15, 4, 9, 10, 10, 6, 15, 15, 15, 4, 3, 3, 3, 5, 15, 10, 12, 2, 1, 15, 15, 15, 7, 10, 8, 5, 15, 15, 15, 15, 15, 15, 15, 15, 15, 10, 10, 10, 6, 15, 15, 15, 4, 3, 5, 15, 15, 15, 15, 15, 15, 15, 0, 2, 2, 10, 10, 10, 6, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 2, 2, 13, 10, 10, 3, 3, 3, 5, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 10, 10, 10, 8, 3, 15, 15, 15, 15, 15, 0, 1, 15, 15, 15, 15, 15, 0, 2, 13, 10, 10, 10, 6, 15, 15, 15, 15, 15, 15, 4, 5, 15, 15, 15, 15, 15, 7, 10, 10, 10, 10, 10, 6, 15, 15, 15, 15, 15, 15, 7, 10, 10, 10, 10, 10, 10, 6, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 4, 9, 10, 10, 10, 8, 3, 5, 15, 0, 2, 2, 2, 1, 15, 2, 1, 15, 15, 15, 15, 7, 10, 10, 10, 6, 15, 15, 15, 7, 10, 10, 10, 6, 15, 10, 6, 15, 15, 15, 15, 4, 9, 10, 10, 6, 15, 15, 15, 4, 3, 3, 3, 5, 15, 10, 12, 2, 1, 15, 15, 15, 7, 10, 8, 5, 15, 15, 15, 15, 15, 15, 15, 15, 15, 10, 10, 10, 6, 15, 15, 15, 4, 3, 5, 15, 15, 15, 15, 15, 15, 15, 0, 2, 2, 10, 10, 10, 6, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 2, 2, 13, 10, 10, 3, 3, 3, 5, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 10, 10, 10, 8, 3, 15, 15, 15, 15, 15, 0, 1, 15, 15, 15, 15, 15, 0, 2, 13, 10, 10, 10, 6, 15, 15, 15, 15, 15, 15, 4, 5, 15, 15, 15, 15, 15, 7, 10, 10, 10, 10, 10, 6, 15, 15, 15, 15, 15, 15, 7, 10, 10, 10, 10, 10, 10, 6, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 4, 9, 10, 10, 10, 8, 3, 5, 15, 0, 2, 2, 2, 1, 15, 2, 1, 15, 15, 15, 15, 7, 10, 10, 10, 6, 15, 15, 15, 7, 10, 10, 10, 6, 15, 10, 6, 15, 15, 15, 15, 4, 9, 10, 10, 6, 15, 15, 15, 4, 3, 3, 3, 5, 15, 10, 12, 2, 1, 15, 15, 15, 7, 10, 8, 5, 15, 15, 15, 15, 15, 15, 15, 15, 15, 10, 10, 10, 6, 15, 15, 15, 4, 3, 5, 15, 15, 15, 15, 15, 15, 15, 0, 2, 2, 10, 10, 10, 6, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 2, 2, 13, 10, 10, 3, 3, 3, 5, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 10, 10, 10, 8, 3, 15, 15, 15, 15, 15, 0, 1, 15, 15, 15, 15, 15, 0, 2, 13, 10, 10, 10, 6, 15, 15, 15, 15, 15, 15, 4, 5, 15, 15, 15, 15, 15, 7, 10, 10, 10, 10, 10, 6, 15 };
void wys_mape() { int startMapX, startMapY; for( startMapX = 0; startMapX < 16; startMapX++ ) { for( startMapY = 0; startMapY < 12; startMapY++ ) { blit( teren, bufor, ( map[ startMapY + mapa_y ][ startMapX + mapa_x ] % 4 ) * 40, ( map[ startMapY + mapa_y ][ startMapX + mapa_x ] / 4 ) * 40, startMapX * 40, startMapY * 40, 40, 40 ); } } };
int main() { allegro_init(); install_keyboard(); set_color_depth( 16 ); set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0 ); install_timer(); install_int_ex( increment_speed, BPS_TO_TIMER( 80 ) ); BITMAP * ludekb = 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; } ludekb = load_bmp( "postac.bmp", default_palette ); teren = load_bmp( "teren.bmp", default_palette ); int frame = 0; ludek.x = 300; ludek.y = 200; ludek.klatka = 0; ludek.kierunek = 0; while( !key[ KEY_ESC ] ) { while( speed > 0 ) { if( key[ KEY_LEFT ] ) { scrollX--; mapa_x--; ludek.kierunek = 1; ludek.x -= 2; frame++; } if( key[ KEY_RIGHT ] ) { scrollX++; mapa_x++; ludek.kierunek = 2; ludek.x += 2; frame++; } if( key[ KEY_UP ] ) { scrollY--; mapa_y--; ludek.kierunek = 3; ludek.y -= 2; frame++; } if( key[ KEY_DOWN ] ) { scrollY++; mapa_y++; ludek.kierunek = 0; ludek.y += 2; frame++; } speed--; int startMapaX = scrollX / 40; int startMapaY = scrollY / 40; if( frame >= 40 ) frame = 0; } clear_to_color( bufor, makecol( 150, 150, 150 ) ); wys_mape(); if( frame >= 0 && frame < 10 ) { ludek.klatka = 0; } else if( frame >= 10 && frame < 20 ) { ludek.klatka = 1; } else if( frame >= 20 && frame < 30 ) { ludek.klatka = 2; } else if( frame >= 30 && frame < 40 ) { ludek.klatka = 3; } masked_blit( ludekb, bufor, ludek.klatka * 32, ludek.kierunek * 48, 300, 200, 32, 48 ); blit( bufor, screen, 0, 0, 0, 0, 640, 480 ); } remove_int( increment_speed ); destroy_bitmap( ludekb ); destroy_bitmap( teren ); destroy_bitmap( bufor ); allegro_exit(); return 0; } END_OF_MAIN();
|