//proste sprawdzanie, czy pocisk trafi³ porównuj¹c wspó³rzêdne pocisku i czo³gu //jeœli pocisk znalaz³ siê w obrêbie czo³gu, to znaczy, ¿e nast¹pi³o trafienie bool Tank::isHit(Projectile p) { if (&p == NULL) return false; if (p.getX() > this->getX() && p.getX() < this->getX() + 64 && p.getY() > this->getY() && p.getY() < this->getY() + 24) { return true; } else return false; }
bool ProjectileList::isProjectileCollide(Projectile proj){ //50 -> PROJ_WIDTH, 20 -> PROJ HEIGHT return area->tileTypeXY(proj.getX(),proj.getY())!='_' \ || area->tileTypeXY(proj.getX(),proj.getY()+10)!='_' \ || area->tileTypeXY(proj.getX(),proj.getY()+20)!='_' \ || area->tileTypeXY(proj.getX()+10,proj.getY())!='_' \ || area->tileTypeXY(proj.getX()+10,proj.getY()+20)!='_' \ || area->tileTypeXY(proj.getX()+10,proj.getY()+10)!='_'; }
bool ProjectileList::checkRect(int index,char origin, float x1, float y1, float x2, float y2){ Projectile * toCheck = &(pVector.at(index)); if(toCheck->origin == origin) return false; else if(isInRect(toCheck->getX(),toCheck->getY(),x1,y1,x2,y2)) return true; }
void ProjectileList::updateList(){ for(unsigned int i = 0; i < pVector.size();i++){ if(!isProjectileCollide(pVector.at(i))) pVector.at(i).update(); else { Projectile * toDel = &pVector.at(i); effects->add(toDel->getX(),toDel->getY(),ENERGYBOOM,EFFECT_NOTYPE,toDel->getDir(),NULL); boomS.play(); pVector.erase(pVector.begin()+i); if(i > 0) i--; } } }
void RemoteProcessClient::writeProjectile(const Projectile& projectile) { writeBoolean(true); writeLong(projectile.getId()); writeDouble(projectile.getMass()); writeDouble(projectile.getX()); writeDouble(projectile.getY()); writeDouble(projectile.getSpeedX()); writeDouble(projectile.getSpeedY()); writeDouble(projectile.getAngle()); writeDouble(projectile.getAngularSpeed()); writeDouble(projectile.getRadius()); writeLong(projectile.getCarId()); writeLong(projectile.getPlayerId()); writeEnum<ProjectileType>(projectile.getType()); }