void PlayState::init() { _snake = new Snake(); _apple = new RectangleShape(); music.openFromFile("data/FreeKO_Fame.ogg"); music.setLoop(true); music.setRelativeToListener(true); _apple->setSize(Vector2f((float)Game::APPLE_SIZE, (float)Game::APPLE_SIZE)); _apple->setPosition(getRandomPosition()*(float)Game::APPLE_SIZE); setAppleFillColor(); setBackground(); mapBounds = FloatRect(0, 0, Game::SCRN_WIDTH, Game::SCRN_HEIGHT); transparentBackgroundLayer.setPosition(Vector2f(0,0)); transparentBackgroundLayer.setSize(Vector2f(Game::SCRN_WIDTH, Game::SCRN_HEIGHT)); transparentBackgroundLayer.setFillColor(Color(0, 0, 0, 0)); music.setVolume(40.f); music.play(); clock.restart(); }
void ImplAlignandum::shuffle( unsigned int num_iterations, Position window_size) { if (window_size == 0) window_size = getLength(); Position first_from = getFrom(); for (unsigned x = 0; x < num_iterations; ++x) { Position i,j; Position to = getTo(); while (to > first_from ) { Position from = to - window_size; if (from < 0) { from = 0; window_size = to; } for (i = to - 1; i >= from; --i) { j = to - getRandomPosition(window_size) - 1; swap( i, j ); } to -= window_size; } } }
void PlayState::update() { if (clock.getElapsedTime().asMilliseconds() > 125 && !endOfGame) { if (doesFailureOccurs()) { endOfGame = true; return; } setAppleFillColor(); _snake->Move(); if (_snake->GetHeadFloatRect() == _apple->getGlobalBounds()) { _apple->setPosition(getRandomPosition()*(float)Game::APPLE_SIZE); _snake->AddBodyPart(); } clock.restart(); } else if (endOfGame) handleFailure(); }
bool MazeEnv::reset(){ position = getRandomPosition(); lastStartPos = position; ntries = 0; isExploitExperiment = false; return true; }
Asteroid::Asteroid() : m_StartPosition(getRandomPosition()) , m_Velocity(getRandomVelocity()) , m_RotationSpeed(getRandomRotationSpeed()) , m_Speed(getRandomSpeed()) , m_Type(getRandomType()) , m_HasBeenStruck(false) { setupSprite(); setupShape(); }
Sprite* Stratosphere::createCloud() { std::string filename = JsonReader::getInstance()->getPathFromJson("cloud"); auto cloud = Sprite::createWithSpriteFrameName(filename); cloud->setPosition(getRandomPosition().x, getRandomPosition().y); float *speed = new float(this->getRandomSpeed()); cloud->setUserData(speed); #if 0 CCLOG("%s:%f", "cloud position!!!", cloud->getPosition().x); CCLOG("%f:random scale", this->getRandomScale()); CCLOG("%s:%f", "cloud speed!", *(float*)(cloud->getUserData())); #endif cloud->setScale(this->getRandomScale()); cloud->setOpacity(this->getRandomOpacity()); //cloud->setRotation(this->getRandomRotation()); return cloud; }
bool MazeEnv::nextTrial() { isExploitExperiment = !isExploitExperiment; ntries = 0; if (isExploitExperiment) { position = lastStartPos; } else { position = getRandomPosition(); lastStartPos = position; } return true; }
//添加ufo void UfoLayer::addUfo(float dt) { int isaddufo = (int)(CCRANDOM_0_1()*2); do { CC_BREAK_IF(isaddufo); //随机生成ufo int type = (int)(CCRANDOM_0_1()*2+1); String* ufoName = String::createWithFormat("ufo%d.png", type); auto ufoSprite = Sprite::createWithSpriteFrameName(ufoName->getCString()); this->addChild(ufoSprite, 5, type); this->ufoMove(ufoSprite, getRandomPosition(ufoSprite->getContentSize())); //添加到ufo管理容器中去 _ufoVector.pushBack(ufoSprite); }while(0); }
void Snowflake::nextFrame() { if (this->position.y < -0.63) { this->terrain->setCollision(this->position.x, this->position.z); // The particle has reached the end of its lifetime. Rather than kill it // and have to add a new one to the scene (and have the memory overhead) // this one can just respawn randomly again (giving the same effect) this->position = getRandomPosition(); } else { // Move the position by a given speed this->position.y -= 0.01; } }
void Stratosphere::cloudScroll() { for (auto cloud : this->cloudVector) { cloud->setPositionX(cloud->getPositionX() - *(float*)(cloud->getUserData())); #if 0 CCLOG("%s:%f", "cloud position", cloud->getPosition().x); #endif if (cloud->getPositionX() < -(cloud->getContentSize().width)) { Point nextPosition = getRandomPosition(); cloud->setPosition(visibleSize.width + nextPosition.x, nextPosition.y); *(float*)(cloud->getUserData()) = this->getRandomSpeed(); cloud->setScale(getRandomScale()); cloud->setOpacity(getRandomOpacity()); } } }
Vector3 CircularAreaShapeImplementation::getRandomPosition(const Vector3& origin, float minDistance, float maxDistance) { Vector3 position; bool found = false; int retries = 5; while (!found && retries-- > 0) { float distance = System::random((int)(maxDistance - minDistance)) + minDistance; float angle = System::random(360) * Math::DEG2RAD; position.set(origin.getX() + distance * Math::cos(angle), 0, origin.getY() + distance * Math::sin(angle)); found = containsPoint(position); } if (!found) return getRandomPosition(); return position; }
CDotOverlord::CDotOverlord(void) { maxDots = MAX_DOTS; CFlockingDot * tempDot; for(int i = 0; i < maxDots; i++) { tempDot = new CFlockingDot(); setRandomColor((CFlockingDot&)*tempDot); tempDot->position = getRandomPosition(2000,1400); tempDot->velocity.x = getRandom(1,2); tempDot->velocity.y = getRandom(1,2); if((getRandom(0, 3) % 3) == 0) { tempDot->velocity.x*=-1; } if((getRandom(0, 3) % 3) == 0) { tempDot->velocity.y*=-1; } tempDot->maxSpeed = getRandom(3, 12); tempDot->maxForce = getRandom(1, 3); //tempDot->drawTrails = true; dots.push_back(tempDot); if((getRandom(0, 5) % 5) == 0) { int rdot = getRandom(0, dots.size()-1); tempDot->setSeek(dots[rdot]); tempDot->drawTrails = true; setRandomColor((CFlockingDot&)*tempDot); } tempDot->wander(); tempDot->wander(); cout << tempDot->position.toString() << endl; } }
Data::Node* GraphSerializer::createNode( QString id, QString data ) { nodeIdMap.insert( id, nodeIdSeq++ ); return new Data::Node( nodeIdMap.value( id ), data, types->at( 0 ), 0, NULL, getRandomPosition() ); }
Snowflake::Snowflake(Terrain* t, Camera* camera) : Bone(getCircle()) { this->terrain = t; this->position = getRandomPosition(false); this->camera = camera; }