#include "ObjectWrapper.h" void InitWObject(VObjectWrapper * o) { o->Type = NONEOBJECTTYPE; o->next = NULL; o->previous = NULL; o->taggedForRemoval = false; o->exploded = 0; } void RunWObject(VObjectWrapper * o, float interval, void * w) { if(o->taggedForRemoval) { CleanUpWObject(o); } else { switch(o->Type) { case VOBJECT: if(o->o->taggedForRemoval) { CleanUpWObject(o); break; } break; case VENEMY: if(o->e->taggedForRemoval) { CleanUpWObject(o); break; } RunEnemy(o->e, interval); break; case VWEAPON: if(o->w->taggedForRemoval) { CleanUpWObject(o); break; } RunWeapon(o->w, interval, w); if(o->w->taggedForRemoval == 2) { o->exploded = true; o->taggedForRemoval = true; if(o->w->Type == WEAPONTYPEBULLET) o->explosionLevel = 2; if(o->w->Type == WEAPONTYPEROCKET) o->explosionLevel = 7; } break; case VEXPLOSION: if(o->ex->markedForRemoval) { CleanUpWObject(o); break; } RunExplosion(o->ex, interval); break; case VPOWERUP: if (o->p->taggedForRemoval) { CleanUpWObject(o); break; } RunPowerup(o->p, interval, w); break; } } } void DrawWObject(VObjectWrapper * o) { switch(o->Type) { case VOBJECT: DrawObject(o->o); break; case VENEMY: DrawEnemy(o->e); break; case VWEAPON: DrawWeapon(o->w); break; case VEXPLOSION: DrawExplosion(o->ex); break; case VPOWERUP: DrawPowerup(o->p); break; } } void CleanUpWObject(VObjectWrapper * o) { if(o->exploded != 1) { switch(o->Type) { case VOBJECT: CleanUpObject(o->o); DisposePtr((Ptr)o->o); break; case VENEMY: CleanUpEnemy(o->e); DisposePtr((Ptr)o->e); break; case VWEAPON: CleanUpWeapon(o->w); DisposePtr((Ptr)o->w); break; case VEXPLOSION: CleanUpExplosion(o->ex); DisposePtr((Ptr)o->ex); break; case VPOWERUP: CleanUpPowerup(o->p); DisposePtr((Ptr)o->p); break; } } o->taggedForRemoval = true; } void AllocateWObject(VObjectWrapper ** o) { *o = (VObjectWrapper *) NewPtrClear(sizeof(VObjectWrapper)); InitWObject(*o); } void AllocateObject(VObjectWrapper * o) { o->o = (VObject *) NewPtrClear(sizeof(VObject)); o->Type = VOBJECT; } void AllocateWeapon(VObjectWrapper * o) { o->w = (VWeapon *) NewPtrClear(sizeof(VWeapon)); o->Type = VWEAPON; } void AllocateEnemy(VObjectWrapper * o) { o->e = (VEnemy *) NewPtrClear(sizeof(VEnemy)); o->Type = VENEMY; } void AllocateExplosion(VObjectWrapper * o) { o->ex = (VExplosion *) NewPtrClear(sizeof(VExplosion)); o->Type = VEXPLOSION; } void AllocatePowerup(VObjectWrapper * o) { o->p = (VPowerup *) NewPtr(sizeof(VPowerup)); o->Type = VPOWERUP; } void WObjectObject(VObjectWrapper * o, VObject ** obj) { switch(o->Type) { case VOBJECT: *obj = o->o; break; case VENEMY: *obj = &o->e->Object; break; case VWEAPON: *obj = &o->w->Object; break; case VEXPLOSION: *obj = NULL; break; case VPOWERUP: *obj = &o->p->Object; break; } }