GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


A Paste by Anonymous
#include "CEnemy.h"
#include "mmgr.h"
#include "CSprite.h"


extern GLfloat timeFromStart;
float v,phase;

extern CSprite explode;

CMissile   *missile = NULL;
CModelMD3  missile1;

CMissile *weaptemp2;

CEnemy::CEnemy()
{
 health  = 0;
 shields = 0;

 CVector3 origin (0.0f,0.0f,0.0f);
}

CEnemy::~CEnemy()
{
    delete weaptemp2;
    weaptemp2 = NULL;
}



void CEnemy::Init()
{
    model.LoadModel("base/models/crafts/drakir","drakir",false);
    missile1.LoadModel("base/models/weapons/ffmissile","ffmissile",false);
}


void CEnemy::Die()
{
    glTranslatef(origin.x,origin.y+10,origin.z);
    explode.Draw(18,24);
}

void CEnemy::FireWeapon(CVector3 org, int weapon)
{

   if(timeFromStart - lasttime < 320) 
     return;

    weaptemp2 = new CMissile;

    if(missile)
    {
     missile->prev = weaptemp2;
    }

    weaptemp2->next = missile;
    weaptemp2->prev = NULL;
    missile = weaptemp2;

    switch (weapon) {
    case WP_FF:
        lasttime = timeFromStart;
        weaptemp2->angle           = 270.0f;
        weaptemp2->model           = missile1;
        weaptemp2->distance     = 100.0f;
        weaptemp2->damage       = 100;
        weaptemp2->owner        = 0;
        weaptemp2->origin       = org;
        weaptemp2->speed        = -0.195f;
        weaptemp2->splashdamage = 25;
        weaptemp2->Init(org);        
        weaptemp2->Launch(org, WP_FF);
        break;
    default:
        break;
    }
    

}

void CEnemy::Idle()
{
    
    phase = timeFromStart / (150.0f * M_PI);
    v = sinf( phase );

    if(behavior==1)
        origin.x += v;

    origin.z -= 0.018f * dtime();
    
    FireWeapon(origin,WP_FF);
}


    
    
void CEnemy::Draw()
{
    CMissile *weaptemp2;

    glPushMatrix();
        glTranslatef(origin.x,origin.y,origin.z);
        glRotatef(270.0f,0.0f,1.0f,0.0f);
        model.DrawModel();                
    glPopMatrix();

    

    for(weaptemp2 = missile; weaptemp2 != NULL; weaptemp2 = weaptemp2->next) {    
        weaptemp2->Explode(weaptemp2);
        if(!weaptemp2->dead) 
            weaptemp2->Draw(weaptemp2);

    }
}