bool imagem::colide(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2, imagem &sprite2) { if(!egl_init) return false; if(index < 0) return false; if(!colide(x1,y1,w1,h1,x2,y2,w2,h2)) return false; return (bool)SDL_CollidePixel(bmp[curr],x1,y1, sprite2.obter_bitmap(),x2,y2); }
//goes through each rock on the screen, checking for player collisions int collideMapObjTest(int chX, int chY) { int retVal = 0; if (runOnce == true) { for (int mapObjCount = 0; mapObjCount < mapObjLocations.size(); mapObjCount++) { //if(SDL_CollidePixel(playerMask, p1.getX() + chX, p1.getY() + chY, getObjSurfaceMasks(mapObjLocations.at(mapObjCount).getObjType()), mapObjLocations.at(mapObjCount).getX() * 32, mapObjLocations.at(mapObjCount).getY() * 32)) if(SDL_CollidePixel(playerMask, p1.getX() + chX, p1.getY() + chY, getObjSurface(mapObjLocations.at(mapObjCount).getObjType()), mapObjLocations.at(mapObjCount).getX() * 32, mapObjLocations.at(mapObjCount).getY() * 32)) { retVal = mapObjLocations.at(mapObjCount).getObjType(); } } } return retVal; }
void Tankas::atnaujinti(int xp, int yp, vector<Kulka*> &kulkos) { if(sprogsta) { Sprogimas(); return; } int dx, dy; dx = X+Tanks->w/2 - xp; dy = Y+Tanks->h/2 - yp; vk = atan2(dx , dy) * 180 / M_PI; pk = vk - kampas + 90; // if( kulkos != NULL ) { int i = 0; while(i < kulkos.size()) { // cout<<"kulkos x"<<kulkos[i]->GetX()<<endl; if( SDL_CollidePixel(rotation, X, Y, kulkos[i]->KPasukta, kulkos[i]->GetX(), kulkos[i]->GetY()) != 0 ) { /*I mane pataike!*/ sprogsta = true; lastW=rotation->w; lastH=rotation->h; cout<<"Pataike!"<<endl; } i++; } } if(senas_kampas!=kampas || senas_kampasP != pk) { SDL_Surface* Tn = new SDL_Surface; //Tanko vamzdis SDL_Surface* ND = new SDL_Surface; //Laikinas sluoksnis SDL_Surface* Tm = new SDL_Surface; //Originaliojo tanko sluoksnio kopija //----------------------------------------------------------------------------- ND = SDL_CreateRGBSurface(SDL_HWSURFACE|SDL_SRCALPHA, Tanks->w, Tanks->h, 32, NULL, NULL, NULL, 0); SDL_BlitSurface(Tanks, NULL, ND, NULL); Uint32 colorkey1 = SDL_MapRGB( Tanks->format, 0, 255, 0 ); SDL_SetColorKey( ND, SDL_SRCCOLORKEY, colorkey1 );//naujai sukurtam sluoksniu nustatom sena color key Tm = SDL_DisplayFormatAlpha( ND ); std::swap(Tm, ND); SDL_FreeSurface(ND); //delete(ND); //----------------------------------------------------------------------------- Tn = rotozoomSurfaceXY(Patranka, pk, 1, 1, 0); SDL_Rect dst = {Tn->w / 2, Tn->h / 2}; dst.x = ( Tanks->w - Tn->w ) / 2; dst.y = ( Tanks->h - Tn->h ) / 2; SDL_BlitSurface(Tn, NULL, Tm, &dst); SDL_FreeSurface(Tn); //delete(Tn); SDL_FreeSurface(rotation); rotation = rotozoomSurface(Tm, kampas, 0.45, 0); SDL_FreeSurface(Tm); //delete(Tm); Uint32 colorkey = SDL_MapRGB( rotation->format, 0, 255, 0 ); SDL_SetColorKey( rotation, SDL_SRCCOLORKEY, colorkey ); SDL_Surface * www = new SDL_Surface; www = SDL_DisplayFormatAlpha(rotation); std::swap(www, rotation); SDL_FreeSurface(www); //delete(www); senas_kampas = kampas; senas_kampasP = pk; } }