Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[Allegro / C++] Bufor nie działa.

Ostatnio zmodyfikowano 2012-05-30 12:41
Autor Wiadomość
Forczek
Temat założony przez niniejszego użytkownika
[Allegro / C++] Bufor nie działa.
» 2012-05-28 15:28:38
Siemka, najpierw kod:

C/C++
#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_WINDOWED, 800, 500, 0, 0 );
    clear_to_color( screen, makecol( 128, 128, 128 ) );
    install_timer();
    install_int_ex( increment_speed, BPS_TO_TIMER( 150 ) );
   
   
    BITMAP * postac = NULL;
    BITMAP * postac0 = NULL;
    BITMAP * postac1 = NULL;
    BITMAP * postac2 = NULL;
    BITMAP * postac3 = NULL;
    BITMAP * postac4 = NULL;
    BITMAP * postac5 = NULL;
   
    BITMAP * ludek = NULL;
    BITMAP * ludek0 = NULL;
    BITMAP * ludek1 = NULL;
    BITMAP * ludek2 = NULL;
    BITMAP * ludek3 = NULL;
    BITMAP * ludek4 = NULL;
    BITMAP * ludek5 = NULL;
   
    BITMAP * buffor = NULL;
    BITMAP * tlo = NULL;
   
    BITMAP * KulaWody = NULL;
    BITMAP * KulaOgnia = NULL;
   
    postac0 = load_bmp( "postac0.bmp", default_palette );
    postac1 = load_bmp( "postac1.bmp", default_palette );
    postac2 = load_bmp( "postac2.bmp", default_palette );
    postac3 = load_bmp( "postac3.bmp", default_palette );
    postac4 = load_bmp( "postac4.bmp", default_palette );
    postac5 = load_bmp( "postac5.bmp", default_palette );
   
    ludek0 = load_bmp( "ludek0.bmp", default_palette );
    ludek1 = load_bmp( "ludek1.bmp", default_palette );
    ludek2 = load_bmp( "ludek2.bmp", default_palette );
    ludek3 = load_bmp( "ludek3.bmp", default_palette );
    ludek4 = load_bmp( "ludek4.bmp", default_palette );
    ludek5 = load_bmp( "ludek5.bmp", default_palette );
   
    tlo = load_bmp( "tlo.bmp", default_palette );
    buffor = load_bmp( "buffor.bmp", default_palette );
   
    KulaWody = load_bmp( "KulaWody.bmp", default_palette );
    KulaOgnia = load_bmp( "KulaOgnia.bmp", default_palette );
   
    int postac_x = 500, postac_y = 200;
    int ludek_x = 100, ludek_y = 200;
    int KulaOgnia_x = ludek_x + 50, KulaOgnia_y = ludek_y;
    int KulaWody_x = postac_x + 50, KulaWody_y = postac_y;
    int frame = 0;
   
    while( !key[ KEY_ESC ] )
    {
        while( speed > 0 )
        {
            frame++;
           
            if( key[ KEY_A ] )
            {
                if( frame > 200 ) frame = 0;
               
                if( frame < 50 ) { draw_sprite( buffor, ludek, ludek_x, ludek_y ); }
                else if( frame >= 50 && frame < 100 ) { draw_sprite( buffor, ludek4, ludek_x, ludek_y ); }
                else if( frame >= 100 && frame < 150 ) { draw_sprite( buffor, ludek5, ludek_x, ludek_y ); }
                else if( frame >= 150 && frame < 200 ) { draw_sprite( buffor, ludek4, ludek_x, ludek_y ); }
                ludek_x--;
            }
           
            if( key[ KEY_D ] )
            {
                if( frame > 200 ) frame = 0;
               
                ludek_x++;
                if( frame < 50 ) { draw_sprite( buffor, ludek, ludek_x, ludek_y ); }
                else if( frame >= 50 && frame < 100 ) { draw_sprite( buffor, ludek4, ludek_x, ludek_y ); }
                else if( frame >= 100 && frame < 150 ) { draw_sprite( buffor, ludek5, ludek_x, ludek_y ); }
                else if( frame >= 150 && frame < 200 ) { draw_sprite( buffor, ludek4, ludek_x, ludek_y ); }
            }
            if( key[ KEY_W ] )
            {
                if( frame > 200 ) frame = 0;
               
                if( frame < 50 ) { draw_sprite( buffor, ludek, ludek_x, ludek_y ); }
                else if( frame >= 50 && frame < 100 ) { draw_sprite( buffor, ludek4, ludek_x, ludek_y ); }
                else if( frame >= 100 && frame < 150 ) { draw_sprite( buffor, ludek5, ludek_x, ludek_y ); }
                else if( frame >= 150 && frame < 200 ) { draw_sprite( buffor, ludek4, ludek_x, ludek_y ); }
                ludek_y--;
            }
           
            if( key[ KEY_S ] )
            {
                if( frame > 200 ) frame = 0;
               
                if( frame < 50 ) { draw_sprite( buffor, ludek, ludek_x, ludek_y ); }
                else if( frame >= 50 && frame < 100 ) { draw_sprite( buffor, ludek4, ludek_x, ludek_y ); }
                else if( frame >= 100 && frame < 150 ) { draw_sprite( buffor, ludek5, ludek_x, ludek_y ); }
                else if( frame >= 150 && frame < 200 ) { draw_sprite( buffor, ludek4, ludek_x, ludek_y ); }
                ludek_y++;
            }
           
            if( key[ KEY_LEFT ] )
            {
                if( frame > 200 ) frame = 0;
               
                if( frame < 50 ) { draw_sprite( buffor, postac, postac_x, postac_y ); }
                else if( frame >= 50 && frame < 100 ) { draw_sprite( buffor, postac4, postac_x, ludek_y ); }
                else if( frame >= 100 && frame < 150 ) { draw_sprite( buffor, postac5, postac_x, ludek_y ); }
                else if( frame >= 150 && frame < 200 ) { draw_sprite( buffor, postac4, postac_x, ludek_y ); }
                postac_x--;
            }
           
            if( key[ KEY_RIGHT ] )
            {
                if( frame > 200 ) frame = 0;
               
                if( frame < 50 ) { draw_sprite( buffor, postac, postac_x, postac_y ); }
                else if( frame >= 50 && frame < 100 ) { draw_sprite( buffor, postac4, postac_x, postac_y ); }
                else if( frame >= 100 && frame < 150 ) { draw_sprite( buffor, postac5, postac_x, postac_y ); }
                else if( frame >= 150 && frame < 200 ) { draw_sprite( buffor, postac4, postac_x, postac_y ); }
                postac_x++;
            }
           
            if( key[ KEY_UP ] )
            {
                if( frame > 200 ) frame = 0;
               
                if( frame < 50 ) { draw_sprite( buffor, postac, postac_x, postac_y ); }
                else if( frame >= 50 && frame < 100 ) { draw_sprite( buffor, postac4, postac_x, postac_y ); }
                else if( frame >= 100 && frame < 150 ) { draw_sprite( buffor, postac5, postac_x, postac_y ); }
                else if( frame >= 150 && frame < 200 ) { draw_sprite( buffor, postac4, postac_x, postac_y ); }
                postac_y--;
            }
           
            if( key[ KEY_DOWN ] )
            {
                if( frame > 200 ) frame = 0;
               
                if( frame < 50 ) { draw_sprite( buffor, postac, postac_x, postac_y ); }
                else if( frame >= 50 && frame < 100 ) { draw_sprite( buffor, postac4, postac_x, postac_y ); }
                else if( frame >= 100 && frame < 150 ) { draw_sprite( buffor, postac5, postac_x, postac_y ); }
                else if( frame >= 150 && frame < 200 ) { draw_sprite( buffor, postac4, postac_x, postac_y ); }
                postac_y++;
            }
           
            if( key[ KEY_4_PAD ] )
            {
                if( frame > 200 ) frame = 0;
               
                if( frame < 50 ) { draw_sprite( buffor, postac, postac_x, postac_y ); }
                else if( frame >= 50 && frame < 100 ) { draw_sprite( buffor, postac3, postac_x, postac_y ); }
                else if( frame >= 100 && frame < 150 ) { draw_sprite( buffor, postac1, postac_x, postac_y ); }
                else if( frame >= 150 && frame < 200 ) { draw_sprite( buffor, postac, postac_x, postac_y ); }
            }
           
            if( key[ KEY_5_PAD ] )
            {
                if( frame > 200 ) frame = 0;
               
                if( frame < 100 ) { draw_sprite( buffor, postac, postac_x, postac_y ); }
                else if( frame >= 100 && frame < 200 ) { draw_sprite( buffor, postac2, postac_x, postac_y ); }
            }
           
            if( key[ KEY_6_PAD ] )
            {
                if( frame > 200 ) frame = 0;
               
                if( frame < 100 ) { draw_sprite( buffor, postac, postac_x, postac_y ); }
                else if( frame >= 100 && frame < 200 ) { draw_sprite( buffor, postac0, postac_x, postac_y ); }
            }
           
            if( key[ KEY_0_PAD ] )
            {
                int KulaOgnia_x = 100, KulaOgnia_y = 100;
                int KulaWody_x = 100, KulaWody_y = 100;
                if( frame > 200 ) frame = 0;
               
                if( frame < 50 ) { draw_sprite( buffor, postac, postac_x, postac_y ); }
                else if( frame >= 50 && frame < 100 ) { draw_sprite( buffor, postac4, postac_x, postac_y ); }
                else if( frame >= 100 && frame < 150 ) { draw_sprite( buffor, postac5, postac_x, postac_y ); }
                else if( frame >= 150 && frame < 200 ) { draw_sprite( buffor, postac4, postac_x, postac_y ); }
            }
           
            if( key[ KEY_F ] )
            {
                if( frame > 200 ) frame = 0;
               
                if( frame < 50 ) { draw_sprite( buffor, postac, postac_x, postac_y ); }
                else if( frame >= 50 && frame < 100 ) { draw_sprite( buffor, postac4, postac_x, postac_y ); }
                else if( frame >= 100 && frame < 150 ) { draw_sprite( buffor, postac5, postac_x, postac_y ); }
                else if( frame >= 150 && frame < 200 ) { draw_sprite( buffor, postac4, postac_x, postac_y ); }
            }
           
            if( key[ KEY_G ] )
            {
                if( frame > 200 ) frame = 0;
               
                if( frame < 50 ) { draw_sprite( buffor, postac, postac_x, postac_y ); }
                else if( frame >= 50 && frame < 100 ) { draw_sprite( buffor, postac4, postac_x, postac_y ); }
                else if( frame >= 100 && frame < 150 ) { draw_sprite( buffor, postac5, postac_x, postac_y ); }
                else if( frame >= 150 && frame < 200 ) { draw_sprite( buffor, postac4, postac_x, postac_y ); }
            }
           
            if( key[ KEY_H ] )
            {
                if( frame > 200 ) frame = 0;
               
                if( frame < 50 ) { draw_sprite( buffor, postac, postac_x, postac_y ); }
                else if( frame >= 50 && frame < 100 ) { draw_sprite( buffor, postac4, postac_x, postac_y ); }
                else if( frame >= 100 && frame < 150 ) { draw_sprite( buffor, postac5, postac_x, postac_y ); }
                else if( frame >= 150 && frame < 200 ) { draw_sprite( buffor, postac4, postac_x, postac_y ); }
            }
           
            if( key[ KEY_J ] )
            {
                if( frame > 200 ) frame = 0;
               
                if( frame < 50 ) { draw_sprite( buffor, postac, postac_x, postac_y ); }
                else if( frame >= 50 && frame < 100 ) { draw_sprite( buffor, postac4, postac_x, postac_y ); }
                else if( frame >= 100 && frame < 150 ) { draw_sprite( buffor, postac5, postac_x, postac_y ); }
                else if( frame >= 150 && frame < 200 ) { draw_sprite( buffor, postac4, postac_x, postac_y ); }
            }
           
            speed--;
           
        }
        clear_to_color( screen, makecol( 128, 128, 128 ) );
        blit( tlo, screen, 0, 0, 0, 0, 800, 500 );
        blit( buffor, screen, 0, 0, 0, 0, 800, 500 );
        masked_blit( ludek, buffor, 0, 0, ludek_x, ludek_y, ludek->w, ludek->h );
        masked_blit( postac, buffor, 0, 0, postac_x, postac_y, postac->w, postac->h );
    }
    remove_int( increment_speed );
    destroy_bitmap( ludek );
    destroy_bitmap( ludek0 );
    destroy_bitmap( ludek1 );
    destroy_bitmap( ludek2 );
    destroy_bitmap( ludek3 );
    destroy_bitmap( ludek4 );
    destroy_bitmap( ludek5 );
    destroy_bitmap( postac );
    destroy_bitmap( postac0 );
    destroy_bitmap( postac1 );
    destroy_bitmap( postac2 );
    destroy_bitmap( postac3 );
    destroy_bitmap( postac4 );
    destroy_bitmap( postac5 );
    destroy_bitmap( tlo );
    destroy_bitmap( buffor );
    remove_int( increment_speed );
    readkey();
    allegro_exit();
    return 0;
   
}
END_OF_MAIN();

Problem w tym, że bufor nie działa i tło miga. Co jest źle w kodzie, to moja pierwsza gra. Co do zastosowania tablic, wiem, umiem, lecz w kursie było tak i tak zrobiłem, a potem nie chciało mi się tego poprawiać. Prosiłbym o poprawny kod, a nie tłumaczenie błędu. Jak pisałem to moja pierwsza gra i chyba najlepiej zrozumiem widząc poprawiony kod. Wcześniej bufor działał, lecz teraz gdy dodałem timera i animacje się popsuło.
P-57382
Giedzu
» 2012-05-30 12:41:14
Pomyśl nad tą linijką :

C/C++
clear_to_color( screen, makecol( 128, 128, 128 ) );

Chyba musisz odświeżać bufor a nie screen, nie?:P
C/C++
clear_to_color( buffor, makecol( 128, 128, 128 ) );
P-57489
« 1 »
  Strona 1 z 1