/* clone - this method makes another BackAndForthBot object, but does not completely initialize it with similar data to this. Most of the object, like velocity and position, are left uninitialized. */ Bot* BackAndForthBot::clone() { BackAndForthBot *botClone = new BackAndForthBot(); PhysicalProperties* pp = this->getPhysicalProperties(); PhysicalProperties* bp = botClone->getPhysicalProperties(); BoundingVolume* pV = this->getBoundingVolume(); BoundingVolume* bV = botClone->getBoundingVolume(); botClone->setEnemy(enemy); botClone->setItem(item); botClone->setPortal(portal); botClone->setSpriteType(this->getSpriteType()); botClone->setAlpha(this->getAlpha()); botClone->setDead(false); bp->setCollidable(pp->isCollidable()); bp->setGravAffected(pp->isGravAffected()); bV->setHeight(pV->getHeight()); bV->setWidth(pV->getWidth()); bV->setX(pV->getX()); bV->setY(pV->getY()); return botClone; }
void Physics::collideTestWithTiles(CollidableObject *c,TiledLayer *tL, list<Collision*> *collisions) { BoundingVolume *bv = c->getBoundingVolume(); float toRight= bv->getWidth()/2; float toBottom = bv->getHeight()/2; PhysicalProperties *pp = c->getPhysicalProperties(); float x = pp->getX()+bv->getX(); float y = pp->getY()+bv->getY(); float xVel = pp->getVelocityX(); float yVel = pp->getVelocityY(); float minX = x - toRight; float maxX = x + toRight; float minY = y - toBottom; float maxY = y + toBottom; if(xVel > 0) maxX += xVel; else minX += xVel; if(yVel > 0) maxY += yVel; else minY += yVel; int tW = tL->getTileWidth(); int tH = tL->getTileHeight(); int firstCol = minX/tW; int lastCol = maxX/tW; int firstRow = minY/tH; int lastRow = maxY/tH; if(firstCol < 0) firstCol = 0; if(firstRow < 0) firstRow = 0; if(lastCol >= tL->getColumns()) lastCol = tL->getColumns() - 1; if(lastRow >= tL->getRows()) lastRow = tL->getRows() - 1; for(int i = firstRow; i <= lastRow; i++) { for(int j = firstCol; j <= lastCol; j++) { Tile* current = tL->getTile(i,j); if(current->collidable == true) { if( !( (i+1)*tH < minY || i*tH > maxY || (j+1)*tW < minX || j*tW > maxX) ) { CollidableObject* tileCO = coStack[coStackCounter]; coStackCounter --; BoundingVolume *bv = tileCO->getBoundingVolume(); bv->setWidth(tW); bv->setHeight(tH); bv->setX(tW/2); bv->setY(tW/2); pp = tileCO->getPhysicalProperties(); pp->setPosition(j*tW,i*tH); /* Collision* currentCollision = collisionStack.top(); collisionStack.pop();*/ Collision* currentCollision = collisionStack[collisionStackCounter]; collisionStackCounter --; currentCollision->setCO1(c); currentCollision->setCO2(tileCO); currentCollision->calculateTimes(); collisions->push_back(currentCollision); } } } } }