diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index dc51cb00..f7c48f8b 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -131,6 +131,11 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; + case ObjectSpecialType_PickupHealth: + { + gameObj = new PickupHealth(rigidBody, obj->specialTypeID, objID, ((PickupHealthAttributes*)obj)->spawnTime, ((PickupHealthAttributes*)obj)->healthValue); + } + break; default: { gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); @@ -216,7 +221,6 @@ bool Level::InitiateLevel(std::wstring levelPath) std::string convertedLevelPath = converterX.to_bytes(levelPath); objects = ll.LoadLevel(convertedLevelPath); - if(objects.size() == 0) return false; @@ -264,7 +268,12 @@ bool Level::InitiateLevel(std::wstring levelPath) { // create game object Object* staticGameObj = CreateGameObj(staticObjData, rigidBody_Static); - if(staticGameObj != NULL) + + if(staticObjData->specialTypeID == ObjectSpecialType_PickupHealth) + { + this->pickupSystem.CreatePickup((PickupHealth*)staticGameObj); + } + else if(staticGameObj != NULL) { this->staticObjects.Push((StaticObject*)staticGameObj); } @@ -321,6 +330,7 @@ bool Level::InitiateLevel(std::wstring levelPath) break; } } + return true; } bool Level::InitiateLevel(float radius) @@ -438,7 +448,7 @@ void Level::Update(float deltaTime) } } - + this->pickupSystem.Update(); } int Level::getNrOfDynamicObj() { diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index f8d41ba9..7d6c25c9 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -16,6 +16,9 @@ #include "DynamicArray.h" #include "LevelLoader.h" +#include "PickupSystem\PickupSystem.h" +#include "PickupSystem\PickupHealth.h" + const int DEATH_TIMER = 5; namespace GameLogic { @@ -88,6 +91,7 @@ namespace GameLogic StaticObject *levelObj; int objID; Utility::DynamicMemory::DynamicArray spawnPoints; + PickupSystem pickupSystem; }; diff --git a/Code/Game/GameLogic/PickupSystem/Pickup.cpp b/Code/Game/GameLogic/PickupSystem/Pickup.cpp index 84b95e87..73a319f8 100644 --- a/Code/Game/GameLogic/PickupSystem/Pickup.cpp +++ b/Code/Game/GameLogic/PickupSystem/Pickup.cpp @@ -1,4 +1,5 @@ #include "Pickup.h" +#include "../Game.h" using namespace GameLogic; @@ -7,6 +8,7 @@ Pickup::Pickup(Oyster::Physics::ICustomBody *rigidBody, EventOnCollision collisi { this->active = true; this->spawnTime = spawnTime; + timer.reset(); } Pickup::~Pickup() @@ -19,6 +21,7 @@ void Pickup::Update() if(timer.getElapsedSeconds() >= spawnTime) { active = true; + ((Game*)&Game::Instance())->onEnableFnc(this); } } } diff --git a/Code/Game/LevelLoader/LevelParser.cpp b/Code/Game/LevelLoader/LevelParser.cpp index fe349988..680b0358 100644 --- a/Code/Game/LevelLoader/LevelParser.cpp +++ b/Code/Game/LevelLoader/LevelParser.cpp @@ -156,6 +156,21 @@ std::vector> LevelParser::Parse(std::string filen objects.push_back(header); break; } + + case ObjectSpecialType_PickupHealth: + { + PickupHealthAttributes* header = new PickupHealthAttributes; + ParseObject(&buffer[counter], *header, counter, loadCgf); + + ParseObject(&buffer[counter], &header->spawnTime, 4); + counter += 4; + + ParseObject(&buffer[counter], &header->healthValue, 4); + counter += 4; + + objects.push_back(header); + break; + } //this is a hotfix, fix so you only load the relevant data when the file is updated default: //Couldn't find specialType diff --git a/Code/Game/LevelLoader/ObjectDefines.h b/Code/Game/LevelLoader/ObjectDefines.h index 9ce7d86a..aadc3382 100644 --- a/Code/Game/LevelLoader/ObjectDefines.h +++ b/Code/Game/LevelLoader/ObjectDefines.h @@ -259,7 +259,11 @@ namespace GameLogic float skySize; }; - + struct PickupHealthAttributes : public ObjectHeader + { + float spawnTime; + float healthValue; + };