#include "WorldManager.h" void InitWorld(VWorld * world) { InitCamera(&world->Camera); InitPlayer(&world->Player); LoadLevel(&world->Levels[0], "level", world); InitObject(&world->CrossHair); world->CrossHair.Position.x = 0.0; world->CrossHair.Position.y = 0.0; world->CrossHair.Position.z = -1.7; BuildCrossHairModel(&world->CrossHair.Model); /*InitObject(&world->Environment); BuildGrassModel(&world->Environment.Model); world->Environment.Position.x = 0.0; world->Environment.Position.y = -2.0; world->Environment.Position.z = 0.0; InitObject(&world->Walls); BuildWallsModel(&world->Walls.Model); world->Walls.Position.x = 0.0; world->Walls.Position.y = -2.0; world->Walls.Position.z = 0.0; AllocateWObject(&world->Objects); AllocateObject(world->Objects); if (world->Objects->o != NULL) { Vector targetPos; InitObject(world->Objects->o); BuildTargetModel(&world->Objects->o->Model); targetPos.x = 2.0; targetPos.y = 1.0; targetPos.z = -7.0; MoveObjectToPoint(world->Objects->o, &targetPos); CalculateRadius(world->Objects->o); } AllocateWObject(&world->Objects->next); AllocateEnemy(world->Objects->next); InitEnemy(world->Objects->next->e, TestAI, world); world->Objects->next->previous = world->Objects; AllocateWObject(&world->Objects->next->next); AllocateEnemy(world->Objects->next->next); InitEnemy(world->Objects->next->next->e, TestAI, world); world->Objects->next->next->e->Object.Position.y = 5; world->Objects->next->next->previous = world->Objects->next; AllocateWObject(&world->Objects->next->next->next); AllocateEnemy(world->Objects->next->next->next); InitEnemy(world->Objects->next->next->next->e, TestAI, world); world->Objects->next->next->next->e->Object.Position.x = 10; world->Objects->next->next->next->previous = world->Objects->next->next;*/ world->Objects = world->Levels[0].Objects; InitPhysics(&world->Physics); } void InitPlayer(VPlayer * p) { p->NumRockets = INITIALROCKETS; p->Shields = INITIALSHIELDS; } void AddWeapon(VWorld * world, int Type) { VWeapon * theWeapon; Vector front; VObjectWrapper * theWObject; if((Type == WEAPONTYPEROCKET && world->Player.NumRockets > 0) || Type == WEAPONTYPEBULLET) { if(Type == WEAPONTYPEROCKET) world->Player.NumRockets--; theWeapon = (VWeapon *) NewPtr(sizeof(VWeapon)); if (theWeapon != NULL) { InitWeapon(theWeapon, Type); AllocateWObject(&theWObject); theWObject->w = theWeapon; theWObject->Type = VWEAPON; theWObject->next = world->Objects; if (world->Objects != NULL) world->Objects->previous = theWObject; world->Objects = theWObject; ForwardsVector(&world->Camera, 1, &front); StartWeapon(theWeapon, &world->Camera.Position, &front, &front, &world->Camera.Up); } } } void CleanUpWorld(VWorld * world) { VObjectWrapper * theWObject; CleanUpObject(&world->CrossHair); while(world->Objects != NULL) { theWObject = world->Objects; world->Objects = theWObject->next; CleanUpWObject(theWObject); DisposePtr((Ptr) theWObject); } CleanUpLevel(&world->Levels[0]); } void DrawCrossHair(VWorld * world) { glPushMatrix(); glLoadIdentity(); glDisable(GL_DEPTH_TEST); DrawObject(&world->CrossHair); glEnable(GL_DEPTH_TEST); glPopMatrix(); } void DrawWorld(VWorld * world, float interval) { VObjectWrapper * theWObject; /* Fill with semi transparent background */ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDepthMask(GL_FALSE); glColor4f(0.0, 0.0, 0.0, ALPHAFILL / interval); glBegin(GL_QUADS); glVertex3f(-10.0, 10.0, -2.0); glVertex3f(10.0, 10.0, -2.0); glVertex3f(10.0, -10.0, -2.0); glVertex3f(-10.0, -10.0, -2.0); glEnd(); glDepthMask(GL_TRUE); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); ApplyCamera(&world->Camera); DrawLevel(&world->Levels[0]); for(theWObject = world->Objects; theWObject != NULL; theWObject = theWObject->next) { DrawWObject(theWObject); } DrawCrossHair(world); DrawConsole(&world->Console); } Boolean InBounds(VWorld * world, Vector Pos) { #pragma unused (world) if(Pos.x < -24 || Pos.x > 24 || Pos.z < -24 || Pos.z > 24 || Pos.y < -2 || Pos.y > 46) return false; return true; } void RunWorld(VWorld * world, float interval) { VObjectWrapper * theWObject; VObjectWrapper * obj; VObjectWrapper * next; VObjectWrapper * powerup; Vector front; Vector right; Boolean exploded; if((!InBounds(world, world->Camera.Position)) && world->Player.Shields > 0) world->Player.Shields = 0; powerup = NULL; theWObject = world->Objects; while(theWObject != NULL) { next = theWObject->next; if(theWObject == NULL) break; RunWObject(theWObject, interval, world); exploded = false; if(theWObject->exploded == 1) { AllocateWObject(&obj); AllocateExplosion(obj); switch(theWObject->Type) { case VOBJECT: InitExplosion(obj->ex, theWObject->o, 7); AllocateWObject(&powerup); AllocatePowerup(powerup); InitPowerup(powerup->p); SetupPowerup(powerup->p, POWERUPTYPEROCKETS, 5); powerup->p->Object.Position = theWObject->o->Position; CleanUpObject(theWObject->o); DisposePtr((Ptr)theWObject->o); break; case VENEMY: InitExplosion(obj->ex, &theWObject->e->Object, 7); AllocateWObject(&powerup); AllocatePowerup(powerup); InitPowerup(powerup->p); SetupPowerup(powerup->p, POWERUPTYPEHEALTH, 10); powerup->p->Object.Position = theWObject->e->Object.Position; CleanUpEnemy(theWObject->e); DisposePtr((Ptr)theWObject->e); break; case VWEAPON: InitExplosion(obj->ex, &theWObject->w->Object, theWObject->explosionLevel); CleanUpWeapon(theWObject->w); DisposePtr((Ptr)theWObject->w); break; } exploded = true; } if(theWObject->exploded == 2) { AllocateWObject(&obj); AllocateExplosion(obj); switch(theWObject->Type) { case VOBJECT: InitExplosion(obj->ex, theWObject->o, 1); break; case VENEMY: InitExplosion(obj->ex, &theWObject->e->Object, 1); break; } world->Objects->previous = obj; obj->next = world->Objects; world->Objects = obj; theWObject->exploded = 0; } if(theWObject->taggedForRemoval) { if(theWObject->next) theWObject->next->previous = theWObject->previous; if(theWObject->previous) theWObject->previous->next = theWObject->next; else world->Objects = world->Objects->next; DisposePtr((Ptr)theWObject); } if(exploded) { if(world->Objects) world->Objects->previous = obj; obj->next = world->Objects; world->Objects = obj; if(powerup) { if(world->Objects) world->Objects->previous = powerup; powerup->next = world->Objects; world->Objects = powerup; } } theWObject = next; } ForwardsVector(&world->Camera, 1.0, &front); CrossProduct(&world->Camera.Up, &front, &right); RunPhysics(&world->Physics, &world->Camera.Position, &front, &right, &world->Camera.Up, interval); AddVector(&world->Camera.Position, &front, &world->Camera.Look); }