TNTeener Temat założony przez niniejszego użytkownika |
[Allegro]Gra na czas czyli wyświetlanie wiadomości "Koniec Gry" po określonym czasie » 2012-10-12 20:27:31 Witam. Tworzę grę i mam dużo problemów. Teraz mam problem z timerami. Otóż chce zbrobić tak że gracz ma np. 60 sekund na zdobycie jak największej liczby punktów. I tutaj jest pytanie - jak użyć do tego timery? Naprawdę mi na tym zależy. Kod mojej gry: #include <allegro.h> bool kolizja( float x1, float y1, float s1, float w1, float x2, float y2, float s2, float w2 ) { if( x1 + s1 >= x2 && x1 <= x2 + s2 && y1 + w1 >= y2 && y1 <= y2 + w2 ) return( true ); return( false ); } int main() { allegro_init(); set_window_title( "Zasypany Gornik 0.2" ); install_keyboard(); set_color_depth( 16 ); set_gfx_mode( GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0 ); install_sound( DIGI_AUTODETECT, MIDI_AUTODETECT, "" ); set_volume( 100, 100 ); BITMAP * punkt = NULL; BITMAP * mapa = NULL; BITMAP * ludek = NULL; BITMAP * bufor = NULL; SAMPLE * tytul = NULL; bufor = create_bitmap( 640, 480 ); if( !bufor ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "Error 001: Nie utworzono bufora" ); allegro_exit(); return 0; } ludek = load_bmp( "tex/ludzik.bmp", default_palette ); mapa = load_bmp( "tex/mapa.bmp", default_palette ); punkt = load_bmp( "tex/punkty.bmp", default_palette ); tytul = load_sample( "sound/tytul.wav" ); if( !ludek ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "Error 002: Nie znaleziono grafiki." ); allegro_exit(); return 0; } if( !punkt ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "Error 002: Nie znaleziono grafiki." ); allegro_exit(); return 0; } if( !mapa ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "Error 002: Nie znaleziono grafiki." ); allegro_exit(); return 0; } play_sample( tytul, 255, 127, 1000, 1 ); int ludek_x = 100, ludek_y = 100; int mapa_x = 0, mapa_y = 0; int punkt_x = 200, punkt_y = 200; int points = 0; int i = 0; int czas = timeGetTime(); while( !key[ KEY_ESC ] ) { adjust_sample( tytul, 255, 255, 1000, 1 ); textprintf( screen, font, 20, 20, makecol( 255, 255, 128 ), "Punkty : %d", points ); if( key[ KEY_ESC ] ) return 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++; if( key[ KEY_F2 ] ) save_bitmap( "screen/ekran.bmp", screen, default_palette ); rest( 10 ); masked_blit( ludek, mapa, 0, 0, ludek_x, ludek_y, ludek->w, ludek->h ); masked_blit( mapa, screen, 0, 0, mapa_x, mapa_y, mapa->w, mapa->h ); masked_blit( punkt, mapa, 0, 0, punkt_x, punkt_y, punkt->w, punkt->h ); if( kolizja( ludek_x, ludek_y, 55, 50, punkt_x, punkt_y, 15, 98 ) == true && ludek_y == punkt_y ) { if( i == 0 ) { points++; i++; punkt_x = rand() % 400 + 100; punkt_y = rand() % 400 + 100; } else { i -= 1; } } } destroy_sample( tytul ); destroy_bitmap( ludek ); destroy_bitmap( bufor ); destroy_bitmap( punkt ); destroy_bitmap( mapa ); allegro_exit(); return 0; } END_OF_MAIN();
|