#include "Game.h" #include "Player.h" #include "Level.h" #include #include #include #include using namespace GameLogic; using namespace Utility::DynamicMemory; using namespace Oyster::Physics; #define DELTA_TIME 0.01666666666666666666666666666667f template int InsertObject(DynamicArray& list, T* obj) { for (unsigned int i = 0; i < list.Size(); i++) { if(!list[i]) { list[i] = obj; return i; } } list.Push(obj); return list.Size() - 1; } template int RemoveObject(DynamicArray& list, T* obj) { for (unsigned int i = 0; i < list.Size(); i++) { if(!list[i]) { list[i] = obj; return i; } } list.Push(obj); return list.Size() - 1; } struct Game::PrivateData { PrivateData() { } ~PrivateData() { for (unsigned int i = 0; i < players.Size(); i++) { this->players[i]->player = 0; } } DynamicArray players; SmartPointer level; Utility::WinTimer timer; }myData; Game::Game(void) { myData = new PrivateData(); } Game::~Game(void) { if(myData) { delete myData; } } void Game::GetAllPlayerPositions() const { } Game::PlayerData* Game::CreatePlayer() { Player *newPlayer = new Player(); PlayerData *newPdata = new PlayerData(); newPdata->player = newPlayer; int id = InsertObject(this->myData->players, newPdata); return this->myData->players[id]; } Game::LevelData* Game::CreateLevel() { Level *newLevel = new Level(); newLevel->InitiateLevel(1000); LevelData *newLdata = new LevelData(); newLdata->level = newLevel; myData->level = newLdata; return myData->level; } void Game::CreateTeam() { } void Game::NewFrame() { double dt = this->myData->timer.getElapsedSeconds(); //60 fps sec is currently staticly if(dt >= DELTA_TIME) { for (int i = 0; i < this->myData->players.Size(); i++) { if(this->myData->players[i]->player) this->myData->players[i]->player->BeginFrame(); } API::Instance().Update(); for (int i = 0; i < this->myData->players.Size(); i++) { if(this->myData->players[i]->player) this->myData->players[i]->player->EndFrame(); } this->myData->timer.reset(); } }