Not finished Pickup system.

This commit is contained in:
Pontus Fransson 2014-02-25 14:36:54 +01:00 committed by Dander7BD
parent 5620a3c517
commit 4f2738e921
9 changed files with 197 additions and 0 deletions

View File

@ -10,6 +10,8 @@
#include "Portal.h" #include "Portal.h"
#include "ExplosiveCrate.h" #include "ExplosiveCrate.h"
#include "PickupSystem/PickupHealth.h"
using namespace Oyster; using namespace Oyster;
using namespace GameLogic; using namespace GameLogic;
@ -357,3 +359,30 @@ 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);
}

View File

@ -173,6 +173,9 @@
<ClInclude Include="JumpPad.h" /> <ClInclude Include="JumpPad.h" />
<ClInclude Include="Level.h" /> <ClInclude Include="Level.h" />
<ClInclude Include="Object.h" /> <ClInclude Include="Object.h" />
<ClInclude Include="PickupSystem\Pickup.h" />
<ClInclude Include="PickupSystem\PickupHealth.h" />
<ClInclude Include="PickupSystem\PickupSystem.h" />
<ClInclude Include="Player.h" /> <ClInclude Include="Player.h" />
<ClInclude Include="Portal.h" /> <ClInclude Include="Portal.h" />
<ClInclude Include="StaticObject.h" /> <ClInclude Include="StaticObject.h" />
@ -194,6 +197,9 @@
<ClCompile Include="JumpPad.cpp" /> <ClCompile Include="JumpPad.cpp" />
<ClCompile Include="Level.cpp" /> <ClCompile Include="Level.cpp" />
<ClCompile Include="Object.cpp" /> <ClCompile Include="Object.cpp" />
<ClCompile Include="PickupSystem\Pickup.cpp" />
<ClCompile Include="PickupSystem\PickupHealth.cpp" />
<ClCompile Include="PickupSystem\PickupSystem.cpp" />
<ClCompile Include="Player.cpp" /> <ClCompile Include="Player.cpp" />
<ClCompile Include="Portal.cpp" /> <ClCompile Include="Portal.cpp" />
<ClCompile Include="StaticObject.cpp" /> <ClCompile Include="StaticObject.cpp" />

View File

@ -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;
}

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -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();
}
}

View File

@ -0,0 +1,30 @@
//////////////////////////////////////
// Created by Pontus Fransson 2014 //
//////////////////////////////////////
#ifndef PICKUP_SYSTEM_H
#define PICKUP_SYSTEM_H
#include <vector>
#include "Pickup.h"
namespace GameLogic
{
class PickupSystem
{
public:
PickupSystem();
~PickupSystem();
void CreatePickup(Pickup* pickup);
void Update();
private:
std::vector<Utility::DynamicMemory::SmartPointer<Pickup>> pickups;
};
}
#endif

View File

@ -42,6 +42,7 @@ namespace GameLogic
ObjectSpecialType_Player, ObjectSpecialType_Player,
ObjectSpecialType_Generic, ObjectSpecialType_Generic,
ObjectSpecialType_PickupHealth,
ObjectSpecialType_Count, ObjectSpecialType_Count,
ObjectSpecialType_Unknown = -1 ObjectSpecialType_Unknown = -1