wiktor16s Temat założony przez niniejszego użytkownika |
Pomoc w złączeniu menu i gry » 2012-04-04 20:12:59 Dobra. ;D oto kolejny mój problem: zrobiłem sobie takie oto proste menu: #include <allegro.h> #include <cmath>
int nr = 123456789;
int mx = 0, my = 0, mb = 0; void myszka() { if( mx != mouse_x || my != mouse_y || mb != mouse_b ) { mx = mouse_x; my = mouse_y; mb = mouse_b; } };
int menu_x = 0, menu_y = 0; int eexit_x = 0, eexit_y = 0; int start_x = 115, start_y = 250; int wyjscie_x = 235, wyjscie_y = 400; int info_x = 430, info_y = 245; int ttworcy_x = 0, ttworcy_y = 0;
int main() { allegro_init(); install_keyboard(); set_color_depth( 16 ); set_gfx_mode( GFX_AUTODETECT_FULLSCREEN, 800, 600, 0, 0 ); install_mouse(); BITMAP * bufor = NULL; BITMAP * menu = NULL; BITMAP * start = NULL; BITMAP * info = NULL; BITMAP * wyjscie = NULL; BITMAP * eexit = NULL; BITMAP * ttworcy = NULL; menu = load_bmp( "images/menu.bmp", default_palette ); ttworcy = load_bmp( "images/infor.bmp", default_palette ); info = load_bmp( "images/tworcy.bmp", default_palette ); start = load_bmp( "images/start.bmp", default_palette ); wyjscie = load_bmp( "images/wyjscie.bmp", default_palette ); eexit = load_bmp( "images/eexit.bmp", default_palette ); bufor = create_bitmap( 800, 600 ); zrodlo: while( !key[ KEY_9_PAD ] ) { myszka(); menu: int kursor_x = mx - 40, kursor_y = my - 40; if( mouse_x >= start_x && mouse_x <= start_x + 125 ) { if( mouse_y >= start_y && mouse_y <= start_y + 25 ) { if( mb == 1 ) goto gra1; } } if( mouse_x >= wyjscie_x && mouse_x <= wyjscie_x + 220 ) { if( mouse_y >= wyjscie_y && mouse_y <= wyjscie_y + 40 ) { if( mb == 1 ) goto quit; } } if( mouse_x >= info_x && info_x <= info_x + 220 ) { if( mouse_y >= info_y && mouse_y <= info_y + 40 ) { if( mb == 1 ) goto inform; } } clear_to_color( bufor, makecol( 100, 100, 100 ) ); myszka(); textprintf_ex( menu, font, 20, 20, makecol( 200, 200, 200 ), 1, "Myszka x = %d, y = %d, klawisz = %d !", mx, my, mb ); masked_blit( menu, bufor, 0, 0, menu_x, menu_y, menu->w, menu->h ); masked_blit( start, bufor, 0, 0, start_x, start_y, start->w, start->h ); masked_blit( wyjscie, bufor, 0, 0, wyjscie_x, wyjscie_y, wyjscie->w, wyjscie->h ); masked_blit( info, bufor, 0, 0, info_x, info_y, info->w, info->h ); show_mouse( bufor ); unscare_mouse(); blit( bufor, screen, 0, 0, 0, 0, 800, 600 ); clear_keybuf(); } inform: { while( !key[ KEY_ESC ] ) { if( key[ KEY_ESC ] ) goto zrodlo; masked_blit( ttworcy, screen, 0, 0, ttworcy_x, ttworcy_y, ttworcy->w, ttworcy->h ); } } quit: { while( !key[ KEY_ENTER ] ) { if( key[ KEY_ESC ] ) goto zrodlo; masked_blit( eexit, screen, 0, 0, eexit_x, eexit_y, eexit->w, eexit->h ); if( key[ KEY_ENTER ] ) allegro_exit(); } } gra1: { while( !key[ KEY_9_PAD ] ) { if( key[ KEY_ESC ] ) goto zrodlo; textprintf( screen, font, 20, 20, makecol( 255, 255, 128 ), "jakis int : %d", nr ); } } destroy_bitmap( bufor ); allegro_exit(); return 0; } END_OF_MAIN();
i chciałbym w miejscu gra1 zamiast textprintf( screen, font, 20, 20, makecol( 255, 255, 128 ), "jakis int : %d", nr ); żeby była moja gra. gra jest w postaci: #include <allegro.h> #include <cmath>
int mx = 0, my = 0, mb = 0; void myszka() { if( mx != mouse_x || my != mouse_y || mb != mouse_b ) { mx = mouse_x; my = mouse_y; mb = mouse_b; } };
volatile long speed = 0; void increment_speed() { speed++; } END_OF_FUNCTION( increment_speed ); LOCK_VARIABLE( speed ); LOCK_FUNCTION( increment_speed );
int samochod_x = 100, samochod_y = 100; double tab_sin[ 72 ]; double tab_cos[ 72 ];
int sx = 195, sy = 384; double dx = 0, dy = 0; int kierunek = 54; double v = 0; int tx = 0, ty = 0;
int samochod2_x = 100, samochod2_y = 100; double tab_sin2[ 72 ]; double tab_cos2[ 72 ];
int sx2 = 165, sy2 = 384; double dx2 = 0, dy2 = 0; int kierunek2 = 54; double v2 = 0;
int paliwo1 = 10000; int paliwo2 = 10000; int zycie1 = 50; int zycie2 = 50; int aa = 100; int bb = 200;
void laduj_sin_cos() { for( int i = 0; i < 72; i++ ) { tab_sin[ i ] = sin(( M_PI *( i * 5 ) ) / 180 ); tab_cos[ i ] = cos(( M_PI *( i * 5 ) ) / 180 ); } }
void laduj_sin_cos2() { for( int i = 0; i < 72; i++ ) { tab_sin2[ i ] = sin(( M_PI *( i * 5 ) ) / 180 ); tab_cos2[ i ] = cos(( M_PI *( i * 5 ) ) / 180 ); } }
int mapa_x = 0, mapa_y = 0; BITMAP * teren = NULL; BITMAP * bufor = NULL; BITMAP * samochod = NULL; BITMAP * tlo = NULL; BITMAP * samochodzik = NULL; BITMAP * tapeta = NULL; BITMAP * pitstop = NULL;
short int map[ 15 ][ 20 ] = { 12, 12, 12, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 3, 3, 13, 13, 12, 8, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 8, 3, 3, 13, 13, 12, 8, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 8, 3, 3, 13, 13, 12, 8, 0, 0, 7, 9, 9, 9, 9, 9, 9, 9, 4, 0, 0, 8, 3, 3, 13, 13, 12, 8, 0, 0, 8, 3, 3, 3, 3, 3, 3, 3, 8, 0, 0, 8, 3, 3, 13, 13, 12, 8, 0, 0, 8, 3, 3, 3, 3, 3, 3, 3, 8, 0, 0, 8, 3, 3, 12, 12, 12, 8, 0, 0, 14, 3, 3, 3, 3, 3, 3, 3, 8, 0, 0, 8, 3, 3, 12, 12, 12, 8, 0, 0, 14, 3, 3, 3, 3, 3, 3, 3, 8, 0, 0, 8, 3, 3, 13, 13, 12, 8, 0, 0, 14, 3, 3, 3, 3, 3, 3, 3, 8, 0, 0, 8, 3, 3, 13, 13, 12, 8, 10, 10, 8, 3, 3, 3, 3, 3, 3, 3, 8, 0, 0, 8, 3, 3, 13, 13, 12, 8, 0, 0, 8, 3, 3, 3, 3, 3, 3, 3, 8, 0, 0, 8, 3, 3, 13, 13, 12, 8, 0, 0, 6, 9, 9, 9, 9, 9, 9, 9, 5, 0, 0, 8, 3, 3, 13, 13, 12, 8, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 8, 3, 3, 13, 13, 12, 8, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 8, 3, 3, 12, 12, 12, 6, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 3, 3 };
void wys_mape() { int licznik_x, licznik_y; for( licznik_x = 0; licznik_x < 20; licznik_x++ ) { for( licznik_y = 0; licznik_y < 15; licznik_y++ ) { blit( teren, bufor, ( map[ licznik_y + mapa_y ][ licznik_x + mapa_x ] % 4 ) * 40, ( map[ licznik_y + mapa_y ][ licznik_x + mapa_x ] / 4 ) * 40, licznik_x * 40, licznik_y * 40, 40, 40 ); } } };
int main() { allegro_init(); install_keyboard(); set_color_depth( 16 ); set_gfx_mode( GFX_AUTODETECT_FULLSCREEN, 800, 600, 0, 0 ); install_mouse(); show_mouse( screen ); unscare_mouse(); install_timer(); install_int_ex( increment_speed, BPS_TO_TIMER( 40 ) ); laduj_sin_cos(); laduj_sin_cos2(); samochod = load_bmp( "images/samochod.bmp", default_palette ); if( !samochod ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "nie mogê za³adowaæ obrazka Samochod !" ); allegro_exit(); return 0; } tlo = load_bmp( "images/tlo1.bmp", default_palette ); if( !samochod ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "nie mogê za³adowaæ tla !" ); allegro_exit(); return 0; } tapeta = load_bmp( "images/tapeta.bmp", default_palette ); if( !tapeta ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "nie mogê za³adowaæ tapety !" ); allegro_exit(); return 0; } samochodzik = load_bmp( "images/samochod3.bmp", default_palette ); if( !samochodzik ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "nie mogê za³adowaæ obrazka Samochod !" ); allegro_exit(); return 0; } pitstop = load_bmp( "images/pitstop.bmp", default_palette ); if( !pitstop ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "nie mogê za³adowaæ obrazka pitstop !" ); allegro_exit(); return 0; } tlo = load_bmp( "images/tlo.bmp", default_palette ); if( !samochod ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "nie mogê za³adowaæ tla !" ); allegro_exit(); return 0; } bufor = create_bitmap( 800, 600 ); if( !bufor ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "Nie mogê utworzyæ bufora !" ); allegro_exit(); return 0; } teren = load_bmp( "images/teren.bmp", default_palette ); while( !key[ KEY_ESC ] ) { int nk = map[ sy / 40 ][ sx / 40 ]; int nk2 = map[ sy2 / 40 ][ sx2 / 40 ]; while( speed > 0 ) { if( key[ KEY_ENTER ] ) { samochod_x = 100, samochod_y = 100; sx = 200, sy = 384; kierunek = 54; v = 0; } if( key[ KEY_Q ] ) { samochod2_x = 100, samochod2_y = 100; sx2 = 165, sy2 = 384; kierunek2 = 54; v2 = 0; } if(( key[ KEY_UP ] ) &&( samochod_y > 40 ) ) { v += 0.02; } else v -= 0.01; if( v <= 0 ) v -= 0.05; if( v < 0 ) v = 0; if( key[ KEY_DOWN ] ) v -= 0.06; if(( key[ KEY_LEFT ] ) &&( samochod_x > 20 ) ) { kierunek--; } else if(( key[ KEY_RIGHT ] ) &&( samochod_x < 780 ) ) { kierunek++; } if( key[ KEY_RCONTROL ] && v > 0 ) v -= 0.05; if(( key[ KEY_W ] ) &&( samochod2_y > 40 ) ) { v2 += 0.02; } else v2 -= 0.01; if( v2 <= 0 ) v2 -= 0.05; if( v2 < 0 ) v2 = 0; if( key[ KEY_S ] ) v2 -= 0.03; if(( key[ KEY_A ] ) &&( samochod2_x > 20 ) ) { kierunek2--; } else if(( key[ KEY_D ] ) &&( samochod2_x < 780 ) ) { kierunek2++; } if( key[ KEY_LCONTROL ] && v2 > 0 ) v2 -= 0.05; speed--; } if( kierunek > 71 ) kierunek = 0; if( kierunek < 0 ) kierunek = 71; if( v > 0.7 ) v = 0.7; if( v <- 0.2 ) v =- 0.2; if( sx > 675 ) v = 0.1; if( sx < 132 ) v = 0.1; if( sy < 15 ) v = 0.1; if( sy > 548 ) v = 0.1; if( sx > 675 ) sx = 674, 9999; if( sx < 131 ) sx = 133, 9999; if( sy < 14 ) sy = 15, 00001; if( sy > 549 ) sy = 548, 000001; dx += v * tab_cos[ kierunek ]; dy += v * tab_sin[ kierunek ]; if( dx >= 1 || dx <= - 1 ) { sx += int( dx ); dx = dx - int( dx ); } if( dy >= 1 || dy <= - 1 ) { sy += int( dy ); dy = dy - int( dy ); } if( kierunek2 > 71 ) kierunek2 = 0; if( kierunek2 < 0 ) kierunek2 = 71; if( v2 > 0.7 ) v2 = 0.7; if( v2 <- 0.2 ) v2 =- 0.2; if( sx2 > 675 ) v2 = 0.1; if( sx2 < 132 ) v2 = 0.1; if( sy2 < 15 ) v2 = 0.1; if( sy2 > 548 ) v2 = 0.1; if( sx2 > 675 ) sx2 = 674, 9999; if( sx2 < 131 ) sx2 = 133, 9999; if( sy2 < 14 ) sy2 = 15, 00001; if( sy2 > 549 ) sy2 = 548, 000001; dx2 += v2 * tab_cos2[ kierunek2 ]; dy2 += v2 * tab_sin2[ kierunek2 ]; if( dx2 >= 1 || dx2 <= - 1 ) { sx2 += int( dx2 ); dx2 = dx2 - int( dx2 ); } if( dy2 >= 1 || dy2 <= - 1 ) { sy2 += int( dy2 ); dy2 = dy2 - int( dy2 ); } if( key[ KEY_UP ] ) paliwo1--; if( key[ KEY_DOWN ] ) paliwo1--; if( nk == 3 ) zycie1--; if( sx > 675 ) { zycie1--; }; if( sx < 131 ) { zycie1--; }; if( sy < 14 ) { zycie1--; }; if( sy > 549 ) { zycie1--; }; textprintf_ex( bufor, font, 2, 110, makecol( 255, 255, 255 ), - 1, "Paliwo", paliwo1 ); textprintf_ex( bufor, font, 2, 140, makecol( 255, 255, 255 ), - 1, "Zycie" ); textprintf_ex( bufor, font, 2, 120, makecol( 255, 255, 255 ), - 1, " : %d", paliwo1 ); textprintf_ex( bufor, font, 2, 150, makecol( 255, 255, 255 ), - 1, " : %d", zycie1 ); if( nk == 3 ) v--; if( nk2 == 3 ) v2--; textprintf_ex( bufor, font, 2, 50, makecol( 255, 255, 255 ), - 1, "GRACZ 1", v ); textprintf_ex( bufor, font, 2, 80, makecol( 255, 255, 255 ), - 1, "Prędkosc:", v ); textprintf_ex( bufor, font, 2, 90, makecol( 255, 255, 255 ), - 1, "V: %.2f", v ); textprintf_ex( bufor, font, 2, 330, makecol( 255, 255, 255 ), - 1, "GRACZ 2", v ); textprintf_ex( bufor, font, 2, 360, makecol( 255, 255, 255 ), - 1, "Prędkosc:", v ); textprintf_ex( bufor, font, 2, 370, makecol( 255, 255, 255 ), - 1, "V: %.2f", v2 ); textprintf_ex( bufor, font, 2, 390, makecol( 255, 255, 255 ), - 1, "Paliwo" ); textprintf_ex( bufor, font, 2, 420, makecol( 255, 255, 255 ), - 1, "Zycie" ); textprintf_ex( bufor, font, 2, 400, makecol( 255, 255, 255 ), - 1, " : %d", paliwo2 ); textprintf_ex( bufor, font, 2, 430, makecol( 255, 255, 255 ), - 1, " : %d", zycie2 ); if( key[ KEY_W ] ) paliwo2 -= 0.001; if( key[ KEY_S ] ) paliwo2 -= 0.001; if( nk2 == 3 ) zycie2--; if( sx2 > 675 ) { zycie2--; }; if( sx2 < 131 ) { zycie2--; }; if( sy2 < 14 ) { zycie2--; }; if( sy2 > 549 ) { zycie2--; }; if( paliwo2 <= 0 ) v2 = 0.2; if( paliwo2 < 0 ) paliwo2 = 0; if( paliwo1 <= 0 ) v = 0.2; if( paliwo1 < 0 ) paliwo1 = 0; if( zycie2 < 0 ) v2 = 0.2; if( zycie2 < 0 ) zycie2 = 0; if( zycie1 < 0 ) v = 0.2; if( zycie1 < 0 ) zycie1 = 0; if( nk == 14 ) paliwo1 += 2; if( nk2 == 14 ) paliwo2 += 2; if( nk == 14 ) zycie1++; if( nk2 == 14 ) zycie2++; if( zycie1 > 50 ) zycie1 = 50; if( zycie2 > 50 ) zycie2 = 50; if( zycie1 == 0 ) v = 0.1; if( zycie2 == 0 ) v2 = 0.1; masked_blit( tapeta, bufor, 0, 0, 258, 139, tapeta->w, tapeta->h ); masked_blit( samochod, bufor,( kierunek % 18 ) * 30,( kierunek / 18 ) * 30, sx, sy, 30, 30 ); masked_blit( samochodzik, bufor,( kierunek2 % 18 ) * 30,( kierunek2 / 18 ) * 30, sx2, sy2, 30, 30 ); blit( bufor, screen, 0, 0, 0, 0, 800, 600 ); clear_to_color( bufor, makecol( 150, 150, 150 ) ); wys_mape(); } remove_int( increment_speed ); destroy_bitmap( teren ); destroy_bitmap( bufor ); destroy_bitmap( samochod ); destroy_bitmap( samochodzik ); allegro_exit(); return 0; } END_OF_MAIN();
Chodzi mi tylko o pomoc typu: to daj tu, to wywal, to ci nie potrzebne. |