Esempio n. 1
0
	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;
		}
	}
Esempio n. 2
0
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;
    }
}