#include "WorldManager.h" void InitWorld(VWorld * world) { InitCamera(&world->Camera); 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); 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); } 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; AllocateWObject(&world->Objects->next); AllocateEnemy(world->Objects->next); InitEnemy(world->Objects->next->e, TestAI, world); world->Objects->next->previous = world->Objects; InitPhysics(&world->Physics); InitConsole(&world->Console); } 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); } } void DrawCrossHair(VWorld * world) { glDisable(GL_DEPTH_TEST); glPushMatrix(); glLoadIdentity(); DrawObject(&world->CrossHair); glPopMatrix(); glEnable(GL_DEPTH_TEST); } 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, 0.017647059 / 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); DrawObject(&world->Environment); for(theWObject = world->Objects; theWObject != NULL; theWObject = theWObject->next) { DrawWObject(theWObject); } DrawCrossHair(world); DrawConsole(&world->Console); } void RunWorld(VWorld * world, float interval) { VObjectWrapper * theWObject; VObjectWrapper * obj; VObjectWrapper * powerup; Vector front; Vector right; Boolean exploded; for (theWObject = world->Objects; theWObject != NULL; theWObject = theWObject->next) { RunWObject(theWObject, interval, world); if(theWObject == NULL) break; exploded = false; if(theWObject->exploded) { AllocateWObject(&obj); AllocateExplosion(obj); switch(theWObject->Type) { case VOBJECT: InitExplosion(obj->ex, theWObject->o, 4); AllocateWObject(&powerup); AllocatePowerup(powerup); InitPowerup(powerup->p); SetupPowerup(powerup->p, POWERUPTYPEROCKETS, 5); powerup->p->Object.Position = theWObject->o->Position; world->Objects->previous = powerup; powerup->next = world->Objects; world->Objects = powerup; CleanUpObject(theWObject->o); break; case VENEMY: InitExplosion(obj->ex, &theWObject->e->Object, 4); CleanUpEnemy(theWObject->e); break; } exploded = true; } 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) { world->Objects->previous = obj; obj->next = world->Objects; world->Objects = obj; } } 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); }