#pragma once #include "WorldManager.h" void InitWorld(VWorld * world) { InitCamera(&world->Camera); world->Weapons = NULL; InitObject(&world->CrossHair); world->CrossHair.Position.x = 0.0; world->CrossHair.Position.y = 0.0; world->CrossHair.Position.z = -1.7; /*world->CrossHair.Rotation.x = 0.0; world->CrossHair.Rotation.y = 0.0; world->CrossHair.Rotation.z = 0.0; InitModel(&world->CrossHair.Model); */ BuildCrossHairModel(&world->CrossHair.Model); world->Objects = (VObject *) NewPtr(sizeof(VObject)); if (world->Objects != NULL) { Vector targetPos; InitObject(world->Objects); BuildTargetModel(&world->Objects->Model); targetPos.x = 2.0; targetPos.y = 1.0; targetPos.z = -7.0; MoveObjectToPoint(world->Objects, &targetPos); CalculateRadius(world->Objects); world->Objects->next = (VObject *) NewPtr(sizeof(VObject)); if (world->Objects->next != NULL) { InitObject(world->Objects->next); BuildGrassModel(&world->Objects->next->Model); targetPos.x = -2.0; targetPos.y = -4.0; targetPos.z = -6.0; MoveObjectToPoint(world->Objects->next, &targetPos); } } world->Enemies = (VEnemy *) NewPtr(sizeof(VEnemy)); if (world->Enemies != NULL) { InitEnemy(world->Enemies, TestAI, world); } } void DrawCrossHair(VWorld * world) { DrawObject(&world->CrossHair); } void CleanUpWorld(VWorld * world) { VWeapon * theWeapon; VEnemy * theEnemy; CleanUpObject(&world->CrossHair); while (world->Weapons != NULL) { theWeapon = world->Weapons; world->Weapons = theWeapon->next; CleanUpWeapon(theWeapon); DisposePtr((Ptr) theWeapon); } while (world->Enemies != NULL) { theEnemy = world->Enemies; world->Enemies = theEnemy->next; CleanUpEnemy(theEnemy); DisposePtr((Ptr) theEnemy); } } void DrawWorld(VWorld * world, Vector * rotate, Vector * movement, float interval) { VWeapon * theWeapon; VObject * theObject; VEnemy * theEnemy; /* Fill with semi transparent background */ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDepthMask(GL_FALSE); glColor4f(0.0, 0.0, 0.0, (0.024 / (interval > 1.0 ? 1.0 : 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); OffsetCamera(&world->Camera, movement, interval); RotateCamera(&world->Camera, rotate, interval); ApplyCamera(&world->Camera); for (theWeapon = world->Weapons; theWeapon != NULL; theWeapon = theWeapon->next) { DrawWeapon(theWeapon); } for (theObject = world->Objects; theObject != NULL; theObject = theObject->next) { DrawObject(theObject); } for (theEnemy = world->Enemies; theEnemy != NULL; theEnemy = theEnemy->next) { DrawEnemy(theEnemy); } } void RunWorld(VWorld * world, float interval) { VWeapon * theWeapon, * previous = NULL; VObject * theObject, * previousObject = NULL; VEnemy * theEnemy; for (theWeapon = world->Weapons; theWeapon != NULL; theWeapon = theWeapon->next) { if (theWeapon->taggedForRemoval) { if (previous == NULL) world->Weapons = theWeapon->next; else previous->next = theWeapon->next; CleanUpWeapon(theWeapon); DisposePtr((Ptr) theWeapon); theWeapon = previous; if (theWeapon == NULL) break; continue; } RunWeapon(theWeapon, interval, world->Objects); previous = theWeapon; } for(theEnemy = world->Enemies; theEnemy != NULL; theEnemy = theEnemy->next) { EnemyEvent(theEnemy, interval); } for (theObject = world->Objects; theObject != NULL; theObject = theObject->next) { if (theObject->taggedForRemoval) { if (previousObject == NULL) world->Objects = theObject->next; else previousObject->next = theObject->next; CleanUpObject(theObject); DisposePtr((Ptr) theObject); theObject = previousObject; if (theObject == NULL) break; continue; } /* Run object, if necessary */ previousObject = theObject; } }