void generateMass(massParameters *mass, massParameters *limits, massGenerationMode mode) { BACKUP_DEFINITION_LINE(); // assert(mass); assert(limits); switch (mode) { case GEN_ETAM: do { mass->totalMass = randomBetween(limits[MIN].totalMass, limits[MAX].totalMass); mass->eta = randomBetween(limits[MIN].eta, limits[MAX].eta); convertMasses(mass, FROM_ETAM); } while (!isMassBetweenLimits(mass, limits)); break; case GEN_M1M2: do { for (short i = 0; i < NUMBER_OF_BLACKHOLES; i++) { mass->mass[i] = randomBetween(limits[MIN].mass[i], limits[MAX].mass[i]); } convertMasses(mass, FROM_M1M2); } while (!isMassBetweenLimits(mass, limits)); break; case GEN_ETACHIRP: do { mass->chirpMass = randomBetween(limits[MIN].chirpMass, limits[MAX].chirpMass); mass->eta = randomBetween(limits[MIN].eta, limits[MAX].eta); convertMasses(mass, FROM_ETACHIRP); } while (!isMassBetweenLimits(mass, limits)); break; case MASS_GENERATIONS: default: break; } // SAVE_FUNCTION_FOR_TESTING(); }
Asteroid::Asteroid(std::string id, int minradius, int maxradius) : cg::Entity(id), _minradius(minradius), _maxradius(maxradius) { cg::tWindow win = cg::Manager::instance()->getApp()->getWindow(); _posx = randomBetween(0, win.width); _posy = randomBetween(0, win.height); init(); }
void Particle::update(unsigned long elapsed_millis) { double elapsed_seconds = elapsed_millis / 1000.0; if (_position[0] < 0) { _position[0] = randomBetween(0, _winWidth); _position[1] = randomBetween(0, _winHeight); _position[2] = 0; } if (_position[0] > _winWidth) { _position[0] = randomBetween(0, _winWidth); _position[1] = randomBetween(0, _winHeight); _position[2] = 0; } if (_position[1] < 0) { _position[0] = randomBetween(0, _winWidth); _position[1] = randomBetween(0, _winHeight); _position[2] = 0; } if (_position[1] > _winHeight) { _position[0] = randomBetween(0, _winWidth); _position[1] = randomBetween(0, _winHeight); _position[2] = 0; } if (_position[2] < -399) { _position[0] = randomBetween(0, _winWidth); _position[1] = randomBetween(0, _winHeight); _position[2] = -250; } }
void SpaceShipHyperAccelerator::update(double elapsed_seconds) { if(_hyperAccelerating == false) return; cg::Vector2d universeDimensions = _ship->getUniverseDimensions(); _ship->setPosition(cg::Vector2d(randomBetween(0, universeDimensions[0]), randomBetween(0, universeDimensions[1]))); _hyperAccelerating = false; }
void FireParticle::init() { _maxlife = randomBetween(400, 800); _life = _maxlife; _physics = new Physics(_initialPosition, cg::Vector2d(randomBetween(-20, 20), randomBetween(-20, 20)), 0, 0); _physics->setAngle(randomBetween(0, 2 * PI)); }
void Asteroid::explode() { _asteroidsManager->removeParticle(Entity::getId()); _debrisManager->debrisExplosion(_physics->getXPosition(), _physics->getYPosition()); _explosionManager->explosion(_physics->getXPosition(), _physics->getYPosition()); if (_medradius > cg::Properties::instance()->getInt("MINDIMENSION")) { _asteroidsManager->addAst(_medradius/2, _medradius/1.2, _physics->getXPosition() + randomBetween(-20, 20), _physics->getYPosition() + randomBetween(-20, 20)); _asteroidsManager->addAst(_medradius/2, _medradius/1.2, _physics->getXPosition() + randomBetween(-20, 20), _physics->getYPosition() + randomBetween(-20, 20)); } _powerUpsManager->addPowerUp(_physics->getXPosition()+ randomBetween(-20, 20), _physics->getYPosition()+ randomBetween(-20, 20)); }
void Ship2::onKeyPressed(unsigned char key){ switch(key) { case 'w': _thrust = 1; break; case 'a': _rotDirection = LEFT; break; case 'd': _rotDirection = RIGHT; break; case 'f': _isCharging = 1; break; case 'e': if (_mineAmmo > 0) { _mineAmmo--; _weaponsManager->addMine(_playerNumber, _physics->getPosition(), _physics->getAngle()); } break; case 'g': _physics->setPosition(randomBetween(0, _winWidth), randomBetween(0, _winHeight)); break; } }
int main() { srand(time(NULL)); int contador,a,b,resultado,entrada; int acertos = 0; printf("Responda as questões a seguir :\n"); for(contador = 0; contador<Perguntas; contador++) { a= randomBetween(1,50); b= randomBetween(1,50); printf("%d + %d = ",a,b); resultado = a+b; scanf("%d",&entrada); if(entrada == resultado) { acertos++; } } printf("Acertos %d\n Erros %d\n.", acertos, Perguntas-acertos); }
void Particle::update(unsigned long elapsed_millis) { double elapsed_seconds = elapsed_millis / 1000.0; _position -= _velocity * elapsed_seconds; if (_position[0] < 0) { _position[0] = randomBetween(0, _winWidth); _position[1] = randomBetween(_winHeight, _winHeight); } if (_position[0] > _winWidth) { _position[0] = randomBetween(0, _winWidth); _position[1] = randomBetween(_winHeight, _winHeight); } if (_position[1] < 0) { _position[0] = randomBetween(0, _winWidth); _position[1] = randomBetween(_winHeight, _winHeight); } if (_position[1] > _winHeight) { _position[0] = randomBetween(0, _winWidth); _position[1] = randomBetween(_winHeight, _winHeight); } }
void Asteroid::init() { int sides = randomBetween(cg::Properties::instance()->getDouble("MINSIDES"), cg::Properties::instance()->getDouble("MAXSIDES")); _anglestep = cg::Properties::instance()->getDouble("ASTANGSTEP"); int i, r, x, y, z; double theta; _medradius = 0; for (i=0; i < sides; i++) { theta = 2 * PI / sides * i; r = randomBetween(_minradius, _maxradius); _medradius += r; x = (int) -(r * sin(theta)); y = (int) (r * cos(theta)); z = randomBetween(-_maxradius, _maxradius); _points.push_back(cg::Vector3d(x, y, z)); } _points.push_back(_points[0]); _medradius = _medradius / sides; _asteroidsManager = (AsteroidsManager*)cg::Registry::instance()->get("AsteroidsManager"); _weaponsManager = (WeaponsManager*)cg::Registry::instance()->get("WeaponsManager"); _debrisManager = (DebrisManager*) cg::Registry::instance()->get("DebrisManager"); _explosionManager = (ExplosionManager*) cg::Registry::instance()->get("ExplosionManager"); _powerUpsManager = (PowerUpsManager*) cg::Registry::instance()->get("PowerUpsManager"); _ship1 = (Ship*)cg::Registry::instance()->get("Ship"); _ship2 = (Ship2*)cg::Registry::instance()->get("ShipTwo"); _mass = cg::Properties::instance()->getDouble("ASTMASS"); _physics = new Physics(cg::Vector2d(_posx, _posy), cg::Vector2d(randomBetween(-200 + _medradius, 200 - _medradius)*1.5, randomBetween(-200 + _medradius, 200 - _medradius)*1.5), _medradius, _mass); _physics->setAngle(randomBetween(0, 2 * PI)); _topVertex = randomBetween(_medradius/4, _medradius/2); _downVertex = randomBetween(_medradius/4, _medradius/2); _rotx = cg::Properties::instance()->getDouble("ROTX"); _roty = cg::Properties::instance()->getDouble("ROTY"); _rotz = cg::Properties::instance()->getDouble("ROTZ"); }
void Particle::init() { // Read from ini file double min_size = cg::Properties::instance()->getDouble("MIN_SIZE"); double max_size = cg::Properties::instance()->getDouble("MAX_SIZE"); // Creates particle cg::tWindow win = cg::Manager::instance()->getApp()->getWindow(); _winWidth = win.width; _winHeight = win.height; //_position = cg::Vector3d(_winWidth/2,_winHeight/2,0); //_size = cg::Vector3d(20,20,0); _position = cg::Vector3d(randomBetween(0, _winWidth), randomBetween(0, _winHeight), randomBetween(-250,-399)); _size = cg::Vector3d(randomBetween(min_size, max_size), randomBetween(min_size, max_size), randomBetween(min_size, max_size)); //_color = cg::Vector3d(1,1,1); _velocity = cg::Vector3d(randomBetween(-10,10), randomBetween(-10,10), randomBetween(10, 20)); DRAW = true; }
void DirtParticle::update(unsigned long elapsed_millis) { double time = (elapsed_millis / 1000.0); cg::Vector2d carKeyPressed = _car->getArrowKeyPressed(); _velocity[2] += -G*time; _position[2] += _velocity[2] * time - (G*time*time)/2; _position[0] += _velocity[0]*time; _position[1] += _velocity[1]*time; Particle::setPosition(_position); if (_position[2] < -405) { // If the particle drops below the ground, this will replace the particle in it's propper place _velocity[2] = Particle::randomBetween(45,55); _position = _car->getPosition(); _velocity[0] = Particle::randomBetween(-50*(cos(_car->getRotation()*PI/180 + PI/2))-10, -50*(cos(_car->getRotation()*PI/180 + PI/2))+10) ; // x direction _velocity[1] = Particle::randomBetween(-50*(sin(_car->getRotation()*PI/180 + PI/2))-10, -50*(sin(_car->getRotation()*PI/180 + PI/2))+10); // y direction _position[2] = -400; _position[0] = Particle::randomBetween(_position[0]-4, _position[0]+4); _position[1] = Particle::randomBetween(_position[1]-4, _position[1]+4); /* If the speed drops, I want less and less particles to become visible on screen. I will select particles not to be drawn randomly when the speed drops */ /* To do that, as soon as the car gets of track, all particles should be visible, and only then it randomly selects the particles not to be drawn as the speed drops */ if (carKeyPressed[1] == 0 && _trackManager->isOfTrack() == true) { Particle::setDRAW(true); if(_car->getVelocity()*80 < randomBetween(1, 10)) { Particle::setDRAW(false); } } else if (carKeyPressed[1] == 1 && _trackManager->isOfTrack() == true) { // If the car accelerates, all particles should be visible Particle::setDRAW(true); } else if (_trackManager->isOfTrack() == false) { // If the car gets of track, no particle should be visible Particle::setDRAW(false); } Particle::setPosition(_position); } }
char randomAsciiByte() { return static_cast<char>(randomBetween(ASCII_LOW_LIMIT, ASCII_HIGH_LIMIT)); }
Item* Gold::copy(ISceneNode * parent, ISceneManager * manager) { Item* item = new Gold(parent, manager, getNamex(), getModelPath().data(), getImagePath().data(), randomBetween(1, DEFAULT_MAX_GOLD)); cout<<"vo loadamesh"<<endl; IAnimatedMesh * mesh = item->getSceneManager()->getMesh(item->getModelPath().data()); cout<<"vo loada texture "<< getImagePath() <<endl; image_ = item->getSceneManager()->getVideoDriver()->getTexture(getImagePath().data()); item->setImage(image_); printf("%Ponteiro da textura: %p\n",image_); cout<<"vo loada node"<<endl; item->setNode(item->getSceneManager()->addAnimatedMeshSceneNode(mesh, item, ISceneNode::getID())); cout<<"vo geta node"<<endl; item->getAnimatedNode()->setMaterialFlag(video::EMF_LIGHTING, false); item->setScale(core::vector3df(0.02,0.02,0.02)); item->setRotation(core::vector3df(90, 0, 0)); item->setPosition(item->getPosition() + core::vector3df(50,50,50)); return item; }