1 / 16

ALLEGRO PIERWSZA GRA: WYŚCIG

ALLEGRO PIERWSZA GRA: WYŚCIG. Co trzeba zrobić?. Wyświetlanie: postaci i mapy Poruszanie dla dwóch postaci Kolizje ze ścianami Koniec gry -wygraną gracza I lub II. BITMAPA. Tworzenie bitmapy: BITMAP * obrazek = NULL; obrazek = create_bitmap (256,256);

lena
Télécharger la présentation

ALLEGRO PIERWSZA GRA: WYŚCIG

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ALLEGRO PIERWSZA GRA:WYŚCIG

  2. Co trzeba zrobić? • Wyświetlanie: postaci i mapy • Poruszanie dla dwóch postaci • Kolizje ze ścianami • Koniec gry -wygraną gracza I lub II

  3. BITMAPA • Tworzenie bitmapy:BITMAP * obrazek = NULL;obrazek = create_bitmap(256,256); • Wczytywanie obrazka:obrazek = load_bmp( „obraz.bmp", default_palette ); 3.Sprawdzanie czy obrazek się wczytał: if (!obrazek) { }

  4. Wyświetlanie bitmap 1.Wyświetlanie Bitmapy blit(obrazek,screen,x1,y1, x,y, szerokość, wysokość); 2.Wyświetlanie Bitmapy bez tła (255,0,255): masked_blit(obrazek,screen,x1,y1, x,y, szerokość, wysokość); screen obrazek y1 x1 x y szerokość Wysokość

  5. Dlaczego ekran miga? labirynt Postaci I i II

  6. Podwójny bufor labirynt Postaci I i II bufor

  7. Podwójny bufor 1.Tworzymy bitmapę o nazwie np. bufor i rozdzielczości identycznej z rozdzielczością naszego okna. 2.Wszystkie obiekty (planszę, postaci) kopiujemy na buforze. 3.Bufor kopiujemy na ekran(screen).

  8. Początek 1.Stwórzcie folder „Wyscigi”. 2.Plik -> nowy ->projekt... -> Multi Media -> allegro application(dll). 3.Skopiójcie z FTP i wklejcie do „Wyscigi” „labirynt.bmp”.

  9. 1.Stworzyć bitmapę dla buforu i labiryntu #include <allegro.h> void init(); void deinit(); int main() { init(); while (!key[KEY_ESC]) { } deinit(); return 0; } END_OF_MAIN() void init() { int depth, res; allegro_init(); depth = desktop_color_depth(); if (depth == 0) depth = 32; set_color_depth(depth); res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); if (res != 0) { allegro_message(allegro_error); exit(-1); } install_timer(); install_keyboard(); install_mouse(); /* add other initializations here */ } void deinit() { clear_keybuf(); /* add other deinitializations here */ } BITMAP * bufor = NULL; bufor = create_bitmap( 800, 600 ); BITMAP * lab = NULL; lab = create_bitmap( 800, 600 ); lab = load_bmp( "lab.bmp", default_palette ); destroy_bitmap( bufor ); destroy_bitmap( lab ); 800,600

  10. Wyświetlanie postaci oraz labiryntu int x=50, y=45; int x1=750, y1=555; #include <allegro.h> void init(); void deinit(); int main() { init(); BITMAP * bufor = NULL; bufor = create_bitmap( 800, 600 ); BITMAP * lab = NULL; lab = create_bitmap( 800, 600 ); lab = load_bmp( "lab.bmp", default_palette ); while (!key[KEY_ESC]) { } destroy_bitmap( bufor ); destroy_bitmap( lab ); deinit(); return 0; } END_OF_MAIN() void init() { int depth, res; allegro_init(); depth = desktop_color_depth(); if (depth == 0) depth = 32; set_color_depth(depth); res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0); if (res != 0) { allegro_message(allegro_error); exit(-1); } install_timer(); install_keyboard(); install_mouse(); /* add other initializations here */ } void deinit() { clear_keybuf(); /* add other deinitializations here */ } blit(lab,bufor,0,0,0,0,800,600); circlefill(bufor, x, y, 20, makecol(255,0,0)); circlefill(bufor, x1, y1, 20, makecol(0,0,255)); blit( bufor, screen, 0, 0, 0, 0, 800, 600 );

  11. Poruszanie postaciami #include <allegro.h> void init(); void deinit(); int main() { init(); BITMAP * bufor = NULL; bufor = create_bitmap( 800, 600 ); BITMAP * lab = NULL; lab = create_bitmap( 800, 600 ); lab = load_bmp( "lab.bmp", default_palette ); int x=50, y=45; int x1=750, y1=555; while (!key[KEY_ESC]) { //wyświetlanie blit(lab,bufor,0,0,0,0,800,600); circlefill(bufor, x, y, 20, makecol(255,0,0)); circlefill(bufor, x1, y1, 20, makecol(0,0,255)); blit( bufor, screen, 0, 0, 0, 0, 800, 600 ); } destroy_bitmap( bufor ); destroy_bitmap( lab ); deinit(); return 0; } END_OF_MAIN() void init() { int depth, res; allegro_init(); depth = desktop_color_depth(); if (depth == 0) depth = 32; set_color_depth(depth); res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0); if (res != 0) { allegro_message(allegro_error); exit(-1); } install_timer(); install_keyboard(); install_mouse(); /* add other initializations here */ } void deinit() { clear_keybuf(); /* add other deinitializations here */ } if ( key [KEY_D] )x++; if ( key [KEY_S] )y++; if ( key [KEY_A] )x--; if ( key [KEY_W] )y--; if ( key [KEY_RIGHT] )x1++; if ( key [KEY_DOWN] )y1++; if ( key [KEY_LEFT] )x1--; if ( key [KEY_UP] )y1--;

  12. Kolizje w grze • getpixel(screen,x,y)- funkcja zwracająca kolor pixela na bitmapie (screen) o pozycji x,y. • Np. if (getpixel(screen, 20, 100)==makecol(0,0,0)) { }

  13. Kolizje w grze

  14. Kolizje i wygrane if( getpixel(lab,x-20,y)==0 || getpixel(lab,x+20,y)==0 || getpixel(lab,x,y-20)==0 || getpixel(lab,x,y+20)==0) { x=50; y=45; } if( getpixel(lab,x1-20,y1)==0 || getpixel(lab,x1+20,y1)==0 || getpixel(lab,x1,y1-20)==0 || getpixel(lab,x1,y1+20)==0) { x1=750; y1=555; } #include <allegro.h> void init(); void deinit(); int main() { init(); BITMAP * bufor = NULL; bufor = create_bitmap( 800, 600 ); BITMAP * lab = NULL; lab = create_bitmap( 800, 600 ); lab = load_bmp( "lab.bmp", default_palette ); int x=50, y=45; int x1=750, y1=555; while (!key[KEY_ESC]) { if ( key [KEY_D] )x++; if ( key [KEY_S] )y++; if ( key [KEY_A] )x--; if ( key [KEY_W] )y--; if ( key [KEY_RIGHT] )x1++; if ( key [KEY_DOWN] )y1++; if ( key [KEY_LEFT] )x1--; if ( key [KEY_UP] )y1--; //wyświetlanie blit(lab,bufor,0,0,0,0,800,600); circlefill(bufor, x, y, 20, makecol(255,0,0)); circlefill(bufor, x1, y1, 20, makecol(0,0,255)); blit( bufor, screen, 0, 0, 0, 0, 800, 600 ); } destroy_bitmap( bufor ); destroy_bitmap( lab ); deinit(); return 0; } END_OF_MAIN() void init() { int depth, res; allegro_init(); depth = desktop_color_depth(); if (depth == 0) depth = 32; set_color_depth(depth); res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0); if (res != 0) { allegro_message(allegro_error); exit(-1); } install_timer(); install_keyboard(); install_mouse(); /* add other initializations here */ } void deinit() { clear_keybuf(); /* add other deinitializations here */ } if( getpixel(lab,x,y)==makecol(255,255,0)) { allegro_message("WYGRYWA CZERWONY"); exit(-1); } if( getpixel(lab,x1,y1)==makecol(255,255,0)) { allegro_message("WYGRYWA NIEBIESKI"); exit(-1); }

  15. allegro_message(„”) oraz exit(-1); Allegro_message(”Text”);- Funkcja wyświetlająca okienko z tekstem oraz przyciskiem „OK”. exit(-1); - Funkcja wyłączająca program w allegro.

  16. ZADANIA • Zaprogramuj by postać nie była kołem, a bitmapom oraz zrób by postać się poruszała (animacje). • Zrób ładniejsze zakończenia gry. • Zrób kilka poziomów licznik zwycięstw graczy oraz automatyczne przechodzenie do następnego poziomu.

More Related