void Animal::handleCollision(Environment *environment, Object *object) { if (object->getType() == OBJ_TYPE_FOOD) { collideWith(environment, (Food *) object); } else if (object->getType() == OBJ_TYPE_ANIMAL) { collideWith(environment, (Animal *) object); } }
bool Bridge::collision() { // Collisions avec les objets fixes std::vector <FixedObject*> fos = Moteur2D::getInstance()->getFixedObjects(); for (unsigned int i = 0; i<fos.size(); i++) { FixedObject* fo = fos.at(i); if ((*fo)!=(*this) /*&& fo->isCollidable()*/ && collideWith(fo)) { return true; } } // Collisions avec les objets mouvants. std::vector <AnimatedObject*> aos = Moteur2D::getInstance()->getAnimatedObjects(); for (unsigned int i = 0; i<aos.size(); i++) { AnimatedObject* ao = aos.at(i); if ((*ao)!=(*m_link1) &&(*ao)!=(*m_link2) &&(*ao)!=(*WorldManager::getInstance()->getPerso()) && collideWith(ao)) { return true; } } return false; }
void AnimatedSprite::checkCollision(float seconds, sf::Vector2f oldPos) { sf::Vector2f newPos = getPosition(); // Pour chaque objets // Collisions avec les objets fixes std::vector <FixedSprite*> fss = Moteur2D::getInstance()->getFixedSprites(); for (unsigned int i = 0; i<fss.size(); i++) { FixedSprite* fs = fss.at(i); if ((*fs)!=(*this) && collideWith(fs)) { // On traite la collision applyCollision(fs, oldPos); return ; } } // Collisions avec les objets mouvants. std::vector <AnimatedSprite*> ass = Moteur2D::getInstance()->getAnimatedSprites(); for (unsigned int i = 0; i<ass.size(); i++) { AnimatedSprite* as = ass.at(i); if ((*as)!=(*this) && collideWith(as)) { // On traite la collision applyCollision(as, oldPos); return; } } // Collisions avec les arrière plans concrets. std::map <int, ConcreteBackground*> cbs = Moteur2D::getInstance()->getConcreteBackgrounds(); for (std::map<int,ConcreteBackground*>::iterator it=cbs.begin(); it!=cbs.end(); ++it) { if ((it->second)->collidedBy(this, newPos)) { // On traite la collision m_vit.x=0; m_vit.y=0; setPosition( oldPos); return; } } }
static Particle *collides(const Particle *p) { Particle *other; Box *b; int ix, iy, iz; int nx, ny, nz; #ifdef BROWNIAN const float d = config.radius + config.radiusHuge; Vec3 dhuge; sub(&p->pos, &huge.pos, &dhuge); if (length2(&dhuge) < d*d) return &huge; #endif nx = p->pos.x / config.boxSize; ny = p->pos.y / config.boxSize; nz = p->pos.z / config.boxSize; b = boxFromIndex(nx, ny, nz); other = collideWith(p, b->p); if (other != NULL) return other; for (ix = -1; ix <= 1; ix++) for (iy = -1; iy <= 1; iy++) for (iz = -1; iz <= 1; iz++) { if (ix == 0 && iy == 0 && iz == 0) continue; b = boxFromIndex(nx+ix, ny+iy, nz+iz); other = collideWith(p, b->p); if (other != NULL) return other; } return NULL; }