aaadam Temat założony przez niniejszego użytkownika |
[Allegro 5] Bomberman - wybuch bomby (kolizje) » 2013-08-05 11:02:56 Witam mam już cześć gry napisanej ale mam problem gdy dochodzi do kolizji wybuchu z terenem. Dla zasięgu = 1 nie mam problemu w sumie to nie wiem czy takie podejście to tego problemu jest prawidłowe spróbuje to w miarę dobrze opisać.
to jest moja pętla która obsługuje wybuch bomby dla tylko zasięgu = 1 oraz 2 bo mam problemy z zasięgiem =2. Mapa kafelkowa 32 pixele
itB = Bomba.begin(); while( itB != Bomba.end() && Bomba.size() > 0 ) { itB->logika(); if( itB->getI() >= 280 ) { if( player.getZasieg() == 1 ) { Wybuch.push_back( wybuch( itB->getX(), itB->getY(), 0, 0, 0, 0 ) ); Wybuch.push_back( wybuch( itB->getX() + 32, itB->getY(), 0, 0, 0, 1 ) ); Wybuch.push_back( wybuch( itB->getX() - 32, itB->getY(), 0, 0, 0, 3 ) ); Wybuch.push_back( wybuch( itB->getX(), itB->getY() - 32, 0, 0, 0, 5 ) ); Wybuch.push_back( wybuch( itB->getX(), itB->getY() + 32, 0, 0, 0, 7 ) ); itB = Bomba.erase( itB ); } else if( player.getZasieg() == 2 ) { Wybuch.push_back( wybuch( itB->getX(), itB->getY(), 0, 0, 0, 0 ) ); Wybuch.push_back( wybuch( itB->getX() + 32, itB->getY(), 0, 0, 0, 2 ) ); Wybuch.push_back( wybuch( itB->getX() - 32, itB->getY(), 0, 0, 0, 4 ) ); Wybuch.push_back( wybuch( itB->getX(), itB->getY() - 32, 0, 0, 0, 6 ) ); Wybuch.push_back( wybuch( itB->getX(), itB->getY() + 32, 0, 0, 0, 8 ) ); Wybuch.push_back( wybuch( itB->getX() + 64, itB->getY(), 0, 0, 0, 1 ) ); Wybuch.push_back( wybuch( itB->getX() - 64, itB->getY(), 0, 0, 0, 3 ) ); Wybuch.push_back( wybuch( itB->getX(), itB->getY() - 64, 0, 0, 0, 5 ) ); Wybuch.push_back( wybuch( itB->getX(), itB->getY() + 64, 0, 0, 0, 7 ) ); itB = Bomba.erase( itB ); } } else itB++; }
to pętla kolizji wybuchu z terenem dla zasiegu = 1 działa dobrze chciałem zrobić to tak, że jeżeli dojdzie do kolizji wybuchu 2 to usuwam tez wybuch 1 jeżeli 4 to 3 itd. natomiast jeżeli dojdzie do kolizji koncowych wybuchów z terenem to usuwam jedynie jeden
itT = Teren.begin(); while( itT != Teren.end() && Teren.size() > 0 ) { itW = Wybuch.begin(); while( itW != Wybuch.end() && Wybuch.size() > 0 ) { if( Collision( itW->getX(), itW->getY(), itT->getX(), itT->getY(), 10, 10 ) && itT->getStan() == 1 ) { if( player.getZasieg() == 1 ) { itW = Wybuch.erase( itW ); x = itT->getX(); y = itT->getY(); itT = Teren.erase( itT ); itT = Teren.begin(); Wybuch.push_back( wybuch( x, y, 0, 0, 0, 9 ) ); } else if( player.getZasieg() == 2 ) { if( itW->getKier() == 4 ) { itW = Wybuch.erase( itW ); x = itT->getX(); y = itT->getY(); itT = Teren.erase( itT ); itT = Teren.begin(); int i = 0; while( i < 5 ) { if( itW->getKier() == 3 ) { itW = Wybuch.erase( itW ); } else { itW++; i++; } } Wybuch.push_back( wybuch( x, y, 0, 0, 0, 9 ) ); } else if( itW->getKier() == 6 ) { x = itT->getX(); y = itT->getY(); itT = Teren.erase( itT ); itT = Teren.begin(); int i = 0; while( i < 5 ) { if( itW->getKier() == 5 ) { itW = Wybuch.erase( itW ); break; } else { itW++; i++; } } itW = Wybuch.erase( itW ); Wybuch.push_back( wybuch( x, y, 0, 0, 0, 9 ) ); } else if( itW->getKier() == 2 ) { itW = Wybuch.erase( itW ); x = itT->getX(); y = itT->getY(); itT = Teren.erase( itT ); itT = Teren.begin(); int i = 0; while( i < 5 ) { if( itW->getKier() == 1 ) { itW = Wybuch.erase( itW ); break; } else { itW++; i++; } } Wybuch.push_back( wybuch( x, y, 0, 0, 0, 9 ) ); } else if( itW->getKier() == 8 ) { itW = Wybuch.erase( itW ); x = itT->getX(); y = itT->getY(); itT = Teren.erase( itT ); itT = Teren.begin(); int i = 0; while( i < 5 ) { if( itW->getKier() == 7 ) { itW = Wybuch.erase( itW ); break; } else { itW++; i++; } } Wybuch.push_back( wybuch( x, y, 0, 0, 0, 9 ) ); } else if( itW->getKier() == 9 ) { itW = Wybuch.erase( itW ); } else if( itW->getKier() == 1 && itW->getKier() == 3 && itW->getKier() == 5 && itW->getKier() == 7 ) { itW = Wybuch.erase( itW ); x = itT->getX(); y = itT->getY(); itT = Teren.erase( itT ); itT = Teren.begin(); Wybuch.push_back( wybuch( x, y, 0, 0, 0, 9 ) ); } } } else itW++; } itT++; }
tutaj jeszcze klasy wybuchu i terenu
class wybuch { private: int x, y, i, kierunek; char * direction; bool stan; public: wybuch( int xx, int yy, int ii, char * Dir, bool st, int kier ); int getX() { return x; } int getY() { return y; } int getI() { return i; } int getKier() { return kierunek; } int getStan() { return stan; } void iniStan( bool st ) { stan = st; } void addX( int xx ) { x += xx; } void addY( int yy ) { y += yy; } void addI( int yy ) { i += yy; } void logika() { i++; } }; wybuch::wybuch( int xx, int yy, int ii, char * Dir, bool st, int kier ) : x( xx ) , y( yy ) , i( ii ) , direction( Dir ) , stan( st ) , kierunek( kier ) { } class teren { private: int x, y, i; char * direction; bool stan; public: teren( int xx, int yy, int ii, char * Dir, bool st ); int getX() { return x; } int getY() { return y; } int getI() { return i; } int getStan() { return stan; } void iniStan( bool st ) { stan = st; } void addX( int xx ) { x += xx; } void addY( int yy ) { y += yy; } void addI( int yy ) { i += yy; } void logika() { i++; } }; teren::teren( int xx, int yy, int ii, char * Dir, bool st ) : x( xx ) , y( yy ) , i( ii ) , direction( Dir ) , stan( st ) { }
nie wiem czy to podejście jest dobre jeżeli znacie lepsze rozwiązania tego problemu to proszę o pomoc. |