#include "WorldManager.h" 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 InitWorld(VWorld * world) { InitCamera(&world->Camera); InitPlayer(&world->Player); 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, &world->Player); } 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) { 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, 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 == 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; world->Objects->previous = powerup; powerup->next = world->Objects; world->Objects = powerup; CleanUpObject(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; world->Objects->previous = powerup; powerup->next = world->Objects; world->Objects = powerup; CleanUpEnemy(theWObject->e); 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) { 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); }