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

[Allegro] Podmiana mapy problem

Ostatnio zmodyfikowano 2009-07-25 12:14
Autor Wiadomość
wojownik266
Temat założony przez niniejszego użytkownika
[Allegro] Podmiana mapy problem
» 2009-07-25 11:23:52
Mam taki sobie projekt gry z ludzikiem i mapą. Na jednej z map program działa tak jak należy a gdy podmienię mapy (teren) ludzik przelatuje przez ekran od góry do dołu i znika. Co może być tego przyczyną? Proszę o pomoc w rozwiązaniu tego problemu. Na zyczenie mogę zamiescić cały kod programu...
P-8762
wojownik266
Temat założony przez niniejszego użytkownika
» 2009-07-25 11:34:57
Oto kod programu:

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 );
short int map[ 12 ][ 16 ] =
{
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    1, 3, 3, 3, 3, 3, 1, 3, 1, 1, 3, 3, 3, 3, 3, 3,
    3, 3, 3, 3, 1, 1, 1, 3, 3, 3, 1, 3, 3, 3, 3, 3,
    3, 3, 1, 1, 1, 3, 3, 3, 3, 3, 3, 1, 3, 3, 1, 1,
    3, 3, 3, 3, 1, 3, 1, 1, 1, 3, 3, 3, 1, 3, 3, 1,
    1, 1, 3, 3, 1, 3, 3, 1, 3, 3, 1, 3, 1, 1, 3, 1,
    1, 7, 7, 1, 1, 1, 7, 7, 7, 1, 1, 1, 1, 7, 7, 1,
    1, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 1,
    1, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 1,
    1, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 1,
   
};


int mapa_x = 0, mapa_y = 0;
void wys_mape( BITMAP * bufor, BITMAP * teren )
{
    int licznik_x, licznik_y;
    for( licznik_x = 0; licznik_x < 20; licznik_x++ )
    {
        for( licznik_y = 0; licznik_y < 13; 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 );
        }
    }
};
void uruchom_allegro()
{
    allegro_init();
    install_keyboard();
    set_color_depth( 16 );
    set_gfx_mode( GFX_AUTODETECT_WINDOWED, 600, 400, 0, 0 );
   
    install_timer();
    install_int_ex( increment_speed, BPS_TO_TIMER( 100 ) );
};

class bohater
{
public:
    short int x, y;
    short int xx, yy;
    short int s, w;
    int hp;
    int exp;
    int lvl;
    int max_exp;
    int pexp;
    int max_hp;
    int zloto;
    int xl, yl;
   
    void hpup( int ile );
    void hpdown( int ile );
    void expup( int ile );
    void expdown( int ile );
    void lvlup();
    void wyswietl( BITMAP * );
    void dodaj_wartosci();
    void update();
    void idz();
    char string[];
    void skacz();
   
   
};
void bohater::hpup( int ile )
{
    hp += ile;
    if( hp > max_hp )
    {
        hp = max_hp;
       
       
    }
}
void bohater::hpdown( int ile )
{
    hp -= ile;
    if( hp < 0 ) hp = 0;
   
}

void bohater::expup( int ile )
{
    exp += ile;
   
}
void bohater::expdown( int ile )
{
    exp -= ile;
    if( exp < 0 ) exp = 0;
   
}
void bohater::lvlup()
{
    lvl++;
    max_exp = lvl * 1000;
    exp = 0;
    hpup( lvl * 50 );
    max_hp = lvl * 200;
    zloto += 100;
   
}

void bohater::wyswietl( BITMAP * bufor )
{
    textprintf_ex( bufor, font, 10, 15, makecol( 0, 0, 0 ), - 1, "Poziom postaci %d ", lvl );
    textprintf_ex( bufor, font, 10, 25, makecol( 0, 0, 0 ), - 1, "Ilosc hp %d ", hp );
    textprintf_ex( bufor, font, 10, 35, makecol( 0, 0, 0 ), - 1, "maks Ilosc hp %d ", max_hp );
    textprintf_ex( bufor, font, 10, 45, makecol( 0, 0, 0 ), - 1, "Ilosc DOS %d ", exp );
    textprintf_ex( bufor, font, 10, 55, makecol( 0, 0, 0 ), - 1, "Pozycja ludka %d %d", xl, yl );
    textprintf_ex( bufor, font, 10, 65, makecol( 0, 0, 0 ), - 1, "Ludek,y %d ", yl );
   
}
void bohater::dodaj_wartosci()
{
    lvl = 1;
    hp = lvl * 100;
    max_hp = 200;
    exp = 1000;
    max_exp = lvl * 2000;
    pexp = max_exp - exp;
    zloto = 100;
   
}
void bohater::update()
{
    pexp = max_exp - exp;
   
}

