/* intersectX0: * Return true if boxes could overlap if shifted in y but don't, * or if actually overlap and an y move is smallest to remove overlap. * Otherwise (no x overlap or a x move is smaller), return false. * Assume q pos to above of p pos. */ static int intersectX0(nitem * p, nitem * q) { int xdelta, ydelta; int v = ((p->bb.LL.x <= q->bb.UR.x) && (q->bb.LL.x <= p->bb.UR.x)); if (v == 0) /* no x overlap */ return 0; if (p->bb.UR.y < q->bb.LL.y) /* but boxes don't really overlap */ return 1; ydelta = distY(&p->bb,&q->bb) - (q->pos.y - p->pos.y); if (q->pos.x >= p->pos.x) xdelta = distX(&p->bb,&q->bb) - (q->pos.x - p->pos.x); else xdelta = distX(&p->bb,&q->bb) - (p->pos.x - q->pos.x); return (ydelta <= xdelta); }
/* intersectY0: * Return true if boxes could overlap if shifted in x but don't, * or if actually overlap and an x move is smallest to remove overlap. * Otherwise (no y overlap or a y move is smaller), return false. * Assume q pos to right of p pos. */ static int intersectY0(nitem * p, nitem * q) { int xdelta, ydelta; int v = ((p->bb.LL.y <= q->bb.UR.y) && (q->bb.LL.y <= p->bb.UR.y)); if (v == 0) /* no y overlap */ return 0; if (p->bb.UR.x < q->bb.LL.x) /* but boxes don't really overlap */ return 1; xdelta = distX(&p->bb,&q->bb) - (q->pos.x - p->pos.x); if (q->pos.y >= p->pos.y) ydelta = distY(&p->bb,&q->bb) - (q->pos.y - p->pos.y); else ydelta = distY(&p->bb,&q->bb) - (p->pos.y - q->pos.y); return (xdelta <= ydelta); }
task main() { ClearMessage(); float widthOfRoom=perimeterX(); //calculate the width of the room float distanceY=perimeterY(); //calculate the length of the room int repitition=reps(widthOfRoom); //calculate how many repititions of the cleaning cycle it needs to do float distanceX= distX(widthOfRoom); //calculate the distance per strafe on the repititions bool hit= false; int counter=0; while((counter<repitition-3)&&hit!=1)// run while it hasn't hit the bottom, or has not completed all of its repititions { hit=drive(1,distanceY-40); //drive forward -20cm for clearance from wall if(hit) //if it hit something go through obstacle functions { float lengthOfObstacle=obstacle(1); //drive around the obstacle drive(1, distanceY-lengthOfObstacle +10); //drive forward the remainder of the distance hit=false; //reset hit } drive(3, distanceX); //drive right hit=drive(2, (distanceY+20) ); //drive backwards -20cm for clearance from wall if(hit) //if it hits something go through obstacle functions { wait1Msec(2000); //wait for sensor to rotate float lengthOfObstacle=obstacle(2); //drive around the obstacle drive(2, distanceY+lengthOfObstacle); //drive the remainder of the distance hit=false; //reset hit } hit=drive(3, distanceX);//drive right counter++; } motor[motorA]=0; motor[motorB]=0; motor[motorC]=0; }
void GameplayState::resolveExistance() { for(unsigned int i = 0; i < enemies.size(); i++) { sf::Vector2f playerPos = player->representation.getPosition(); float enemyLen = ezo::vecLength(playerPos.x - enemies[i]->representation.getPosition().x, playerPos.y - enemies[i]->representation.getPosition().y); if(enemyLen > 1500.f) { std::uniform_real_distribution<float> distX(servLoc.getRender()->getWindow()->getSize().x/4, servLoc.getRender()->getWindow()->getSize().x/2); std::uniform_real_distribution<float> distY(servLoc.getRender()->getWindow()->getSize().y/4, servLoc.getRender()->getWindow()->getSize().y/2); std::uniform_int_distribution<int> boolDist(false, true); sf::Vector2f playerPos = player->representation.getPosition(); float posX = distX(randEngine); float posY = distY(randEngine); if(boolDist(randEngine)) posX = -posX; if(boolDist(randEngine)) posY = -posY; enemies[i]->representation.setPosition({posX + playerPos.x, posY + playerPos.y}); } if(!enemies[i]->exist) { std::uniform_int_distribution<unsigned char> exploColor(0, 255); sf::Color explosionColor(exploColor(randEngine), exploColor(randEngine), exploColor(randEngine)); ParticlesSource* explo = new ParticlesSource(enemies[i]->representation.getPosition()); explo->createParticles(1000, sf::Vector2f(0, 0), 4.f, explosionColor, 0, sf::seconds(0.7f), 0.4f); explosions.push_back(explo); std::uniform_real_distribution<float> distX(servLoc.getRender()->getWindow()->getSize().x/4, servLoc.getRender()->getWindow()->getSize().x/2); std::uniform_real_distribution<float> distY(servLoc.getRender()->getWindow()->getSize().y/4, servLoc.getRender()->getWindow()->getSize().y/2); std::uniform_int_distribution<int> boolDist(false, true); if(boolDist(randEngine)) { player->hp += enemies[i]->attack * 3; if(player->hp > player->fullHP) player->hp = player->fullHP; } delete enemies[i]; enemies.erase( enemies.begin() + i); static unsigned int enemyHP, enemyAttack; unsigned int enemiesCount; if(player->score < 3) enemiesCount = 1, enemyHP = 30, enemyAttack = 1; else if(player->score < 10) enemiesCount = 2, enemyHP = 60, enemyAttack = 2; else if(player->score < 50) enemiesCount = 4, enemyHP = 80, enemyAttack = 3; else if(player->score < 100) enemiesCount = 7, enemyHP = 100, enemyAttack = 5; else if(player->score < 200) enemiesCount = 10, enemyHP = 150, enemyAttack = 4; else if(player->score < 1000) enemiesCount = 12, enemyHP = 180, enemyAttack = 5; else enemiesCount = 17, enemyHP = 200, enemyAttack = 8; for(unsigned int i = enemies.size(); i < enemiesCount; i++) { sf::Vector2f enemyPos; float xpart = distX(randEngine); float ypart = distY(randEngine); if(boolDist(randEngine)) xpart = -xpart; if(boolDist(randEngine)) ypart = -ypart; enemyPos.x = xpart + player->representation.getPosition().x; enemyPos.y = ypart + player->representation.getPosition().y; enemies.push_back(new Ship(enemyPos, enemyHP, 1100, 700, enemyAttack, 6, 10000, 1000000000)); } } } }