HealthyBunny *BunniesManager::GetRandomHealthyBunny(bool ableToReproduce, bool ableToFuck, const IBunny *excludeFromTest) { static Randomizer rand; int baseIndex = rand.GetInt(0, m_maxHealthyBunnyIndex); int index = baseIndex; bool firstIteration = true; while (true) { if (!firstIteration && index == baseIndex) // if checked all and didnt found return NULL; firstIteration = false; if (m_healthyBunnies[index]->IsActive() && m_healthyBunnies[index] != excludeFromTest) { bool found = true; if (ableToReproduce && !m_healthyBunnies[index]->CanReproduce()) found = false; if (ableToFuck && !m_healthyBunnies[index]->CanBeFucked()) found = false; if (found) return m_healthyBunnies[index]; } index++; if (index == m_maxHealthyBunnyIndex + 1) index = 0; } }
void HealthyBunny::RefreshNewTargetPosition(float seconds) { static Randomizer random; float distance = (m_targetPosition - m_position).GetLength(); m_targetPositionRefreshColldown -= seconds; if (m_targetPositionRefreshColldown <= 0.0f || distance <= 0.4f) { if (m_useRunningAwayInitialDirection) { m_targetPosition = m_position + m_runningAwayInitialDirection; m_useRunningAwayInitialDirection = false; } else { m_targetPosition.x = random.GetFloat(-50.0f, 50.0f); m_targetPosition.y = 0.0f; m_targetPosition.z = random.GetFloat(-50.0f, 50.0f); } m_targetPositionRefreshColldown = random.GetFloat( GameProps::RefreshNewTargetPositionFrom, GameProps::RefreshNewTargetPositionTo); } }
void BunniesManager::ResetForNewGame(uint32_t healthyBunniesCount) { static Randomizer random; assert(healthyBunniesCount < MaxBunniesCount); ClearBunnies(); for (uint32_t i = 0; i < MaxBunniesCount; i++) { if (i < healthyBunniesCount) { sm::Vec3 startPos; startPos.x = random.GetFloat(-50.0f, 50.0f); startPos.y = 0.0f; startPos.z = random.GetFloat(-50.0f, 50.0f); m_healthyBunnies[i]->ActivateOnStart(startPos); if (i > m_maxHealthyBunnyIndex) m_maxHealthyBunnyIndex = i; } } // TEST SpawnInfectedBunny(); InfectedBunny *ib = m_infectedBunnies[0]; assert(ib != NULL && ib->IsActive()); ib->SetPosition(sm::Vec3(0, 0, -10)); }
int main(int argc, char *argv[]) { Q_INIT_RESOURCE(icrandomizer); QApplication app(argc, argv); Randomizer randomizer; randomizer.show(); return app.exec(); }
void InfectedBunny::Die() { if (GetState()->GetStateType() == IBunnyState::State_Fucking || GetState()->GetStateType() == IBunnyState::State_Hunting) m_huntingTarget->SetToIdle(); m_dieBaseMatrix = CalcBoneMatrixZ(sm::Vec3(0, 0, 0), m_moveTarget) * sm::Matrix::RotateAxisMatrix(3.1415f, 0, 1, 0); static Randomizer random; m_dieBodyTrajectory.Throw(m_position, sm::Vec3(random.GetFloat(-0.2f, 0.2f), 1, random.GetFloat(-0.2f, 0.2f)).GetNormalized(), random.GetFloat(10.0f, 14.0f), 30.0f); m_dieHeadTrajectory.Throw(m_position, sm::Vec3(random.GetFloat(-0.2f, 0.2f), 1, random.GetFloat(-0.2f, 0.2f)).GetNormalized(), random.GetFloat(10.0f, 14.0f), 30.0f); m_dieBodyAxis = sm::Vec3(random.GetFloat(-1.0f, 1.0f), random.GetFloat(-1.0f, 1.0f), random.GetFloat(-1.0f, 1.0f)).GetNormalized(); m_dieBodyAngleProgress = 0.0f; m_dieBodyAngleSpeed = random.GetFloat(2.0f, 6.0f); m_dieHeadAxis = sm::Vec3(random.GetFloat(-1.0f, 1.0f), random.GetFloat(-1.0f, 1.0f), random.GetFloat(-1.0f, 1.0f)).GetNormalized(); m_dieHeadAngleProgress = 0.0f; m_dieHeadAngleSpeed = random.GetFloat(2.0f, 6.0f); SetState(Dying::GetInstance()); }
uint32 DoRandom(int line, const char *file) { if (_networking && (!_network_server || (NetworkClientSocket::IsValidID(0) && NetworkClientSocket::Get(0)->status != STATUS_INACTIVE))) { printf("Random [%d/%d] %s:%d\n", _frame_counter, (byte)_current_company, file, line); } return _random.Next(); }
void HealthyBunny::SetNewborn() { m_useTransform = true; m_transform = sm::Matrix::IdentityMatrix(); m_growingUpTime = GameProps::GrowingUpTime; static Randomizer rand; m_borningJumpOutVector = sm::Vec3(rand.GetFloat(-1.0f, 1.0), 0.0f, rand.GetFloat(-1.0f, 1.0f)); m_borningJumpOutVector.Normalize(); m_borningJumpOutAxis = m_borningJumpOutVector * sm::Vec3(0, 1, 0); m_borningJumpOutAxis.Normalize(); SetState(Idle::GetInstance()); }
uint32 DoRandom(int line, const char *file) { if (_networking && (!_network_server || (NetworkClientSocket::IsValidID(0) && NetworkClientSocket::Get(0)->status != NetworkClientSocket::STATUS_INACTIVE))) { DEBUG(random, 0, "%08x; %02x; %04x; %02x; %s:%d", _date, _date_fract, _frame_counter, (byte)_current_company, file, line); } return _random.Next(); }
void InfectedBunny::RefreshNewTargetPosition(float seconds) { static Randomizer random; float distance = (m_targetPosition - m_position).GetLength(); m_targetPositionRefreshColldown -= seconds; if (m_targetPositionRefreshColldown <= 0.0f || distance <= 0.4f) { m_targetPositionRefreshColldown = random.GetFloat( GameProps::RefreshNewTargetPositionFrom, GameProps::RefreshNewTargetPositionTo); sm::Vec3 newPos(random.GetFloat(-50.0f, 50.0f), 0.0f, random.GetFloat(-50.0f, 50.0f)); SetDestinationPosition(newPos); } }
int main(void) { Randomizer randomizer; // set for 16 MHz clock, and turn on the LED CPU_PRESCALE(0); LED_CONFIG; LED_ON; // initialize the USB, and then wait for the host // to set configuration. If the Teensy is powered // without a PC connected to the USB port, this // will wait forever. usb_init(); while (!usb_configured()) /* wait */ ; _delay_ms(1000); while (1) { // wait for the user to run their terminal emulator program // which sets DTR to indicate it is ready to receive. while (!(usb_serial_get_control() & USB_SERIAL_DTR)) /* wait */ ; // discard anything that was received prior. Sometimes the // operating system or other software will send a modem // "AT command", which can still be buffered. usb_serial_flush_input(); //Get 128 bits of debiased entropy from the ADCs (using Von Neumann debias) //and add that entropy to the randomizer (cryptographic entropy mixer). //Repeat 4 times. for(int i=0; i<4; i++){ randomizer.add(Entropy::get_entropy()); } //Get cryptographically mixed and decorrelated random data from the randomizer RandomData random_data = randomizer.get(); for(int i=0; i<16; i++){ //Send the random data over the USB serial device usb_serial_putchar(random_data.bytes[i]); } LED_TOGGLE; } }
void Hunting::Update(IBunny *bunny, float time, float seconds) { assert(bunny != NULL); InfectedBunny *ibunny = dynamic_cast<InfectedBunny*>(bunny); assert(ibunny != NULL); HealthyBunny *hbunny = ibunny->GetHuntingTarget(); assert(hbunny != NULL); if (!hbunny->CanBeFucked()) // make sure if bunny can be still f****d { static Randomizer random; ibunny->RestingAfterFuckingProgress().SetTicker(random.GetFloat(GameProps::RestingAfterTryingToFuckTimeFrom, GameProps::RestingAfterTryingToFuckTimeTo)); ibunny->SetState(RestingAfterFucking::GetInstance()); return; } sm::Vec3 moveTarget = (hbunny->GetPosition() - ibunny->GetPosition()); moveTarget.y = 0.0f; if (moveTarget.GetLength() <= 0.4f * 2) { ibunny->FuckingProgress().Reset(); ibunny->SetState(F*****g::GetInstance()); hbunny->SetToBeeingFucked(ibunny); } if (moveTarget.GetLength() <= GameProps::RunningAwayDistance && !ibunny->DidTellToGTFO()) { hbunny->GetTheFuckOut(ibunny); ibunny->DidTellToGTFO() = true; } else { moveTarget.Normalize(); ibunny->m_currentAnim = ibunny->m_runAnim; ibunny->SetDestinationPosition(hbunny->GetPosition()); ibunny->UpdateMovement(seconds, GameProps::InfectedBunnyHuntingSpeed, GameProps::DelayBetweenRunJump); } }
int main() { Tree *tree = new Tree(); XMLParser xmlParse("decisions.xml", tree); Randomizer r; std::string input; std::string searchType = "depthFirstSearch"; bool running = true; while (running == true) { std::cout << "Press 1 to print out XML tree of ""decisions.xml""\n"; std::cout << "Press 2 to change search type: *depthFirstSearch or breadthFirstSearch\n"; std::cout << "Press 3 to receive a response based on input\n"; std::cout << "Press q to Exit \n"; std::getline(std::cin, input); if (input == "1") { tree->printTree(tree->getRoot()); } if (input == "2") { std::cout << "Enter type: depthFirstSearch or breadthFirstSearch: "; std::getline(std::cin, searchType); } if (input == "3") { std::cout << "Press q to Escape Sequence \n"; bool getResponses = true; std::string behaviorInput; while (getResponses) { std::cout << "Enter a Behavior: "; std::getline(std::cin, behaviorInput); std::string response = r.getResponse(tree, behaviorInput, searchType); std::cout << "Response: " << response << '\n'; if (behaviorInput == "q") { getResponses = false; } } } if (input == "q") { running = false; return 0; } } }
//------------------------------------------------------------------------------ int main(int ac,char * av[]) { int errcode = 0; adicpp::AutoInitializer autoInitializer(ac,av); autoInitializer = autoInitializer; try { union { intptr_t i; uintptr_t u; }; ksys::stdErr.fileName(SYSLOG_DIR("mskey/") + "mskey.log"); ksys::Config::defaultFileName(SYSCONF_DIR("") + "mskey.conf"); utf8::String expirationDate("00.00.0000"); for( u = 1; u < argv().count(); u++ ){ if( argv()[u].compare("--version") == 0 ){ stdErr.debug(9,utf8::String::Stream() << mskey_version.tex_ << "\n"); fprintf(stdout,"%s\n",mskey_version.tex_); continue; } if( argv()[u].compare("--expiration-date") == 0 && u + 1 < argv().count() ){ expirationDate = argv()[++u]; continue; } utf8::String keyAdd; if( gettimeofday() > timeFromTimeString("13.06.2008",false) ){ Randomizer rnd; keyAdd = utf8::int2Str(rnd.random()); } utf8::String key(getMachineCryptedUniqueKey(argv()[u] + keyAdd,expirationDate)); fprintf(stdout,(const char *) key.getANSIString()); copyStrToClipboard(key); } } catch( ExceptionSP & e ){ e->writeStdError(); errcode = e->code() >= errorOffset ? e->code() - errorOffset : e->code(); } catch( ... ){ } return errcode; }
void F*****g::Update(IBunny *bunny, float time, float seconds) { assert(bunny != NULL); InfectedBunny *ibunny = dynamic_cast<InfectedBunny*>(bunny); assert(ibunny != NULL); HealthyBunny *hbunny = ibunny->GetHuntingTarget(); assert(hbunny != NULL); if (!hbunny->IsActive() || hbunny->GetState()->GetStateType() == IBunnyState::State_Dying) // make sure if bunny can be still f****d { static Randomizer random; ibunny->RestingAfterFuckingProgress().SetTicker(random.GetFloat(GameProps::RestingAfterTryingToFuckTimeFrom, GameProps::RestingAfterTryingToFuckTimeTo)); ibunny->SetState(RestingAfterFucking::GetInstance()); return; } ibunny->m_fuckProgressTime += seconds; if (ibunny->m_fuckMoveCycles < GameProps::FuckingHipCycles && ibunny->m_fuckProgressTime >= ibunny->m_fuckAnimEnd) { ibunny->m_fuckMoveCycles++; ibunny->m_fuckProgressTime = ibunny->m_fuckAnimStart; } ibunny->m_currentAnim = ibunny->m_fuckAnim; ibunny->m_currentAnimTime = ibunny->m_fuckProgressTime; ibunny->FuckingProgress().Progress(seconds); if (ibunny->m_currentAnimTime >= ibunny->m_fuckAnim->GetAnimLength()) { static Randomizer random; ibunny->RestingAfterFuckingProgress().SetTicker(random.GetFloat(GameProps::RestingAfterFuckingTimeFrom, GameProps::RestingAfterFuckingTimeTo)); ibunny->SetState(RestingAfterFucking::GetInstance()); hbunny->StartChangingToInfected(); } }
int main(int argc, char *argv[]) { if (argc != 5) { cerr << "usage: sample num str_len_min str_len_max times\n"; exit(1); } int n = atoi(argv[1]); int str_len_min = atoi(argv[2]); int str_len_max = atoi(argv[3]); string char_set = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"; Randomizer random; vector<int> len_vec; for (int i = 0; i < n; i++) { len_vec.push_back(random.randint(str_len_min, str_len_max)); } random.srand(); vector<string> str_seq; for (int i = 0; i < n; i++) { str_seq.push_back(random.sample(char_set, len_vec[i])); } random.srand(); n = atoi(argv[4]); for (int i = 0; i < n; i++) { cout << random.choice(str_seq) << '\n'; } return 0; }
sm::Vec3 BunniesManager::GetRandomRespawnPosition() { static Randomizer rand; sm::Vec3 position; int side = rand.GetInt(0, 3); switch (side) { case 0: // left position = sm::Vec3(-50.0f, 0, rand.GetFloat(-50.0f, 50.0f)); break; case 1: // right position = sm::Vec3(50.0f, 0, rand.GetFloat(-50.0f, 50.0f)); break; case 2: // top position = sm::Vec3(rand.GetFloat(-50.0f, 50.0f), 0, 50.0f); break; case 3: // bottom position = sm::Vec3(rand.GetFloat(-50.0f, 50.0f), 0, -50.0f); break; } return position; }
Node::ptr Node::make_random(Randomizer& random) { int r = random.NextInt(0, 5); switch (r) { case 0: return ControlBlock::make(); case 1: return CodeBlock::make(); case 2: return CodeBlock::make(); case 3: return Command::make(Command::BLANK); case 4: return Command::make(Command::BLANK); case 5: return Command::make(Command::BLANK); default: //supress warning return nullptr; } }
void Taxi::Update(float time, float seconds) { //m_position.y = sinf(time * (((m_speed + 1) / 13.0f) * 1.0f)) * 0.5f + 0.5f; //m_position.y *= 0.5f; sm::Vec3 oldPos = m_position; if (IsOccupied()) { m_timeLeft -= seconds; if (m_timeLeft < 0.0f) m_timeLeft = 0.0f; } sm::Vec3 turnPivot; sm::Matrix turnMatrix; float pivotDistance = 0.0f; m_speed += m_acc * 5.0f * seconds; static float maxSpeed = 14.0f; if (m_acc == 0.0f) { m_speed -= MathUtils::Min(MathUtils::Abs(m_speed), 8.0f * seconds) * MathUtils::Sign(m_speed); } if (m_speed > 0.0f && m_acc == -1.0f) { m_speed -= MathUtils::Min(MathUtils::Abs(m_speed), 12.0f * seconds) * MathUtils::Sign(m_speed); } m_speed = MathUtils::Clamp(m_speed, -maxSpeed / 4, maxSpeed); SoundManager::GetInstance()->SetEnginePitch((MathUtils::Abs(m_speed) / maxSpeed) * 1.0f + 1.0f); m_wheelsAngle += 2.0f * m_turnValue * seconds; m_wheelsAngle = MathUtils::Clamp(m_wheelsAngle, -MathUtils::PI4, MathUtils::PI4); if (m_wheelsAngle != 0.0f) { if (m_wheelsAngle < 0.0) { pivotDistance = m_backFrontWheelsDistance / tanf(fabs(m_wheelsAngle)); turnPivot = sm::Vec3(m_baseBackRightWheelPosition.x + pivotDistance, 0, m_baseBackRightWheelPosition.z); } else { pivotDistance = m_backFrontWheelsDistance / tanf(fabs(m_wheelsAngle)); turnPivot = sm::Vec3(m_baseBackLeftWheelPosition.x - pivotDistance, 0, m_baseBackLeftWheelPosition.z); } float angleSpeed = m_speed / (2.0f * MathUtils::PI * MathUtils::Abs(turnPivot.x)); sm::Matrix turnMatrixNormal = sm::Matrix::RotateAxisMatrix( angleSpeed * (MathUtils::PI * 2.0f) * seconds * MathUtils::Sign(m_wheelsAngle), 0, 1, 0); turnPivot = m_worldMatrix * turnPivot; turnPivot.y = 0.0f; turnMatrix = sm::Matrix::TranslateMatrix(turnPivot) * turnMatrixNormal * sm::Matrix::TranslateMatrix(turnPivot.GetReversed()); sm::Vec3 prevCarDirection = m_carDirection; m_carDirection = turnMatrixNormal * m_carDirection; m_carDirection.Normalize(); float angleDiff = sm::Vec3::GetAngle(prevCarDirection, m_carDirection); m_wheelsAngle -= angleDiff * MathUtils::Sign(m_wheelsAngle); m_position = turnMatrix * m_position; } else m_position += m_carDirection * m_speed * seconds; sm::Matrix newWorldMatrix = sm::Matrix::TranslateMatrix(m_position) * sm::Matrix::CreateLookAt(m_carDirection.GetReversed(), sm::Vec3(0, 1, 0)); sm::Vec3 boundsTopLeftWorldOld = m_worldMatrix * m_boundsTopLeft; sm::Vec3 boundsBottomLeftWorldOld = m_worldMatrix * m_boundsBottomLeft; sm::Vec3 boundsTopRightWorldOld = m_worldMatrix * m_boundsTopRight; sm::Vec3 boundsBottomRightWorldOld = m_worldMatrix * m_boundsBottomRight; sm::Vec3 boundsTopLeftWorldNew = newWorldMatrix * m_boundsTopLeft; sm::Vec3 boundsBottomLeftWorldNew = newWorldMatrix * m_boundsBottomLeft; sm::Vec3 boundsTopRightWorldNew = newWorldMatrix * m_boundsTopRight; sm::Vec3 boundsBottomRightWorldNew = newWorldMatrix * m_boundsBottomRight; sm::Vec3 collisionNormal; sm::Vec3 collisionPoint; if (Street::Instance->GetCollistion(boundsTopLeftWorldOld, boundsTopLeftWorldNew, collisionPoint, collisionNormal)) { if (m_speed > 4.0f) { static Randomizer random; SoundManager::GetInstance()->PlaySound((SoundManager::Sound)random.GetInt(0, 2)); } float dot = sm::Vec3::Dot(collisionNormal, m_carDirection.GetReversed()); if (dot > 0.8 && m_speed > 3.0f) m_speed = -3.0f; else m_speed *= 1.0f - sm::Vec3::Dot(collisionNormal, m_carDirection.GetReversed()); collisionPoint += collisionNormal * 0.01f; sm::Vec3 toCollisionTarget = collisionPoint - boundsTopLeftWorldOld; sm::Vec3 fromCollisionTarget = sm::Vec3::Reflect(collisionNormal, toCollisionTarget); sm::Vec3 correntPosition = boundsTopLeftWorldOld + toCollisionTarget + fromCollisionTarget; sm::Vec3 deltaMove = collisionPoint - boundsTopLeftWorldOld; m_carDirection = (collisionPoint - boundsBottomLeftWorldOld).GetNormalized(); m_position = oldPos + deltaMove; m_worldMatrix = sm::Matrix::TranslateMatrix(m_position) * sm::Matrix::CreateLookAt(m_carDirection.GetReversed(), sm::Vec3(0, 1, 0)); } else if (Street::Instance->GetCollistion(boundsTopRightWorldOld, boundsTopRightWorldNew, collisionPoint, collisionNormal)) { if (m_speed > 4.0f) { static Randomizer random; SoundManager::GetInstance()->PlaySound((SoundManager::Sound)random.GetInt(0, 2)); } float dot = sm::Vec3::Dot(collisionNormal, m_carDirection.GetReversed()); if (dot > 0.8 && m_speed > 3.0f) m_speed = -3.0f; else m_speed *= 1.0f - sm::Vec3::Dot(collisionNormal, m_carDirection.GetReversed()); collisionPoint += collisionNormal * 0.01f; sm::Vec3 toCollisionTarget = collisionPoint - boundsTopRightWorldOld; sm::Vec3 fromCollisionTarget = sm::Vec3::Reflect(collisionNormal, toCollisionTarget); sm::Vec3 correntPosition = boundsTopRightWorldOld + toCollisionTarget + fromCollisionTarget; sm::Vec3 deltaMove = collisionPoint - boundsTopRightWorldOld; m_carDirection = (collisionPoint - boundsBottomRightWorldOld).GetNormalized(); m_position = oldPos + deltaMove; m_worldMatrix = sm::Matrix::TranslateMatrix(m_position) * sm::Matrix::CreateLookAt(m_carDirection.GetReversed(), sm::Vec3(0, 1, 0)); } /*else if (Street::Instance->GetCollistion(boundsBottomRightWorldOld, boundsBottomRightWorldNew, collisionPoint, collisionNormal)) { if (m_speed > 4.0f) { static Randomizer random; SoundManager::GetInstance()->PlaySound((SoundManager::Sound)random.GetInt(0, 2)); } float dot = sm::Vec3::Dot(collisionNormal, m_carDirection.GetReversed()); if (dot > 0.8 && m_speed > 3.0f) m_speed = -3.0f; else m_speed *= 1.0f - sm::Vec3::Dot(collisionNormal, m_carDirection.GetReversed()); collisionPoint += collisionNormal * 0.01f; sm::Vec3 toCollisionTarget = collisionPoint - boundsBottomRightWorldOld; sm::Vec3 fromCollisionTarget = sm::Vec3::Reflect(collisionNormal, toCollisionTarget); sm::Vec3 correntPosition = boundsBottomRightWorldOld + toCollisionTarget + fromCollisionTarget; sm::Vec3 deltaMove = collisionPoint - boundsBottomRightWorldOld; m_carDirection = (boundsTopRightWorldOld - collisionPoint).GetNormalized(); m_position = oldPos + deltaMove; m_worldMatrix = sm::Matrix::TranslateMatrix(m_position) * sm::Matrix::CreateLookAt(m_carDirection.GetReversed(), sm::Vec3(0, 1, 0)); }*/ else if (Street::Instance->GetCollistion(boundsBottomRightWorldOld, boundsBottomRightWorldNew, collisionPoint, collisionNormal)) { if (m_speed > 4.0f) { static Randomizer random; SoundManager::GetInstance()->PlaySound((SoundManager::Sound)random.GetInt(0, 2)); } m_position = oldPos + collisionNormal * 0.1f; m_speed = 0.0f; m_worldMatrix = sm::Matrix::TranslateMatrix(m_position) * sm::Matrix::CreateLookAt(m_carDirection.GetReversed(), sm::Vec3(0, 1, 0)); } else if (Street::Instance->GetCollistion(boundsBottomLeftWorldOld, boundsBottomLeftWorldNew, collisionPoint, collisionNormal)) { if (m_speed > 4.0f) { static Randomizer random; SoundManager::GetInstance()->PlaySound((SoundManager::Sound)random.GetInt(0, 2)); } m_position = oldPos + collisionNormal * 0.1f; m_speed = 0.0f; m_worldMatrix = sm::Matrix::TranslateMatrix(m_position) * sm::Matrix::CreateLookAt(m_carDirection.GetReversed(), sm::Vec3(0, 1, 0)); } else m_worldMatrix = newWorldMatrix; m_frontRightWheel->Transform() = m_frontRightWheel->m_worldMatrix * sm::Matrix::RotateAxisMatrix(m_wheelsAngle, 0, 1, 0) * m_frontRightWheel->m_worldInverseMatrix; m_frontLeftWheel->Transform() = m_frontLeftWheel->m_worldMatrix * sm::Matrix::RotateAxisMatrix(m_wheelsAngle, 0, 1, 0) * m_frontLeftWheel->m_worldInverseMatrix; }
std::string random_chars(int length) { std::string result; while(length --) result.push_back(charset[char_rand.next()]); return result; }
int main() { sf::RenderWindow window(sf::VideoMode(800, 600), "Space Invaders"); //STARTING SETTINGS AudioManager audioManager; BulletManager bulletManager; EnemyManager enemyManager; Randomizer random; TimeManager time; Menu mainMenu; Interface mainInterface; Player player(400, 500); Player *playerWsk = &player; //CONTROL VARIABLES bool menu = true; bool init = false; bool menuMusic = false; bool stageTwo = false; mainMenu.loadData(); while (window.isOpen()) { if(menu == false) { if(init == false) { audioManager.stopMenu(); menuMusic = false; player.setHealth(3); //CREATING ENEMIES and INITILIAZING enemyManager.addEnemies(); //2 ROWS random.initialize(); audioManager.playMusic(); init = true; } if((stageTwo == false) && (mainInterface.getScore() >= 280)) { enemyManager.addEnemiesMedium(); stageTwo = true; } if((mainInterface.getScore() >= 560)) { audioManager.stopMusic(); init = false; menu = true; } time.updateShoot(); time.updateRandomShoot(); // REFRESHING WINDOW // ALL PHYSICS HERE while(time.getAccumulator() > time.getUps()) { time.updateAccumulator(); player.keyboardControl(time.getUps(), bulletManager, time.getShootTimer(), time, audioManager); enemyManager.controlEnemies(random, bulletManager, time); bulletManager.controlBullets(time.getUps()); //COLLISIONS bulletManager.checkPlayerCollisions(playerWsk); enemyManager.updateDead(bulletManager); player.gameOver(audioManager, menu, init); } //SIMPLE EVENTS sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } mainInterface.checkRecords(mainMenu); //DRAWING window.clear(); mainInterface.drawText(window, player.getHealth()); enemyManager.drawEnemies(window); window.draw(player.getSprite()); bulletManager.drawBullets(window); window.display(); if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { window.close(); } time.restartAccumulator(); } else { if(menuMusic == false) { audioManager.playMenu(); menuMusic = true; } enemyManager.clearAll(); bulletManager.clearAll(); time.clearAll(); mainInterface.clearScore(); mainMenu.keyboardControl(window, menu); sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } window.clear(); mainMenu.drawMenu(window); window.display(); if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { window.close(); } } } return EXIT_SUCCESS; }
/** * (Re)set the state of the random number generators. * @param seed the new state */ void SetRandomSeed(uint32 seed) { _random.SetSeed(seed); _interactive_random.SetSeed(seed * 0x1234567); }
static FORCEINLINE uint32 Random() { return _random.Next(); }
void President::randomStatFunc() { Randomizer *randomizer; randomizer = Randomizer::getInstance(); randomStats.push_back("foodPrice"); randomStats.push_back("goodsPrice"); randomStats.push_back("techPrice"); randomStats.push_back("nuclearPrice"); randomStats.push_back("spacePrice"); randomStats.push_back("spyPrice"); randomStats.push_back("patriotismTax"); std::map<std::string, std::string> posStatsText; posStatsText.insert(std::pair<std::string, std::string>("foodPrice", "Food Price -3")); posStatsText.insert(std::pair<std::string, std::string>("goodsPrice", "Goods Price -3")); posStatsText.insert(std::pair<std::string, std::string>("techPrice", "Tech Price -3")); posStatsText.insert(std::pair<std::string, std::string>("nuclearPrice", "Nuclear weapons \n20% cheaper")); posStatsText.insert(std::pair<std::string, std::string>("spacePrice", "Space program \n20% cheaper")); posStatsText.insert(std::pair<std::string, std::string>("spyPrice", "Spy network \n20% cheaper")); posStatsText.insert(std::pair<std::string, std::string>("patriotismTax", "Tax cuts give \n+1 extra patriotism")); std::map<std::string, std::string> negStatsText; negStatsText.insert(std::pair<std::string, std::string>("foodPrice", "Food price +2")); negStatsText.insert(std::pair<std::string, std::string>("goodsPrice", "Goods price +2")); negStatsText.insert(std::pair<std::string, std::string>("techPrice", "Tech price +2")); negStatsText.insert(std::pair<std::string, std::string>("nuclearPrice", "Nuclear weapons \n20% more expensive")); negStatsText.insert(std::pair<std::string, std::string>("spacePrice", "Space program \n20% more expensive")); negStatsText.insert(std::pair<std::string, std::string>("spyPrice", "Spy network \n20% more expensive")); negStatsText.insert(std::pair<std::string, std::string>("popEatsMore", "Population eats \n10% more food")); std::map<std::string, float> posStatMap; posStatMap.insert(std::pair<std::string,float>("foodPrice", -3.f)); posStatMap.insert(std::pair<std::string,float>("goodsPrice", -3.f)); posStatMap.insert(std::pair<std::string,float>("techPrice", -3.f)); posStatMap.insert(std::pair<std::string,float>("nuclearPrice", 0.8f)); posStatMap.insert(std::pair<std::string,float>("spacePrice",0.8f)); posStatMap.insert(std::pair<std::string,float>("spyPrice", 0.8f)); posStatMap.insert(std::pair<std::string,float>("patriotismTax", 1.f)); std::map<std::string, float> negStatMap; negStatMap.insert(std::pair<std::string,float>("foodPrice", 2.f)); negStatMap.insert(std::pair<std::string,float>("goodsPrice", 2.f)); negStatMap.insert(std::pair<std::string,float>("techPrice", 2.f)); negStatMap.insert(std::pair<std::string,float>("nuclearPrice", 1.2f)); negStatMap.insert(std::pair<std::string,float>("spacePrice", 1.2f)); negStatMap.insert(std::pair<std::string,float>("spyPrice", 1.2f)); negStatMap.insert(std::pair<std::string,float>("popEatsMore", 1.1f)); int random = ( randomizer->randomNr(randomStats.size(),0) ); mValues.insert(std::pair<std::string,float>(randomStats[random], posStatMap.find(randomStats[random])->second)); mPositiveStats.push_back(posStatsText.find(randomStats[random])->second); randomStats[random] = randomStats.back(); randomStats.pop_back(); random = ( randomizer->randomNr(randomStats.size(),0) ); mValues.insert(std::pair<std::string,float>(randomStats[random], posStatMap.find(randomStats[random])->second)); mPositiveStats.push_back(posStatsText.find(randomStats[random])->second); randomStats[random] = randomStats.back(); randomStats.pop_back(); randomStats.push_back("popEatsMore"); random = ( randomizer->randomNr(randomStats.size(),0) ); if(randomStats[random] == "patriotismTax") { randomStats[random] = randomStats.back(); randomStats.pop_back(); random = ( randomizer->randomNr(randomStats.size(),0) ); } mValues.insert(std::pair<std::string,float>(randomStats[random], negStatMap.find(randomStats[random])->second)); mNegativeStats.push_back(negStatsText.find(randomStats[random])->second); randomStats[random] = randomStats.back(); randomStats.pop_back(); for(std::vector<std::string>::iterator it = randomStats.begin(); it != randomStats.end(); it++) { mValues.insert(std::pair<std::string, float>((*it), 0.f)); } randomStats.clear(); }
static inline uint32 InteractiveRandomRange(uint32 max) { return _interactive_random.Next(max); }
static inline uint32 InteractiveRandom() { return _interactive_random.Next(); }
static FORCEINLINE uint32 InteractiveRandom() { return _interactive_random.Next(); }
static FORCEINLINE uint32 RandomRange(uint32 max) { return _random.Next(max); }
static inline uint32 Random() { return _random.Next(); }
static FORCEINLINE uint32 InteractiveRandomRange(uint32 max) { return _interactive_random.Next(max); }
static inline uint32 RandomRange(uint32 max) { return _random.Next(max); }