void Game::addAst(int numOfAsteroids) { std::default_random_engine e(std::chrono::steady_clock::now().time_since_epoch().count()); Asteroid* ast = nullptr; for (int i = 0; i < numOfAsteroids; i++) { switch (e() % 2) { case 0: ast = new Asteroid(glm::vec2(0, 0), glm::vec2(55, 55), &this->GObjects, this->ship, 1400.0f, 25, 100, glm::ivec2(this->width, this->height)); ast->randomize(); break; case 1: ast = new Asteroid(glm::vec2(0, 0), glm::vec2(110, 110), &this->GObjects, this->ship, 1000.0f, 50, 200, glm::ivec2(this->width, this->height)); ast->randomize(); break; default: ast = new Asteroid(glm::vec2(0, 0), glm::vec2(55, 55), &this->GObjects, this->ship, 1400.0f, 25, 100, glm::ivec2(this->width, this->height)); ast->randomize(); break; } this->GObjects.push_back(ast); } }
bool GameManager::loadAsteroidState( TiXmlElement* element, Apollo::SceneObject* parent) { TiXmlElement* childElem = NULL; TiXmlElement* spriteElem = NULL; Asteroid* asteroid; const char* resourcePath; resourcePath = element->Attribute("resource"); if (resourcePath) { asteroid = this->CreateAsteroid(resourcePath); asteroid->LoadState(element, parent); childElem = element->FirstChildElement("Children"); if (childElem) { return loadChildObjects(childElem, asteroid); } return true; } else { throw Apollo::IOError(ERR_APOLLOAPP_ASTEROID_MISSINGATTR); } }
void Game::addAsteroids(int num) { ofPoint randDirection, randSize, randPos; int randSpeed = 0; float randRotation = 0.0, randValue = 0.0; for (int i = 0; i < num; ++i) { randValue = ofRandom(0.0, 1.0); if (randValue > 0.8) { randSize.x = 120; randSize.y = 120; } else if (randValue > 0.5) { randSize.x = 80; randSize.y = 80; } else { randSize.x = 40; randSize.y = 40; } randDirection.x = ofRandom(-1, 1); randDirection.y = ofRandom(-1, 1); normalizePoint(randDirection); randRotation = ofRandom(-0.5, 0.5); randPos.x = ofRandom(0, ofGetWidth()); randPos.y = ofRandom(0, ofGetHeight()); randSpeed = ofRandom(200, 400); Asteroid *asteroid = new Asteroid(); asteroid->initialize(randSize, randSpeed, randPos, randDirection); asteroid->rotationSpeed = randRotation; asteroids.push_back(asteroid); } }
//------------------------------------------------------------- void ofApp::generateAsteroids(int numAsteroids) { float randSize = 0.0f; for ( int i = 0; i < numAsteroids; i++ ) { // Logic to generate the Asteroids in different sizes // these are right now 120, 80, 40 and 20 (minimum) int randValue = ofRandom(0, 3); if(randValue == 2){ randSize = 120; } else { if(randValue == 1) { randSize = 80; } else { randSize = 40; } } int asteroidShape = ofRandom(asteroidsDefinitions.size()); Asteroid* temp = new Asteroid(); temp->setup(asteroidsDefinitions.at(asteroidShape), randSize, ofRandom(100, 250), ofRandom(-PI, PI), ofPoint(ofRandom(0, ofGetWidth()), ofRandom(0, ofGetHeight())), ofPoint(ofRandom(-1, 1), ofRandom(-1, 1)).normalize()); asteroids.push_back(temp); } }
void Asteroid::onDestroy() { sf::Vector2f pos = getPosition(); switch (m_size) { case BIG: // Create 3 medium asteroids for (int i = 0; i < 3; ++i) { Asteroid* asteroid = new Asteroid(MEDIUM, math::rand(0, 360)); asteroid->setPosition(pos); EntityManager::getInstance().addEntity(asteroid); } SoundSystem::playSound("asteroid-break.ogg", 0.5f); break; case MEDIUM: // Create 3 small asteroids for (int i = 0; i < 3; ++i) { Asteroid* asteroid = new Asteroid(SMALL, math::rand(0, 360)); asteroid->setPosition(pos); EntityManager::getInstance().addEntity(asteroid); } SoundSystem::playSound("asteroid-break.ogg", 0.75f); break; default: SoundSystem::playSound("asteroid-break.ogg", 1.f); break; } EntityManager::getInstance().createImpactParticles(getPosition(), 10); }
Asteroid* UnitFactory::createAsteroid( const char *filename, int faction, Flightgroup *fg, int fg_snumber, float difficulty, ObjSerial netcreate ) { _Universe->netLock( true ); Asteroid *ast = new Asteroid( filename, faction, fg, fg_snumber, difficulty ); _Universe->netLock( false ); if (netcreate) //Only allow creating through system files? Doesn't make sense to be able to dynamically generate these. ast->SetSerial( netcreate ); /* * if ( !_Universe->netLocked()) { * NetBuffer netbuf; * addAsteroidBuffer( netbuf, ast); * endBuffer(netbuf); * // NETFIXME: addBuffer for all subunits? * VSServer->broadcast( netbuf, 0, _Universe->activeStarSystem()->GetZone(), CMD_ENTERCLIENT, true); * } * VSServer->invalidateSnapshot(); */ return ast; }
AsteroidFieldChunkServer::AsteroidFieldChunkServer(int asteroidNumber, float chunkSideLength, float astMinSize, float astMaxSize, uint32_t ownerId, osg::Vec3i chunk, GameInstanceServer* ctx, PhysicsEngine* engine) : GameObject(ownerId, ctx) { m_chunkCoord = chunk; m_physicsEngine = engine; std::random_device randDevice; //Generate Asteroid Field //step 1: scatter asteroids. save to AsteroidField m_asteroids = std::make_shared<AsteroidField>(); float astSizeDif = astMaxSize - astMinSize; float asteroidCubeMaxSidelength = astMaxSize * 2; float radius; osg::Vec3f pos; for (int i = 0; i < asteroidNumber; i++) { pos.set( randDevice()*1.0f / randDevice.max() * chunkSideLength, randDevice()*1.0f / randDevice.max() * chunkSideLength, randDevice()*1.0f / randDevice.max() * chunkSideLength); radius = ( ( randDevice() * 1.0f / randDevice.max() ) * ( randDevice() * 1.0f / randDevice.max() ) * astSizeDif + astMinSize ) * 0.5f; m_asteroids->addAsteroid(pos, radius); } //step 2: move asteroids to avoid overlappings (heuristic). save to Level::asteroidField int accuracy = 10; //how often d'you wanna apply heuristic? for (int iterations = 0; iterations < accuracy; iterations++) { std::shared_ptr<AsteroidField> previousScattering = m_asteroids; m_asteroids = std::make_shared<AsteroidField>(); for (int i = 0; i < asteroidNumber; i++) { float favoredDistance = (asteroidCubeMaxSidelength - astMaxSize) / 2 + previousScattering->getAsteroid(i)->getRadius(); float boundingBoxRadius = favoredDistance + astMaxSize / 2; std::list<Asteroid*> candidates = previousScattering->getAsteroidsInBlock(previousScattering->getAsteroid(i)->getPosition(), osg::Vec3f(boundingBoxRadius, boundingBoxRadius, boundingBoxRadius)); osg::Vec3f shift(0, 0, 0); int numberOfCloseAsteroids = 0; for (std::list<Asteroid*>::iterator it = candidates.begin(); it != candidates.end(); it++) { if (*it != previousScattering->getAsteroid(i)) { osg::Vec3f d = previousScattering->getAsteroid(i)->getPosition() - (*it)->getPosition(); float scale = -((d.length() - (*it)->getRadius()) - favoredDistance); if (scale > 0) { d.normalize(); shift += shift + (d * scale *0.5f); //push away from other close asteroids numberOfCloseAsteroids++; } } } m_asteroids->addAsteroid(previousScattering->getAsteroid(i)->getPosition() + shift, previousScattering->getAsteroid(i)->getRadius()); } } // Add asteroids as collision bodies to the engine for (unsigned int i = 0; i < m_asteroids->getLength(); ++i) { Asteroid* currentAst = m_asteroids->getAsteroid(i); unsigned int id = engine->addCollisionSphere(currentAst->getPosition() + GameInstanceServer::chunkToPosition(m_chunkCoord), currentAst->getRadius()); m_physicsIds.push_back(id); } }
Asteroid::Asteroid(int ast_size){ int i, gen, dots, interval, angle, radius, min_radius, delta_radius; Asteroid* ast; Dot d; item = NULL; dots = 3*pow(2,ast_size); interval = 360/dots; min_radius = 10*pow(2,ast_size); delta_radius = 1.25*min_radius; //Generating vertex for(i=0; i<dots; i++){ angle = rand()%interval + i*interval; radius = rand()%delta_radius + min_radius; d.setX(radius*cos(angle*PI/180)); d.setY(radius*sin(angle*PI/180)); loop_vertex.push_back(d); } if(ast_size != SMALL){ //Generating subparts gen = rand()%2+2; while(gen>0){ ast = new Asteroid(ast_size-1); d.setX(rand()%4-2); d.setY(rand()%4-2); ast->setSpeed(d); parts.push_back(ast); gen--; } } if(ast_size == BIG){ //Generating item gen = rand()%(NUM_ITEMS*3); if(gen%3 == 0){ item = new Item(gen/3); item->setSpeed(rand()%360, 0.25); } } //Adjusting centroid centralize(); //setColor(0, 1, (float)(BIG - ast_size)/BIG); setColor(0, (GLfloat)(ast_size*0.125 + 0.75), (GLfloat)(0.25-ast_size*0.125)); setHandling(1); if(rand()%2 == 0){ commands[TURN_LEFT] = true; } else{ commands[TURN_RIGHT] = true; } }
bool LaserPhysicsComponent::testIntersectionWithAsteroid(Laser &laser, Asteroid &asteroid) { D3DXVECTOR3 currLaserPos = laser.getPosition(), lastLaserPos = laser.getLastPosition(), laserDir = laser.getDirection(), asteroidPosition = asteroid.getPosition(); float asteroidRadius = getAsteroidBoundingSphereRadius(asteroid); float asteroidPosToLaserEnd; //check if the laser ray intersects a rough bounding sphere of the asteroid if (!D3DXSphereBoundProbe(&asteroidPosition, asteroidRadius, &lastLaserPos, &laserDir)) { return false; } asteroidPosToLaserEnd = D3DXVec3LengthSq(&(currLaserPos - asteroidPosition)); //if this is true then the laser's current position does not fall within the sphere, and a ray starting at the laser's //current point crosses the circle. A ray starting at the last point already crosses the sphere, so this means both //points are "before" the sphere, along the ray in the direction the laser is travelling. if (asteroidRadius * asteroidRadius < asteroidPosToLaserEnd && D3DXSphereBoundProbe(&asteroidPosition, asteroidRadius, &currLaserPos, &laserDir)) { return false; } //it may have collided. Now check ray against mesh shared_ptr<GraphicsComponent> gfx = asteroid.getGraphicsComponent(); AsteroidGraphicsComponent *asteroidGraphicsComponent = dynamic_cast<AsteroidGraphicsComponent*>(gfx.get()); if (asteroidGraphicsComponent == NULL) { throw "Asteroid didn't have a valid asteroid graphics component!"; } BOOL hit; float dist; D3DXVECTOR3 laserPosRelativeToAsteroid = lastLaserPos - asteroidPosition; D3DXVECTOR3 asteroidScale = asteroid.getScale(); D3DXQUATERNION rotationQuat = asteroid.getRotationQuat(); D3DXMATRIX rot, scale; D3DXMatrixScaling(&scale, 0.8f/asteroidScale.x, 0.8f/asteroidScale.y, 0.8f/asteroidScale.z); D3DXMatrixRotationQuaternion(&rot, &rotationQuat); D3DXVec3TransformCoord(&laserPosRelativeToAsteroid, &laserPosRelativeToAsteroid, &(scale * rot)); D3DXIntersect(asteroidGraphicsComponent->getMesh(), &laserPosRelativeToAsteroid, &laserDir, &hit, NULL, NULL, NULL, &dist, NULL, NULL); float distTravelledSq = D3DXVec3LengthSq(&(currLaserPos - lastLaserPos)); if (!hit || dist * dist > D3DXVec3LengthSq(&(currLaserPos - lastLaserPos))) { return false; } return true; }
/********************************************* * CALLBACK * The main interaction loop of the engine. * This gets called from OpenGL. It give us our * interface pointer (where we get our events from) * as well as a void pointer which we know is our * game class. *********************************************/ void callBack(const Interface *pUI, void *p) { Asteroid *pAsteroid = (Asteroid *)p; //draw it pAsteroid->draw(); pAsteroid->interact(pUI); pAsteroid->advance(); }
void MainScene::ViewportChanged() { for(int idx = 0; idx < _asteroids.size(); idx++) { Asteroid* asteroid = _asteroids[idx]; EntityUtilities::AdjustNodeScale(asteroid->GetSprite(),asteroid,1.01,Viewport::Instance().GetPTMRatio()); } EntityUtilities::AdjustNodeScale(_entity->GetSprite(), _entity, 1.01, Viewport::Instance().GetPTMRatio()); }
void AsteroidManager::splitAsteroid(Asteroid* aAsteroid) { std::vector<Asteroid*>::iterator itr = iAsteroids.begin(); for (; itr != iAsteroids.end(); itr++) { if ((*itr) == aAsteroid) { break; } } //Found aAsteroid in iAsteroids if (itr != iAsteroids.end()) { Asteroid* asteroidMatch = (*itr); if (asteroidMatch == nullptr) { printf ("Error! asteroidMatch %p is null; Cannot complete split! Ignoring operation...\n", aAsteroid); return; } iAsteroids.erase(itr); if (asteroidMatch == nullptr) { printf ("Error! Erase f***s with the pointer :/ \n", aAsteroid); return; } int newTier = asteroidMatch->getTier() - 1; //Only create smaller pieces if split asteroid is big enough if (newTier > 0) { Ogre::Vector3 newDirection = iApplication->generateRandomVector3(); Asteroid* splitA = createAsteroid(newTier, newDirection); Asteroid* splitB = createAsteroid(newTier, -newDirection); placeAsteroid(splitA, asteroidMatch->getNode()->getPosition() + newDirection); placeAsteroid(splitB, asteroidMatch->getNode()->getPosition() + newDirection); splitA->setSpeed(asteroidMatch->getSpeed() * 1.5); splitB->setSpeed(asteroidMatch->getSpeed() * 1.5); splitA->setInvulnTimer(3.0f); splitB->setInvulnTimer(3.0f); iAsteroids.push_back(splitA); iAsteroids.push_back(splitB); } delete asteroidMatch; } //Didn't find matching asteroid (shouldn't happen) else { printf ("Error! Couldn't find Asteroid %p in iAsteroids to split! Ignoring operation...\n", aAsteroid); return; } }
int main() { Asteroid intStash; // 'new' works with built-in types, too. Note // the "pseudo-constructor" syntax: for(int i = 0; i < 25; i++) intStash.add((Asteroid*)new int(i)); for(int j = 0; j < intStash.count(); j++) cout << "intStash[" << j << "] = " << *(int*)intStash[j] << endl; // Clean up: for(int k = 0; k < intStash.count(); k++) delete intStash.remove(k); ifstream in ("PStashTest.cpp"); assure(in, "PStashTest.cpp"); Asteroid stringStash; string line; while(getline(in, line)) stringStash.add((Asteroid*)new string(line)); // Print out the strings: for(int u = 0; stringStash[u]; u++) cout << "stringStash[" << u << "] = " << *(string*)stringStash[u] << endl; // Clean up: for(int v = 0; v < stringStash.count(); v++) delete (string*)stringStash.remove(v); }
void GameScreen::Update(const float time_step) { player.Update(time_step); bool game_over = false; //Update asteroids checking them against player and lasers BSphere player_sphere = player.GetBSphere(); std::list<Asteroid*>::iterator iter = asteroids.begin(); while(iter != asteroids.end()) { Asteroid* ast = iter._Ptr->_Myval; ast->Update(time_step); //Check asteroid is in the play region //if not reset it if(!play_region.Contains(ast->GetBSphere())) { //Move the asteroid elsewhere RepositionAsteroid(ast); } //check against the player if(player_sphere.Contains(ast->GetBSphere())) { //player.AddScore(ast->GetBSphere().GetRadius()); game_over = true; } iter++; } //Do some laser-asteroid checking player.CheckLaserAsteroidCollisions(&asteroids); asteroid_spawn_countdown -= time_step; if(asteroid_spawn_countdown < 0 && asteroids.size() < MAX_ASTEROIDS) { asteroid_spawn_countdown = ASTEROID_SPAWN_INTERVAL; SpawnAsteroid(); } if(game_over) { GameOverScreen *gameover_screen = new GameOverScreen(); gameover_screen->Initialise(player.GetScore()); RustyLib::Framework::ScreenManagement::ScreenManager::Instance().ChangeScreen( gameover_screen); } }
void Bullet::collided(BaseEntity *other) { if (other->entity_type == TYPE_ASTEROID) { Asteroid* asteroid = ((Asteroid*) other); asteroid->reset(true); Vector2 draw_position = position - level_->viewport.position(); game_->sr.render(game_->tft, (int8_t *) bulletShape, 1, RGB(0, 0, 0), old_draw_position_x, old_draw_position_y, rotation, (int) draw_position.x, (int) draw_position.y, rotation); game_->score->add_score(3); level_->removeEntity(this); } }
std::vector<std::shared_ptr<Asteroid>> AsteroidFactory::createSubAsteroids(Asteroid& asteroid) { std::vector<std::shared_ptr<Asteroid>> subAsteroids; auto position = asteroid.getSprite().getPosition(); auto type = asteroid.getType(); auto subType = getSubType(type); if (subType != AsteroidType::Last) createAsteroids(subAsteroids, position, subType); return subAsteroids; }
void ManagerModel::ColissionWall() { int index = 0; while(index < mEntities.size()) { Entity *e = mEntities[index]; if (e->Type() == ENTITY_PLAYER) { Player *player = ((Player*)e); if (player->mPos.x < player->GetRadius() + 10) { player->mPos.x = player->GetRadius() + 10; } if (player->mPos.x + player->GetRadius() > mPlayArea.x - 15) { player->mPos.x = mPlayArea.x - player->GetRadius() - 15;//Sprite is rotated. } if (player->mPos.y < player->GetRadius()) { player->mPos.y = player->GetRadius(); } if (player->mPos.y > mPlayArea.y - player->GetRadius()) { player->mPos.y = mPlayArea.y - player->GetRadius(); } } else if (e->Type() == ENTITY_BULLET) { Shot *bullet = ((Shot*)e); if (bullet->mPos.x > mPlayArea.x) { RemoveEntity(e); --index; } } else if (e->Type() == ENTITY_ASTEROID) { Asteroid *asteroid = ((Asteroid*)e); if (asteroid->mPos.x + asteroid->GetRadius() < 0 || asteroid->mPos.y + asteroid->GetRadius() < 0) { int type = asteroid->mType; RemoveEntity(e); AddAsteroid(type, 2, Vec2(1, 1), Vec2(0)); --index; } } else if (e->Type() == ENTITY_HEALTHPACKAGE) { HealthPackage *healthPackage = ((HealthPackage*)e); if (healthPackage->mPos.x + healthPackage->GetRadius() < 0 || healthPackage->mPos.y + healthPackage->GetRadius() < 0) { RemoveEntity(e); --index; } } ++index; } }
void ManagerModel::AddAsteroid(int type, int length, Vec2 scale, Vec2 startPosition) { for (int i = 0; i != length; ++i) { Asteroid *asteroid = DBG_NEW Asteroid(); asteroid->OnInit(this); asteroid->mType = type; asteroid->SetType(type); asteroid->Cleavage(startPosition, scale); mEntities.push_back(asteroid); for (auto *view : mViews) { view->OnAsteroidSpawned((Asteroid*)asteroid); } } }
//--------------------------------------------------------------------------- int GameScreen::getPositions(float * positions) { Ogre::Vector3 pos = ship->getPos(); positions[0] = pos.x; positions[1] = pos.y; positions[2] = pos.z; Ogre::Quaternion rot = ship->getNode()->getOrientation(); positions[3] = rot.w; positions[4] = rot.x; positions[5] = rot.y; positions[6] = rot.z; pos = alien->getPos(); positions[7] = pos.x; positions[8] = pos.y; positions[9] = pos.z; rot = alien->getNode()->getOrientation(); positions[10] = rot.w; positions[11] = rot.x; positions[12] = rot.y; positions[13] = rot.z; pos = paddle->getPos(); positions[14] = pos.x; positions[15] = pos.y; positions[16] = pos.z; rot = paddle->getNode()->getOrientation(); positions[17] = rot.w; positions[18] = rot.x; positions[19] = rot.y; positions[20] = rot.z; std::deque<GameObject*> oList = *(sim->getObjList()); int astIndex = 3; for(int i = 21; i < 21+7*NUM_ASTEROIDS; i+=7, astIndex++){ Asteroid* ast = (Asteroid*)oList[astIndex]; pos = ast->getPos(); positions[i] = pos.x; positions[i+1] = pos.y; positions[i+2] = pos.z; rot = ast->getNode()->getOrientation(); positions[i+3] = rot.w; positions[i+4] = rot.x; positions[i+5] = rot.y; positions[i+6] = rot.z; } return (21+7*NUM_ASTEROIDS)*sizeof(float); }
void GameScreen::Render(void ) { player.Render(); //Update asteroids std::list<Asteroid*>::iterator iter = asteroids.begin(); while(iter != asteroids.end()) { Asteroid* ast = iter._Ptr->_Myval; ast->Render(); iter++; } }
void ofApp::splitAsteroid(int which) { int asteroidShape = 0; if(asteroids[which]->getSize() > 20) { for(int i = 0; i < (asteroids[which]->getSize()/40)+1; i++) { asteroidShape = ofRandom(asteroidsDefinitions.size()); Asteroid* newAsteroid = new Asteroid(); newAsteroid->setup(asteroidsDefinitions.at(asteroidShape), asteroids[which]->getSize()/2, asteroids[which]->getSpeed(), asteroids[which]->getRotation(), asteroids[which]->getPosition(), ofPoint(-(ofRandom(-1, 1)), ofRandom(-1, 1))); asteroids.push_back(newAsteroid); } } asteroids.erase(asteroids.begin() + which); if(asteroids.size() == 0) { generateAsteroids(ofRandom(4,6)); } //Play sound explosion explosion.play(); //GUI Data Update if(getSpaceShip(1)){ Player1Lifes = ofToString (getSpaceShip(1)->getLifes()); Player1Score = ofToString (getSpaceShip(1)->getPoints()); switch(getSpaceShip(1)->getLifes()) { case 0: serialConnection.writeByte('s'); break; case 1: serialConnection.writeByte('o'); break; case 2: serialConnection.writeByte('w'); break; case 3: serialConnection.writeByte('h'); break; } } if(getSpaceShip(2)){ Player2Lifes = ofToString (getSpaceShip(2)->getLifes()); Player2Score = ofToString (getSpaceShip(2)->getPoints()); switch(getSpaceShip(2)->getLifes()) { case 0: serialConnection.writeByte('f'); break; case 1: serialConnection.writeByte('u'); break; case 2: serialConnection.writeByte('d'); break; case 3: serialConnection.writeByte('t'); break; } } }
float LaserPhysicsComponent::getAsteroidBoundingSphereRadius(Asteroid &asteroid) { D3DXVECTOR3 asteroidScale = asteroid.getScale(); float maxRadius = max<float>(ASTEROID_BASE_X * asteroidScale.x, ASTEROID_BASE_Y * asteroidScale.y); maxRadius = max<float>(maxRadius, ASTEROID_BASE_Z * asteroidScale.z); return maxRadius; }
bool Game::createAsteroids() { // asteroid Asteroid * A; // random values std::mt19937 rng; rng.seed(std::random_device()()); std::uniform_int_distribution<std::mt19937::result_type> xrand(-ceil(limitWidth / 2),ceil(limitWidth / 2)); std::uniform_int_distribution<std::mt19937::result_type> yrand(-ceil(limitHeight / 2),ceil(limitHeight / 2)); int x,y; // create asteroids with random positions for(int i = 0; i < numAsteroids; ++i) { A = new Asteroid(); A->setMass(1); vector<int> p; x = xrand(rng); y = yrand(rng); p.push_back(x); p.push_back(y); A->setPosition(p); A->setVolume(1); theAsteroids.push_back(A); } // Load sprite sheet texture for asteroid if( !( loadAsteroidSpriteSheet() ) ) { cout << "Sprite sheet load fail!" << endl; return false; } else { // default sprite for asteroids int x,y,w,h; x = 0; y = 0; w = asteroidSpriteSheetWidth; h = asteroidSpriteSheetHeight; defaultAsteroidSprite.x = x; defaultAsteroidSprite.y = y; defaultAsteroidSprite.w = w; defaultAsteroidSprite.h = h; } return true; }
Asteroid* UnitFactory::createAsteroid( const char * filename, int faction, Flightgroup* fg, int fg_snumber, float difficulty, ObjSerial netcreate ) { Asteroid * ast = new GameAsteroid( filename, faction, fg, fg_snumber, difficulty ); if( netcreate) { KillDuplicateUnits( netcreate); ast->SetSerial( netcreate); } return ast; }
Error GameScreen::Exit(void ) { player.Exit(); std::list<Asteroid*>::iterator iter = asteroids.begin(); while(iter != asteroids.end()) { Asteroid* ast = iter._Ptr->_Myval; ast->Exit(); delete ast; iter++; } asteroids.clear(); return Error::RL_NO_ERROR; }
void Splinter::init(const Asteroid &parent, float fi) { _rr = parent.R() /2.; x = parent.X() + parent.R() * cos(fi); y = parent.Y() + parent.R() * sin(fi); _rotateSpeed = parent.rotateSpeed(); float dv = 0.05; vx = parent.VX() + dv * cos(fi); vy = parent.VY() + dv * sin(fi); _color = parent.color(); angle = atan2(vx, vy); nvertices = random2().irandom(12,16); _colorMult = parent.colorMult(); applyParams(); }
//--------------------------------------------------------------------------- void GameScreen::updateClient(const Ogre::FrameEvent &evt, float * positions) { ship->setPosition(positions[0], positions[1], positions[2]); ship->getNode()->setOrientation(Ogre::Quaternion(positions[3],positions[4],positions[5],positions[6])); alien->setPosition(positions[7], positions[8], positions[9]); alien->getNode()->setOrientation(Ogre::Quaternion(positions[10],positions[11],positions[12],positions[13])); alien->setCam(positions[7], positions[8] + 25, positions[9] + 40, positions[7], positions[8], positions[9] - 25); alien ->setLight(positions[7], positions[8] + 500, positions[9] + 250); paddle->setPosition(positions[14], positions[15], positions[16]); paddle->getNode()->setOrientation(Ogre::Quaternion(positions[17],positions[18],positions[19],positions[20])); std::deque<GameObject*> oList = *(sim->getObjList()); int astIndex = 3; for(int i = 21; i < 21+7*NUM_ASTEROIDS; i+=7, astIndex++){ Asteroid* ast = (Asteroid*)oList[astIndex]; ast->setPosition(positions[i], positions[i+1], positions[i+2]); ast->getNode()->setOrientation(Ogre::Quaternion(positions[i+3],positions[i+4],positions[i+5],positions[i+6])); } }
void Player::CheckLaserAsteroidCollisions(std::list<Asteroid*>* asteroids) { std::list<Asteroid*>::iterator a_iter = asteroids->begin(); std::list<Asteroid*> a_tbd; std::list<Laser*> l_tbd; while(a_iter != asteroids->end()) { Asteroid *ast = a_iter._Ptr->_Myval; std::list<Laser*>::iterator l_iter = lasers.begin(); while(l_iter != lasers.end()) { Laser *las = l_iter._Ptr->_Myval; if(ast->GetBSphere().Contains(las->GetPosition())) { //The laser is inside the asteroid bsphere a_tbd.push_back(ast); l_tbd.push_back(las); AddScore(ast->GetBSphere().GetRadius()); } l_iter++; } a_iter++; } //Do the deletions std::list<Laser*>::iterator l_iter = l_tbd.begin(); while(l_iter != l_tbd.end()) { lasers.remove(l_iter._Ptr->_Myval); l_iter++; } a_iter = a_tbd.begin(); while(a_iter != a_tbd.end()) { asteroids->remove(a_iter._Ptr->_Myval); a_iter++; } }
bool Player::collided(const Asteroid &rock){ double x,y,s; rock.xysInfo(x,y,s); double ref = s/2; if((x < loc.x - ref) || (x > loc.x + ref)) return false; //too far away if((y < loc.y - ref) || (y > loc.y + ref)) return false; if(pow(loc.x - x,2) + pow(loc.y - y,2) > pow(s,2)) return false; fprintf(stderr,"Player: %f %f, Rock: %f %f\n",loc.x,loc.y,x,y); return true; //assuming worst case }
void BasicApp::setup() { this->setFullScreen(false); // start the sound engine with default parameters engine = createIrrKlangDevice(); if (!engine) { return; } mFont = Font( "Times New Roman", 32 ); mParams = params::InterfaceGl( "App parameters", Vec2i( 200, 400 ) ); game_state = Game_Demo; firingTime = 0; score = 0; numberAsteriods = 0; delay = 20; currentShip.Init(Vec2f((float)getWindowWidth()/2,(float)getWindowHeight()/2)); particleManager.Init_Particles(); enemy.Init(); for (int i=0; i<5;i++) { Ship ship; ship.Init(Vec2f(10+20*i,70)); ships.push_back(ship); } for (int i=0; i<8; i++) { Asteroid asteroid; int shape = rand()%2+1; asteroid.Init(1, 0.5); asteroids.push_back(asteroid); } }