// Filename : PARTICLE.C // Coded by : Scott Evans // Created/Modified : 15/2/98 // Description : Particle handling routines #include #include // Function : SetParticleBrightness() // Coded by : Scott Evans // Created/Modified : 15/2/98 // Description : Set the colour of a particle // Parameters : p - pointer to particle // r,g,b - red, green and blue values // Returns : None // Notes : None void SetParticleBrightness(PARTICLE *p,BRIGHTNESS *b) { // What type of particle is it switch(p->type_code) { case PTILE: setRGB0(&p->type.ptile,(b->r)>>FP12_4,(b->g)>>FP12_4,(b->b)>>FP12_4); break; case PTILE1: setRGB0(&p->type.ptile1,(b->r)>>FP12_4,(b->g)>>FP12_4,(b->b)>>FP12_4); break; case PTILE8: setRGB0(&p->type.ptile8,(b->r)>>FP12_4,(b->g)>>FP12_4,(b->b)>>FP12_4); break; case PTILE16: setRGB0(&p->type.ptile16,(b->r)>>FP12_4,(b->g)>>FP12_4,(b->b)>>FP12_4); break; default: #ifdef DEBUG_INFO sprintf(fm_string,"(%d) Failed\n",p->type_code); PrintFM(fm_string); #endif break; } } // Function : GetParticleBrightness() // Coded by : Scott Evans // Created/Modified : 15/2/98 // Description : Get the colour of a particle // Parameters : p - pointer to particle // Returns : Brightness of particle // Notes : None CVECTOR *GetParticleBrightness(PARTICLE *p) { static CVECTOR b={0,0,0}; // What type of particle is it switch(p->type_code) { case PTILE: b.r=p->type.ptile.r0; b.g=p->type.ptile.g0; b.b=p->type.ptile.b0; break; case PTILE1: b.r=p->type.ptile1.r0; b.g=p->type.ptile1.g0; b.b=p->type.ptile1.b0; break; case PTILE8: b.r=p->type.ptile8.r0; b.g=p->type.ptile8.g0; b.b=p->type.ptile8.b0; break; case PTILE16: b.r=p->type.ptile16.r0; b.g=p->type.ptile16.g0; b.b=p->type.ptile16.b0; break; default: #ifdef DEBUG_INFO PrintFM("Failed\n"); #endif break; } return(&b); } // Function : SortParticle() // Coded by : Scott Evans // Created/Modified : 15/2/98 // Description : Sort particle into ordering table // Parameters : p - pointer to particle // ot - ordering table // priority - ordering table priority // Returns : None // Notes : None void SortParticle(PARTICLE *p,GsOT *ot,u_word priority,SVECTOR *screen) { switch(p->type_code) { case PTILE: setXY0(&p->type.ptile,screen->vx,screen->vy); GsSortTile(&p->type.ptile,ot,priority); break; case PTILE1: setXY0(&p->type.ptile1,screen->vx,screen->vy); GsSortTile1(&p->type.ptile1,ot,priority); break; case PTILE8: setXY0(&p->type.ptile8,screen->vx,screen->vy); GsSortTile8(&p->type.ptile8,ot,priority); break; case PTILE16: setXY0(&p->type.ptile16,screen->vx,screen->vy); GsSortTile16(&p->type.ptile16,ot,priority); break; default: #ifdef DEBUG_INFO sprintf("Failed (%d)\n",p->type_code); PrintFM(fm_string); #endif break; } } // Function : CreateParticleExplosion() // Coded by : Scott Evans // Created/Modified : 27/2/98 // Description : Create an explosion of particles // Parameters : e - pointer to explosion information // Returns : None // Notes : None void CreateParticleExplosion(PARTICLE_EXPLOSION *e) { u_word i,cx,cy; OBJECT *new; VECTOR vel; // Find centre of area to spread particles cx=e->r.x+(e->r.w>>1); cy=e->r.y+(e->r.h>>1); // Create n particles for(i=0;in;i++) { if((new=CreateObject(e->h,PARTICLE_OBJECT))) { SetObjectsDefaultProperties(new); new->f=e->f; new->wind_effect=1; new->type.p.type_code=PTILE; new->type.p.timer=e->life; new->type.p.type.ptile.w=(rand()%e->maxw)+1; new->type.p.type.ptile.h=(rand()%e->maxh)+1; new->type.p.type.ptile.attribute=0; SetObjectsPosition(new,(rand()%e->r.w)+e->r.x,(rand()%e->r.h)+e->r.y,0); SetObjectsBrightness(new,&e->b); vel.vx=(rand()%e->maxvel.vx)+1; vel.vy=(rand()%e->maxvel.vy)+1; // Decide which way to move particle if(new->screen.vxscreen.vyacceleration.vx=e->acc.vx; new->acceleration.vy=e->acc.vy; new->acceleration.vz=e->acc.vz; new->blink=e->blink; new->blink_rate=e->blink_rate; } } }