Exemple #1
0
/** Reset this game object back to the center of the game world. */
void GameObject::Reset()
{
	SetPosition(GLVector3f(0,0,0));
	SetVelocity(GLVector3f(0,0,0));
	SetAcceleration(GLVector3f(0,0,0));
	SetAngle(0);
	SetRotation(0);
}
Exemple #2
0
Life::Life(GLVector3f p, GLVector3f v, GLfloat h, GLfloat r)
	: GameObject("Life", p, v, GLVector3f(), h, r){

	mRotation = 0;
	mPosition.x = rand() / 2;
	mPosition.y = rand() / 2;
	mPosition.z = 0.0;
}
Exemple #3
0
/** Update this spaceship. */
void Drone::Update(int t)
{
    // Calculate seconds since last update
	float dt = t / 1000.0f;

    if(mOrder.GetPtr() != NULL){
        //cout << "HAZ ORDER\n";
        mOrder->Update(t, (GameObject*)this);
    } else {
        //cout << "DOESN'T HAZ ORDER\n";
    }

    // Update Acceleration
    mAcceleration.x = mSpeed*cos(DEG2RAD*mAngle);
    mAcceleration.y = mSpeed*sin(DEG2RAD*mAngle);
    // Update Velocity
//	mVelocity.x += mAcceleration.x * dt;
//	mVelocity.y += mAcceleration.y * dt;
////    mVelocity.z += mAcceleration.z * dt;
    // Update Position
	mPosition.x += mAcceleration.x * dt;
	mPosition.y += mAcceleration.y * dt;
//    mPosition.z += mVelocity.z * dt;
    // Reset acceleration to 0
	mAcceleration = GLVector3f(0,0,0);

	// Update sprite if one exists
	if (mSprite.GetPtr() != NULL) mSprite->Update(t);
	// If in world, wrap position
	if (mWorld) { mWorld->WrapXY(mPosition.x, mPosition.y); }

    //mAngle += 50 * dt;
    mAngle = fmod(mAngle, 360);

    if(mFireTimer > 0) mFireTimer -= t;
}
Exemple #4
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++;
        }
    }
}
Exemple #5
0
/** Construct a new explosion with given position, velocity, angle and rotation. */
Explosion::Explosion(GLVector3f p, GLVector3f v, GLfloat h, GLfloat r)
	: GameObject("Explosion", p, v, GLVector3f(), h, r) {}