diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 1ab9afbd..a5ae6380 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; @@ -281,4 +283,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/PickupSystem/Pickup.cpp b/Code/Game/GameLogic/PickupSystem/Pickup.cpp new file mode 100644 index 00000000..84b95e87 --- /dev/null +++ b/Code/Game/GameLogic/PickupSystem/Pickup.cpp @@ -0,0 +1,29 @@ +#include "Pickup.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; +} + +Pickup::~Pickup() +{} + +void Pickup::Update() +{ + if(!active) + { + if(timer.getElapsedSeconds() >= spawnTime) + { + active = true; + } + } +} + +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/ObjectDefines.h b/Code/Game/LevelLoader/ObjectDefines.h index 918fb4e6..151bf27c 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