Reading hp pickups from levelformat. Updating pickups.

This commit is contained in:
Pontus Fransson 2014-02-25 16:10:02 +01:00
parent d56d1d7569
commit 11eda5065e
5 changed files with 40 additions and 4 deletions

View File

@ -131,6 +131,11 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_PickupHealth:
{
gameObj = new PickupHealth(rigidBody, obj->specialTypeID, objID, ((PickupHealthAttributes*)obj)->spawnTime, ((PickupHealthAttributes*)obj)->healthValue);
}
break;
default: default:
{ {
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); 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); std::string convertedLevelPath = converterX.to_bytes(levelPath);
objects = ll.LoadLevel(convertedLevelPath); objects = ll.LoadLevel(convertedLevelPath);
if(objects.size() == 0) if(objects.size() == 0)
return false; return false;
@ -264,7 +268,12 @@ bool Level::InitiateLevel(std::wstring levelPath)
{ {
// create game object // create game object
Object* staticGameObj = CreateGameObj(staticObjData, rigidBody_Static); 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); this->staticObjects.Push((StaticObject*)staticGameObj);
} }
@ -321,6 +330,7 @@ bool Level::InitiateLevel(std::wstring levelPath)
break; break;
} }
} }
return true; return true;
} }
bool Level::InitiateLevel(float radius) bool Level::InitiateLevel(float radius)
@ -440,7 +450,7 @@ void Level::Update(float deltaTime)
} }
} }
this->pickupSystem.Update();
} }
int Level::getNrOfDynamicObj() int Level::getNrOfDynamicObj()
{ {

View File

@ -16,6 +16,9 @@
#include "DynamicArray.h" #include "DynamicArray.h"
#include "LevelLoader.h" #include "LevelLoader.h"
#include "PickupSystem\PickupSystem.h"
#include "PickupSystem\PickupHealth.h"
const int DEATH_TIMER = 5; const int DEATH_TIMER = 5;
namespace GameLogic namespace GameLogic
{ {
@ -89,6 +92,7 @@ namespace GameLogic
StaticObject *levelObj; StaticObject *levelObj;
int objID; int objID;
Utility::DynamicMemory::DynamicArray<Oyster::Math::Float3> spawnPoints; Utility::DynamicMemory::DynamicArray<Oyster::Math::Float3> spawnPoints;
PickupSystem pickupSystem;
}; };

View File

@ -1,4 +1,5 @@
#include "Pickup.h" #include "Pickup.h"
#include "../Game.h"
using namespace GameLogic; using namespace GameLogic;
@ -7,6 +8,7 @@ Pickup::Pickup(Oyster::Physics::ICustomBody *rigidBody, EventOnCollision collisi
{ {
this->active = true; this->active = true;
this->spawnTime = spawnTime; this->spawnTime = spawnTime;
timer.reset();
} }
Pickup::~Pickup() Pickup::~Pickup()
@ -19,6 +21,7 @@ void Pickup::Update()
if(timer.getElapsedSeconds() >= spawnTime) if(timer.getElapsedSeconds() >= spawnTime)
{ {
active = true; active = true;
((Game*)&Game::Instance())->onEnableFnc(this);
} }
} }
} }

View File

@ -156,6 +156,21 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
objects.push_back(header); objects.push_back(header);
break; 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 //this is a hotfix, fix so you only load the relevant data when the file is updated
default: default:
//Couldn't find specialType //Couldn't find specialType

View File

@ -259,7 +259,11 @@ namespace GameLogic
float skySize; float skySize;
}; };
struct PickupHealthAttributes : public ObjectHeader
{
float spawnTime;
float healthValue;
};