Merge branch 'GameLogic' of https://github.com/dean11/Danbias into GameLogic

This commit is contained in:
Linda Andersson 2014-02-25 16:26:46 +01:00
commit de3250f650
13 changed files with 241 additions and 8 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

@ -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
{ {
@ -88,6 +91,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

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

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

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

@ -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
@ -258,7 +259,11 @@ namespace GameLogic
float skySize; float skySize;
}; };
struct PickupHealthAttributes : public ObjectHeader
{
float spawnTime;
float healthValue;
};

View File

@ -23,9 +23,9 @@ namespace GameLogic
void ParseLight(char* buffer, BasicLight& header, int& size) void ParseLight(char* buffer, BasicLight& header, int& size)
{ {
int start = 0; int start = 0;
memcpy(&header.typeID, &buffer[start], 40); memcpy(&header.typeID, &buffer[start], 4);
start += 40; start += 4;
/*
memcpy(&header.lightType, &buffer[start], 4); memcpy(&header.lightType, &buffer[start], 4);
start += 4; start += 4;
@ -39,7 +39,7 @@ namespace GameLogic
start += 4; start += 4;
memcpy(&header.intensity, &buffer[start], 4); memcpy(&header.intensity, &buffer[start], 4);
start += 4;*/ start += 4;
size += start; size += start;