void StateCowFleeGetWeapon::update(){ entity->setVelocityX(velocityX); entity->setVelocityY(velocityY); //for the evader's current position. SVector2D vectorCow; vectorCow.x = entity->GetX() + entity->getVelocityX(); vectorCow.y = entity->GetY() + entity->getVelocityY(); SVector2D vectorGun; vectorGun.x = entityGun->GetX(); vectorGun.y = entityGun->GetY(); SVector2D vectorRabbit; vectorRabbit.x = entityRabbit->GetX(); vectorRabbit.y = entityRabbit->GetY(); int entity_x, entity_y; //for toroid entity_x = entity->GetX(); entity_y = entity->GetY(); uint32_t entitiy_w; uint32_t entitiy_h; entity->GetSize(entitiy_w, entitiy_h); /*Toroid*/ if (entity->GetX() < 0 - static_cast<int>(entitiy_w)){ //entity->setVelocityX(-entity->getVelocityX()); entity->setVelocityX(-velocityX); entity_x = w - 1; } if (entity->GetY() < 0 - static_cast<int>(entitiy_h)){ //entity->setVelocityY(-entity->getVelocityY()); entity->setVelocityY(-velocityY); entity_y = h - 1; } /*Toroid*/ if (entity->GetX() > w + static_cast<int>(entitiy_w)){ entity->setVelocityX(velocityX); //entity_x = -static_cast<int>(entitiy_w); //unary operation on unsigned int entity_x = 1; } if (entity->GetY() > h + static_cast<int>(entitiy_h)){ entity->setVelocityY(velocityY); //entity_y = -static_cast<int>(entitiy_h); //unary operation on unsigned int entity_y = 1; } int distance = Vec2DDistanceSq2(vectorGun, vectorCow); const float PanicDistanceSq = 10.0f * 10.0f; int distanceCowRabbit = Vec2DDistanceSq2(vectorCow, vectorRabbit); if (distanceCowRabbit < PanicDistanceSq * 3) { flee(entity, entityRabbit); //printf("flee!"); } else{ seek2(vectorGun); //Seek2 } //Use the distance between cow and gun as collision if (distance < 30){ //set position Weapon/Gun getCaught(); } }
void RFile::seek(DWORD pos) { seek2(pos, FILE_BEGIN); }