diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp
index d60d16ce..3e931f8e 100644
--- a/Code/Game/GameLogic/CollisionManager.cpp
+++ b/Code/Game/GameLogic/CollisionManager.cpp
@@ -10,6 +10,8 @@
#include "Portal.h"
#include "ExplosiveCrate.h"
+#include "PickupSystem/PickupHealth.h"
+
using namespace Oyster;
using namespace GameLogic;
@@ -356,4 +358,31 @@ using namespace GameLogic;
}
+ }
+
+ //General collision collision for pickups
+ //It calls the collision function defined in each pickup.
+ void Pickup::PickupCollision(Oyster::Physics::ICustomBody* objA, Oyster::Physics::ICustomBody* objB, Oyster::Math::Float kineticEnergyLoss)
+ {
+ //Check if player is a player.
+ Object* a = (Object*)objA->GetCustomTag();
+ Object* b = (Object*)objB->GetCustomTag();
+
+ if(!a)
+ return;
+ if(!b)
+ return;
+
+ if(b->GetObjectType() == ObjectSpecialType_Player)
+ {
+ ((Pickup*)a)->OnCollision((Player*)(b));
+ }
+ else if(a->GetObjectType() != ObjectSpecialType_Player)
+ {
+ //One of the objects are not a player.
+ //Do nothing.
+ return;
+ }
+
+ ((Pickup*)b)->OnCollision((Player*)a);
}
\ No newline at end of file
diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj
index 52b7722b..08a932d2 100644
--- a/Code/Game/GameLogic/GameLogic.vcxproj
+++ b/Code/Game/GameLogic/GameLogic.vcxproj
@@ -173,6 +173,9 @@
+
+
+
@@ -194,6 +197,9 @@
+
+
+
diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp
index 439f3ac8..0f0ab632 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)
@@ -440,7 +450,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
new file mode 100644
index 00000000..73a319f8
--- /dev/null
+++ b/Code/Game/GameLogic/PickupSystem/Pickup.cpp
@@ -0,0 +1,32 @@
+#include "Pickup.h"
+#include "../Game.h"
+
+using namespace GameLogic;
+
+Pickup::Pickup(Oyster::Physics::ICustomBody *rigidBody, EventOnCollision collisionFunc, ObjectSpecialType type, int objectID, Oyster::Math::Float spawnTime)
+ : StaticObject(rigidBody, collisionFunc, type, objectID)
+{
+ this->active = true;
+ this->spawnTime = spawnTime;
+ timer.reset();
+}
+
+Pickup::~Pickup()
+{}
+
+void Pickup::Update()
+{
+ if(!active)
+ {
+ if(timer.getElapsedSeconds() >= spawnTime)
+ {
+ active = true;
+ ((Game*)&Game::Instance())->onEnableFnc(this);
+ }
+ }
+}
+
+bool Pickup::IsActive()
+{
+ return active;
+}
\ No newline at end of file
diff --git a/Code/Game/GameLogic/PickupSystem/Pickup.h b/Code/Game/GameLogic/PickupSystem/Pickup.h
new file mode 100644
index 00000000..e48017fc
--- /dev/null
+++ b/Code/Game/GameLogic/PickupSystem/Pickup.h
@@ -0,0 +1,35 @@
+#ifndef PICKUP_H
+#define PICKUP_H
+
+#include "../StaticObject.h"
+#include "../Player.h"
+#include "WinTimer.h"
+
+typedef void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss);
+
+namespace GameLogic
+{
+ class Pickup : public StaticObject
+ {
+ public:
+ Pickup(Oyster::Physics::ICustomBody *rigidBody, EventOnCollision collisionFunc, ObjectSpecialType type, int objectID, Oyster::Math::Float spawnTime);
+ virtual ~Pickup();
+
+ virtual void Update();
+
+ bool IsActive();
+
+ virtual void OnCollision(Player *player) = 0;
+
+ static void PickupCollision(Oyster::Physics::ICustomBody *rigidBodyCrate, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss);
+
+ protected:
+ bool active;
+
+ Utility::WinTimer timer;
+ double spawnTime;
+
+ };
+}
+
+#endif
\ No newline at end of file
diff --git a/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp b/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp
new file mode 100644
index 00000000..56cbef1e
--- /dev/null
+++ b/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp
@@ -0,0 +1,18 @@
+#include "PickupHealth.h"
+
+using namespace GameLogic;
+
+PickupHealth::PickupHealth(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type, int objectID, Oyster::Math::Float spawnTime, Oyster::Math::Float healthValue)
+ : Pickup(rigidBody, Pickup::PickupCollision, type, objectID, spawnTime)
+{
+ this->hpValue = healthValue;
+}
+
+PickupHealth::~PickupHealth()
+{}
+
+void PickupHealth::OnCollision(Player *player)
+{
+ timer.reset();
+ player->DamageLife(-hpValue);
+}
\ No newline at end of file
diff --git a/Code/Game/GameLogic/PickupSystem/PickupHealth.h b/Code/Game/GameLogic/PickupSystem/PickupHealth.h
new file mode 100644
index 00000000..5d5db809
--- /dev/null
+++ b/Code/Game/GameLogic/PickupSystem/PickupHealth.h
@@ -0,0 +1,27 @@
+//////////////////////////////////////
+// Created by Pontus Fransson 2014 //
+//////////////////////////////////////
+
+#ifndef PICKUP_HEALTH_H
+#define PICKUP_HEALTH_H
+
+#include "Pickup.h"
+
+namespace GameLogic
+{
+ class PickupHealth : public Pickup
+ {
+ public:
+ PickupHealth(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type, int objectID, Oyster::Math::Float spawnTime, Oyster::Math::Float HealthValue);
+ virtual ~PickupHealth();
+
+
+ void OnCollision(Player *player);
+
+ protected:
+ int hpValue;
+
+ };
+}
+
+#endif
\ No newline at end of file
diff --git a/Code/Game/GameLogic/PickupSystem/PickupSystem.cpp b/Code/Game/GameLogic/PickupSystem/PickupSystem.cpp
new file mode 100644
index 00000000..0f60ddc9
--- /dev/null
+++ b/Code/Game/GameLogic/PickupSystem/PickupSystem.cpp
@@ -0,0 +1,22 @@
+#include "PickupSystem.h"
+
+using namespace GameLogic;
+
+PickupSystem::PickupSystem()
+{}
+
+PickupSystem::~PickupSystem()
+{}
+
+void PickupSystem::CreatePickup(Pickup* pickup)
+{
+ pickups.push_back(pickup);
+}
+
+void PickupSystem::Update()
+{
+ for(int i = 0; i < pickups.size(); i++)
+ {
+ pickups.at(i)->Update();
+ }
+}
\ No newline at end of file
diff --git a/Code/Game/GameLogic/PickupSystem/PickupSystem.h b/Code/Game/GameLogic/PickupSystem/PickupSystem.h
new file mode 100644
index 00000000..4bd1e69e
--- /dev/null
+++ b/Code/Game/GameLogic/PickupSystem/PickupSystem.h
@@ -0,0 +1,30 @@
+//////////////////////////////////////
+// Created by Pontus Fransson 2014 //
+//////////////////////////////////////
+
+#ifndef PICKUP_SYSTEM_H
+#define PICKUP_SYSTEM_H
+
+#include
+
+#include "Pickup.h"
+
+namespace GameLogic
+{
+ class PickupSystem
+ {
+ public:
+ PickupSystem();
+ ~PickupSystem();
+
+ void CreatePickup(Pickup* pickup);
+
+ void Update();
+
+ private:
+ std::vector> pickups;
+
+ };
+}
+
+#endif
\ No newline at end of file
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 8ff3a0af..aadc3382 100644
--- a/Code/Game/LevelLoader/ObjectDefines.h
+++ b/Code/Game/LevelLoader/ObjectDefines.h
@@ -42,6 +42,7 @@ namespace GameLogic
ObjectSpecialType_Player,
ObjectSpecialType_Generic,
+ ObjectSpecialType_PickupHealth,
ObjectSpecialType_Count,
ObjectSpecialType_Unknown = -1
@@ -258,7 +259,11 @@ namespace GameLogic
float skySize;
};
-
+ struct PickupHealthAttributes : public ObjectHeader
+ {
+ float spawnTime;
+ float healthValue;
+ };
diff --git a/Code/Game/LevelLoader/ParseFunctions.cpp b/Code/Game/LevelLoader/ParseFunctions.cpp
index ac361c46..060180a2 100644
--- a/Code/Game/LevelLoader/ParseFunctions.cpp
+++ b/Code/Game/LevelLoader/ParseFunctions.cpp
@@ -23,9 +23,9 @@ namespace GameLogic
void ParseLight(char* buffer, BasicLight& header, int& size)
{
int start = 0;
- memcpy(&header.typeID, &buffer[start], 40);
- start += 40;
- /*
+ memcpy(&header.typeID, &buffer[start], 4);
+ start += 4;
+
memcpy(&header.lightType, &buffer[start], 4);
start += 4;
@@ -39,7 +39,7 @@ namespace GameLogic
start += 4;
memcpy(&header.intensity, &buffer[start], 4);
- start += 4;*/
+ start += 4;
size += start;