Esempio n. 1
0
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);
    }
}
Esempio n. 2
0
void Game::splitAsteroid(int which) {

    if (asteroids[which]->size.x > 20 && asteroids[which]->size.y > 20) {
        for (unsigned int i = 0; i < (asteroids[which]->size.x / 40) + 1; ++i) {
            Asteroid *asteroid = new Asteroid();
            asteroid->initialize(
                asteroids[which]->size / 2, 
                asteroids[which]->speed, 
                asteroids[which]->position, 
                ofPoint(-(ofRandom(-1, 1)), 
                ofRandom(-1, 1))
            );
			asteroid->rotationSpeed = -asteroids[which]->rotationSpeed;
			asteroids.push_back(asteroid);
        }
    }

    asteroids.erase(asteroids.begin() + which);
    if (asteroids.size() == 0) {
        addAsteroids(ofRandom(4, 6));
    }
}