int main()
{
    uruchom_allegro();
   
    // Wskaźniki
    BITMAP * bufor = create_bitmap( 600, 400 );
    BITMAP * ludekb1 = NULL;
    BITMAP * ludekb2 = NULL;
    BITMAP * tlo = NULL;
    BITMAP * teren = NULL;
   
    //Ładowanie  obrazków
    teren = load_bmp( "teren.bmp", default_palette );
    ludekb1 = load_bmp( "ludek.bmp", default_palette );
    tlo = load_bmp( "tlo.bmp", default_palette );
    ludekb2 = load_bmp( "ludekb2.bmp", default_palette );
   
   
    bohater ludek, ludek2;
   
    ludek.x = 440; ludek.y = 40; ludek.s = 40; ludek.w = 40;
    ludek2.x = 300; ludek2.y = 300; ludek2.s = 40; ludek2.w = 40;
   
   
    ludek.dodaj_wartosci();
    bool help = false;
    bool kolizja = false;
    bool grawitacja;
    bool mp = true;
    bool ml;
    double predkoscLotu = 0;
   
    while( !key[ KEY_ESC ] )
    {
        while( speed > 0 )
        {
            grawitacja = true;
            mp = true;
            ml = true;
            ludek.update();
           
            // Obsługa klawiatury
            for( int x = ludek.x; x <= ludek.x + 40; x += 39 )
            for( int y = ludek.y; y <= ludek.y + 40; y += 39 )
            if( x <= 600 && y <= 440 )
            {
                if(( map[( y +( int ) predkoscLotu ) / 40 ][ x / 40 ] ) == 15 ) grawitacja = false;
               
                if(( map[ y / 40 ][( x - 1 ) / 40 ] ) == 15 ) ml = false;
               
                if(( map[ y / 40 ][( x + 1 ) / 40 ] ) == 15 ) mp = false;
               
            }
           
            if( ml == true ) { if( key[ KEY_LEFT ] ) ludek.x--; }
           
            if( mp == true ) { if( key[ KEY_RIGHT ] ) ludek.x++; }
           
            if( grawitacja == false ) predkoscLotu = 1;
           
            if( key[ KEY_UP ] && grawitacja == false ) predkoscLotu =- 4;
           
            if( grawitacja == true )
            {
                ludek.y += predkoscLotu;
                predkoscLotu += 0.1;
            }
           
            if( key[ KEY_A ] ) ludek.expup( 100 );
           
            if( key[ KEY_S ] ) ludek.hpup( 100 );
           
            if( key[ KEY_D ] ) ludek.hpdown( 100 );
           
            if( key[ KEY_P ] ) help = true;
           
            if( key[ KEY_O ] ) help = false;
           
           
            if( ludek.y < 0 ) ludek.y = 0;
           
            if( ludek.x < 0 ) ludek.x = 0;
           
            if( ludek.y > 440 ) ludek.y = 440;
           
            if( ludek.x > 600 ) ludek.x = 600;
           
            speed--;
        }
       
       
       
       
        clear_to_color( bufor, makecol( 150, 150, 150 ) );
       
       
        if( ludek.exp > ludek.max_exp )
        {
            ludek.lvlup();
           
        }
        wys_mape( bufor, teren );
       
        masked_blit( ludekb1, bufor, 0, 0, ludek.x, ludek.y, ludek.s, ludek.w );
        masked_blit( ludekb2, bufor, 0, 0, ludek2.x, ludek2.y, ludek2.s, ludek2.w );
        masked_blit( tlo, bufor, 0, 0, 5, 5, 200, 100 );
        ludek.wyswietl( bufor );
        blit( bufor, screen, 0, 0, 0, 0, 600, 400 );
    }
   
    destroy_bitmap( bufor );
    destroy_bitmap( ludekb1 );
    destroy_bitmap( ludekb2 );
    destroy_bitmap( tlo );
    destroy_bitmap( teren );
   
    allegro_exit();
    return 0;
}
END_OF_MAIN();
P-8763
DejaVu
» 2009-07-25 12:14:28
Problem z grawitacją już rozwiązywałem komuś innemu. Zapoznaj się z tematem http://forum.ddt.pl/?Tid=1164.
P-8765
« 1 »
  Strona 1 z 1