Esempio n. 1
0
SmartPtr<GameObject> Asteroids::CreateAsteroidOre(int _x, int _y)
{
    Animation *anim_ptr = AnimationManager::GetInstance().GetAnimationByName("asteroidOre1");
    SmartPtr<Sprite> asteroidOre_sprite = new Sprite(anim_ptr->GetWidth(), anim_ptr->GetHeight(), anim_ptr);
    asteroidOre_sprite->SetLoopAnimation(true);
    SmartPtr<GameObject> asteroidOre = new AsteroidOre(_x, _y);
    asteroidOre->SetSprite(asteroidOre_sprite);
    asteroidOre->SetScale(0.2f);

    //debug
    if(mConsoleDebug == true) cout << "Created an Ore asteroid: " << asteroidOre->GetPosition().x << "," << asteroidOre->GetPosition().y << endl;

    return asteroidOre;
}
Esempio n. 2
0
void Asteroids::OnObjectRemoved(GameWorld* world, SmartPtr<GameObject> object)
{
    if (object->GetType() == GameObjectType("Asteroid"))
    {
        SmartPtr<GameObject> explosion = CreateExplosion();
        explosion->SetPosition(object->GetPosition());
        explosion->SetRotation(object->GetRotation());
        mGameWorld->AddObject(explosion);

        mAsteroidCount--;

        if(object->GetScale() > 0.2) {
            float newVel[4][2] = { {-1.0,-1.0}, { 1.0,-1.0},
                                   { 1.0, 1.0}, {-1.0, 1.0} };
            GLVector3f obPos = object->GetPosition();

            for(int i = 0; i < 4; i++)
            {
                SmartPtr<GameObject> newAsteroid = CreateAsteroid(obPos.x, obPos.y);
                float f = 5;    //force
                newAsteroid->SetVelocity(GLVector3f(newVel[i][0] * f + (rand() % 4), newVel[i][1] * f + (rand() % 4), 0.0));
                newAsteroid->SetScale(object->GetScale()/2);
                mGameWorld->AddObject(newAsteroid);
                mAsteroidCount++;
            }
        }

        if (mAsteroidCount <= 0)
        {
            SetTimer(500, START_NEXT_LEVEL);
        }
    }
    if (object->GetType() == GameObjectType("AsteroidOre"))
    {
        SmartPtr<GameObject> explosion = CreateExplosion();
        explosion->SetPosition(object->GetPosition());
        explosion->SetRotation(object->GetRotation());
        mGameWorld->AddObject(explosion);

        float newPos[4][2] = { {-1.0,-1.0}, { 1.0,-1.0},
                               { 1.0, 1.0}, {-1.0, 1.0} };
        GLVector3f obPos = object->GetPosition();
        float obRot = object->GetRotation();
        int sep = 5; // how much to separate the ore fromt he position of the asteroid

        for(int i = 0; i < 4; i++)
        {
            SmartPtr<GameObject> ore = CreateOre();
            ore->SetPosition(GLVector3f(obPos.x + newPos[i][0] * sep + (rand() % 4), obPos.y + newPos[i][1] * sep + (rand() % 4), 0.0));
            ore->SetRotation(obRot);
            mGameWorld->AddObject(ore);
        }

        int noA = 1 + (rand() % 3);
        cout << "RAND A: " << noA << endl;

        for (int i = 0; i < noA; i++)
        {
            SmartPtr<GameObject> newAsteroid = CreateAsteroid(obPos.x, obPos.y);
            float rA = rand() % 360; // a random angle
            cout << "RAND ANGLE: " << rA << endl;
            newAsteroid->SetVelocity(GLVector3f( cos(DEG2RAD * rA), sin(DEG2RAD * rA), 0.0));
            cout << "Object Scale: " << object->GetScale() << endl;
            newAsteroid->SetScale(object->GetScale());
            mGameWorld->AddObject(newAsteroid);
            mAsteroidCount++;
        }
    }
}