Gameserver - Merged with gamelogic

This commit is contained in:
dean11 2014-02-26 14:42:17 +01:00
commit 504f11ef4c
25 changed files with 295 additions and 198 deletions

View File

@ -90,10 +90,13 @@ int C_Object::GetId() const
void C_Object::Render()
{
if( this->model )
{
if(this->model->Visible)
{
Oyster::Graphics::API::RenderModel(model);
}
}
}
void C_Object::Release()
{
if( this->model )

View File

@ -158,19 +158,28 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa
GameClientState::ClientState GameState::Update( float deltaTime )
{
GameStateUI::UIState UIstate = this->currGameUI->Update( deltaTime );
GameStateUI::UIState UIstate = this->gameUI->Update( deltaTime );
switch (UIstate)
{
case DanBias::Client::GameStateUI::UIState_shut_down:
{
this->privData->nextState = ClientState_Quit;
// disconnect
}
break;
case DanBias::Client::GameStateUI::UIState_same:
break;
case DanBias::Client::GameStateUI::UIState_gaming:
break;
case DanBias::Client::GameStateUI::UIState_main_menu:
//this->privData->nextState =
break;
case DanBias::Client::GameStateUI::UIState_shut_down:
this->privData->nextState = ClientState_Quit;
{
this->privData->nextState = ClientState_Main;
// disconnect
}
break;
default:
break;
}
@ -603,6 +612,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
{
// if it is not a player
object = (*this->privData->dynamicObjects)[decoded.objectID];
if(!object)
{
//If it is a static object
object = (*this->privData->staticObjects)[decoded.objectID];
}
}
if( object )
@ -620,6 +635,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
{
// if it is not a player
object = (*this->privData->dynamicObjects)[decoded.objectID];
if(!object)
{
//If it is a static object
object = (*this->privData->staticObjects)[decoded.objectID];
}
}
if( object )
@ -757,6 +778,15 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
case GameLogic::PlayerAction::PlayerAction_Idle:
player->playAnimation(L"idle", true);
break;
case GameLogic::WeaponAction::WeaponAction_PrimaryShoot:
break;
case GameLogic::WeaponAction::WeaponAction_SecondaryShoot:
break;
case GameLogic::WeaponAction::WeaponAction_Reload:
break;
default:
break;
}
@ -764,6 +794,28 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
}
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectCollision:
{
Protocol_ObjectCollision decoded(data);
C_Object *object;
object = (this->privData->players)[decoded.objectID];
if( !object)
{
// if it is not a player
object = (*this->privData->dynamicObjects)[decoded.objectID];
}
if( object )
{
switch (decoded.collisionID)
{
case GameLogic::CollisionEvent::CollisionEvent_BasicCollision:
break;
default:
break;
}
}
}
return GameClientState::event_processed;
default: break;
}
}

View File

@ -17,6 +17,7 @@ GamingUI::GamingUI() :
this->camera = nullptr;
this->plane = nullptr;
this->text = nullptr;
this->nextState = GameStateUI::UIState_same;
}
GamingUI::GamingUI( SharedStateContent* shared, Camera_FPSV2 *camera ) :
@ -24,6 +25,7 @@ GamingUI::GamingUI( SharedStateContent* shared, Camera_FPSV2 *camera ) :
{
this->sharedData = shared;
this->camera = camera;
this->nextState = GameStateUI::UIState_same;
}
GamingUI::~GamingUI() { /* Do nothing */ }

View File

@ -1,7 +1,7 @@
#include "AttatchmentMassDriver.h"
#include "PhysicsAPI.h"
#include "GameLogicStates.h"
#include "Game.h"
using namespace GameLogic;
@ -48,6 +48,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage,
{
currentEnergy -= 90.0f;
ForcePush(usage,dt);
// add CD
((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_PrimaryShoot);
}
break;
@ -56,6 +58,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage,
{
currentEnergy -= 1.0f;
ForcePull(usage,dt);
// add CD
((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_SecondaryShoot);
}
break;
@ -64,6 +68,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage,
{
currentEnergy -= 90.0f;
ForceZip(usage,dt);
// add CD
((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_UtilityActivate);
}
break;
}

View File

@ -44,7 +44,6 @@ using namespace GameLogic;
realObjB = realObjA;
}
switch (realObjB->GetObjectType())
{
case ObjectSpecialType::ObjectSpecialType_Generic:
@ -69,7 +68,8 @@ using namespace GameLogic;
//player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING;
break;
}
// send collision event message
((Game*)&Game::Instance())->onCollisionEventFnc(player, CollisionEvent::CollisionEvent_BasicCollision);
//return Physics::ICustomBody::SubscriptMessage_none;
}
@ -255,16 +255,18 @@ using namespace GameLogic;
{
//realobjA is the affectedObject, transfer this to realobjB
realObjB->SetAffectedBy(*realObjA->getAffectingPlayer());
return;
}
if(realObjB->getAffectingPlayer() != NULL && realObjA->getAffectingPlayer() == NULL)
{
//realobjB is the affectedObject, transfer this to realobjA
realObjA->SetAffectedBy(*realObjB->getAffectingPlayer());
return;
}
if(realObjA->getAffectingPlayer() != NULL && realObjB->getAffectingPlayer() != NULL)
if(realObjA->getAffectingPlayer() != NULL && realObjB->getAffectingPlayer() != NULL && ( realObjA->getAffectingPlayer()->GetID() != realObjB->getAffectingPlayer()->GetID()))
{
//Both objects have a player affecting them, now use the special case
if(realObjA->GetRigidBody()->GetState().previousVelocity.GetMagnitude() > realObjB->GetRigidBody()->GetState().previousVelocity.GetMagnitude() )
@ -374,9 +376,14 @@ using namespace GameLogic;
return;
if(b->GetObjectType() == ObjectSpecialType_Player)
{
//Only update if it is active. And if the player is alive
if(((Pickup*)a)->IsActive() && ((Player*)b)->GetState() != PLAYER_STATE_DEAD && ((Player*)b)->GetState() != PLAYER_STATE_DIED)
{
((Pickup*)a)->OnCollision((Player*)(b));
}
return;
}
else if(a->GetObjectType() != ObjectSpecialType_Player)
{
//One of the objects are not a player.
@ -384,5 +391,9 @@ using namespace GameLogic;
return;
}
//Only update if it is active. And if the player is alive
if(((Pickup*)b)->IsActive() && ((Player*)a)->GetState() != PLAYER_STATE_DEAD && ((Player*)a)->GetState() != PLAYER_STATE_DIED)
{
((Pickup*)b)->OnCollision((Player*)a);
}
}

View File

@ -90,11 +90,6 @@ void DynamicObject::Activate()
void DynamicObject::SetAffectedBy(Player &player)
{
this->affectedBy = &player;
if(this->type != ObjectSpecialType::ObjectSpecialType_Player) //should not add itself to its own list if its a player
{
player.AddAffectedObject(*this);
}
}
Player* DynamicObject::getAffectingPlayer()

View File

@ -182,12 +182,16 @@ void Game::SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer)
}
void Game::SetActionSubscription(GameEvent::AnimationEventFunction functionPointer)
{
this->onPlayerActionEventFnc = functionPointer;
this->onActionEventFnc = functionPointer;
}
void Game::SetPickupSubscription(GameEvent::PickupEventFunction functionPointer)
{
this->onPickupEventFnc = functionPointer;
}
void Game::SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer)
{
this->onCollisionEventFnc = functionPointer;
}
bool Game::Initiate()
{
API::Instance().Init();

View File

@ -87,6 +87,7 @@ namespace GameLogic
void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) override;
void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) override;
void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) override;
void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) override;
bool Initiate() override;
float GetFrameTime() const;
@ -106,8 +107,9 @@ namespace GameLogic
GameEvent::ObjectHpFunction onDamageTakenFnc;
GameEvent::ObjectRespawnedFunction onRespawnFnc;
GameEvent::ObjectDeadFunction onDeadFnc;
GameEvent::AnimationEventFunction onPlayerActionEventFnc;
GameEvent::AnimationEventFunction onActionEventFnc;
GameEvent::PickupEventFunction onPickupEventFnc;
GameEvent::CollisionEventFunction onCollisionEventFnc;
};
}

View File

@ -33,6 +33,7 @@ namespace GameLogic
typedef void(*ObjectDeadFunction)(IObjectData* victim, IObjectData* killer, float seconds); // Callback method that sends killer and death timer
typedef void(*PickupEventFunction)(IObjectData* player, int pickupEffectID ); // Callback method that sends killer and death timer
typedef void(*AnimationEventFunction)(IObjectData* player, int actionID ); // Callback method that sends killer and death timer
typedef void(*CollisionEventFunction)(IObjectData*object, int collisionID);
//etc...
};
@ -188,7 +189,7 @@ namespace GameLogic
virtual void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) = 0;
virtual void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) = 0;
virtual void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) = 0;
virtual void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) = 0;
};
}

View File

@ -16,12 +16,11 @@ using namespace Oyster::Math;
Level::Level(void)
{
objID = 100;
srand (time(NULL));
objIDCounter = 100;
}
Level::~Level(void)
{
delete this->levelObj;
this->levelObj = NULL;
}
Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
{
@ -31,7 +30,7 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
{
case ObjectSpecialType_None:
{
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID);
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
}
break;
@ -49,22 +48,22 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
float worldSize = ((WorldAttributes*)obj)->worldSize;
float atmosphereSize = ((WorldAttributes*)obj)->atmoSphereSize;
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID);
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
}
break;
case ObjectSpecialType_Building:
{
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID);
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
}
break;
case ObjectSpecialType_Stone:
{
gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID);
gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
}
break;
case ObjectSpecialType_StandardBox:
{
gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID);
gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
}
break;
case ObjectSpecialType_RedExplosiveBox:
@ -72,7 +71,7 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
Oyster::Math::Float dmg = 120;
Oyster::Math::Float force = 500;
Oyster::Math::Float radie = 3;
gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, dmg, force, radie);
gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter, dmg, force, radie);
}
break;
//case ObjectSpecialType_BlueExplosiveBox:
@ -81,24 +80,24 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
// break;
case ObjectSpecialType_SpikeBox:
{
gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID);
gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
}
break;
case ObjectSpecialType_Spike:
{
gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID);
gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
}
break;
case ObjectSpecialType_CrystalFormation:
{
int dmg = 50;
//gameObj = new Crystal(rigidBody);
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID);
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
}
break;
case ObjectSpecialType_CrystalShard:
{
gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID);
gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
}
break;
case ObjectSpecialType_JumpPad:
@ -106,39 +105,28 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
float power = 500; //((JumpPadAttributes*)obj)->power;
Oyster::Math::Float3 dir = ((JumpPadAttributes*)obj)->direction;
Oyster::Math::Float3 pushForce = dir * power;
gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID , pushForce);
gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter , pushForce);
}
break;
case ObjectSpecialType_Portal:
{
Oyster::Math::Float3 destination = ((PortalAttributes*)obj)->destination;
gameObj = new Portal(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID, destination);
}
break;
//case ObjectSpecialType_SpawnPoint:
//{
// save
//}
break;
case ObjectSpecialType_Player:
{
// should not be read from the lvl format
gameObj = new Portal(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter, destination);
}
break;
case ObjectSpecialType_Generic:
{
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID);
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
}
break;
case ObjectSpecialType_PickupHealth:
{
gameObj = new PickupHealth(rigidBody, obj->specialTypeID, objID, ((PickupHealthAttributes*)obj)->spawnTime, ((PickupHealthAttributes*)obj)->healthValue);
gameObj = new PickupHealth(rigidBody, obj->specialTypeID, objIDCounter, ((PickupHealthAttributes*)obj)->spawnTime, ((PickupHealthAttributes*)obj)->healthValue);
}
break;
default:
{
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID);
gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter);
}
break;
}
@ -264,7 +252,7 @@ bool Level::InitiateLevel(std::wstring levelPath)
for (int i = 0; i < objCount; i++)
{
++this->objID;
++this->objIDCounter;
ObjectTypeHeader* obj = objects.at(i);
switch (obj->typeID)
{
@ -272,6 +260,7 @@ bool Level::InitiateLevel(std::wstring levelPath)
{
LevelMetaData* LevelObjData = ((LevelMetaData*)obj);
std::string levelName = LevelObjData->levelName;
// LevelObjData->worldSize;
}
break;
@ -372,71 +361,6 @@ bool Level::InitiateLevel(std::wstring levelPath)
return true;
}
bool Level::InitiateLevel(float radius)
{
API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0));
API::Instance().SetGravity(200);
int idCount = 100;
// add level sphere
ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f);
levelObj = new StaticObject(rigidBody, LevelCollisionAfter, ObjectSpecialType_World, idCount++);
//this->levelObj->objectID = idCount++;
rigidBody->SetCustomTag(levelObj);
ICustomBody* rigidBody_TestBox;
int nrOfBoxex = 5;
int offset = 0;
for(int i =0; i< nrOfBoxex; i ++)
{
rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(0.0f, 605.0f + i*5.0f, 10.0f), 5.0f, 0.5f, 0.8f, 0.6f);
this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultOnCollision, ObjectSpecialType_StandardBox, idCount++));
}
/*offset += nrOfBoxex;
for(int i =0; i< nrOfBoxex; i ++)
{
rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0,5, -605 -( i*5)), 5);
this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX));
rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i+offset]);
}
offset += nrOfBoxex;
for(int i =0; i< nrOfBoxex; i ++)
{
rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(200, 620 + ( i*7), 0), 5);
this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX));
rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i+offset]);
}
offset += nrOfBoxex;
for(int i =0; i< nrOfBoxex; i ++)
{
rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(5, 605 + i*5, 0), 5);
this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX));
rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]);
}*/
// add crystal
ICustomBody* rigidBody_Crystal = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(10.0f, 605.0f, 0.0f), 5.0f, 0.5f, 0.8f, 0.6f);
this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultOnCollision, ObjectSpecialType_StandardBox, idCount++));
// add house
ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20.0f, 20.0f, 20.0f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(-50.0f, 590.0f, 0.0f), 0.0f, 0.5f, 0.8f, 0.6f);
this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultOnCollision, ObjectSpecialType_Generic, idCount++));
// add jumppad
ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1.0f, 1.0f, 1.0f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(4.0f, 600.3f, 0.0f), 5.0f, 0.5f, 0.8f, 0.6f);
this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, ObjectSpecialType_JumpPad,idCount++ ,Oyster::Math::Float3(0,2000,0)));
return true;
}
void Level::AddPlayerToTeam(Player *player, int teamID)
{
@ -444,6 +368,15 @@ void Level::AddPlayerToTeam(Player *player, int teamID)
}
void Level::AddPlayerToGame(Player *player)
{
for(int i = 0; i < (int)this->playerObjects.Size(); i++)
{
if (!this->playerObjects[i])
{
this->playerObjects[i] = player;
return;
}
}
// if no free space, allocate a new spot
this->playerObjects.Push(player);
}
void Level::RemovePlayerFromGame(Player *player)
@ -452,7 +385,7 @@ void Level::RemovePlayerFromGame(Player *player)
{
if ((Player*)this->playerObjects[i] == player)
{
//this->playerObjects[i].
this->playerObjects[i] = nullptr;
}
}
}
@ -465,14 +398,22 @@ void Level::RespawnPlayer(Player *player)
{
//this->teamManager.RespawnPlayerRandom(player);
Float3 spawnPoint = spawnPoints[0];
int i = rand() % spawnPoints.Size();
Float3 spawnPoint = spawnPoints[i];
player->Respawn(spawnPoint);
}
void Level::Update(float deltaTime)
{
// update lvl-things
for(int i = 0; i < (int)this->playerObjects.Size(); i++)
{
if(this->playerObjects[i]->getAffectingPlayer() != NULL)
{
}
if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD)
{
// true when timer reaches 0
@ -483,9 +424,41 @@ void Level::Update(float deltaTime)
{
this->playerObjects[i]->setDeathTimer(DEATH_TIMER);
// HACK to avoid crasch. affected by tag is NULL
//((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID
Player* killer = this->playerObjects[i]->getAffectingPlayer();
((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID
//((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i]->getAffectingPlayer(), DEATH_TIMER); // add killer ID
if(!killer) //if there is no killer then you commited suicide
{
killer = this->playerObjects[i];
}
((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], killer, DEATH_TIMER); // add killer ID
}
}
for(int i = 0; i < dynamicObjects.Size(); i++)
{
if(dynamicObjects[i]->getAffectingPlayer() != NULL)
{
Oyster::Math::Float vel = dynamicObjects[i]->GetRigidBody()->GetLinearVelocity().GetMagnitude();
if(vel <= 0.1f) // is bearly moving
{
//set the tag AffectedBy to NULL
dynamicObjects[i]->RemoveAffectedBy();
}
}
}
for(int i = 0; i < playerObjects.Size(); i++)
{
if(playerObjects[i]->getAffectingPlayer() != NULL)
{
Oyster::Math::Float vel = playerObjects[i]->GetRigidBody()->GetLinearVelocity().GetMagnitude();
if(vel <= 0.1f) // is bearly moving
{
//set the tag AffectedBy to NULL
playerObjects[i]->RemoveAffectedBy();
}
}
}
@ -511,7 +484,7 @@ void Level::PhysicsOnMoveLevel(const ICustomBody *object)
Object* temp = (Object*)object->GetCustomTag();
((Game*)&Game::Instance())->onMoveFnc(temp);
}
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<Player>> Level::GetPlayers()
Utility::DynamicMemory::DynamicArray<Player*> Level::GetPlayers()
{
return this->playerObjects;
}

View File

@ -35,7 +35,6 @@ namespace GameLogic
* @param levelPath: Path to a file that contains all information on the level
********************************************************/
bool InitiateLevel(std::wstring levelPath);
bool InitiateLevel(float radius);
Oyster::Physics::ICustomBody* InitRigidBodyCube( const ObjectHeader* obj);
Oyster::Physics::ICustomBody* InitRigidBodySphere( const ObjectHeader* obj);
Oyster::Physics::ICustomBody* InitRigidBodyMesh( const ObjectHeader* obj);
@ -79,19 +78,19 @@ namespace GameLogic
static void PlayerDied( Player* player );
static void PhysicsOnMoveLevel(const Oyster::Physics::ICustomBody *object);
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<Player>> GetPlayers();
Utility::DynamicMemory::DynamicArray<Player*> GetPlayers();
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<StaticObject>> GetStaticObjects();
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<DynamicObject>> GetDynamicObject();
private:
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<Player>> playerObjects;
Utility::DynamicMemory::DynamicArray<Player*> playerObjects;
TeamManager teamManager;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<StaticObject>> staticObjects;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<DynamicObject>> dynamicObjects;
GameModeType gameMode;
Utility::DynamicMemory::SmartPointer<Oyster::Physics::ICustomBody> rigidBodyLevel;
StaticObject *levelObj;
int objID;
//Utility::DynamicMemory::SmartPointer<Oyster::Physics::ICustomBody> rigidBodyLevel;
// //StaticObject *levelObj;
int objIDCounter;
Utility::DynamicMemory::DynamicArray<Oyster::Math::Float3> spawnPoints;
PickupSystem pickupSystem;

View File

@ -9,6 +9,7 @@ Pickup::Pickup(Oyster::Physics::ICustomBody *rigidBody, EventOnCollision collisi
this->active = true;
this->spawnTime = spawnTime;
timer.reset();
this->GetRigidBody()->MoveToLimbo();
}
Pickup::~Pickup()

View File

@ -1,4 +1,5 @@
#include "PickupHealth.h"
#include "../Game.h"
using namespace GameLogic;
@ -14,5 +15,8 @@ PickupHealth::~PickupHealth()
void PickupHealth::OnCollision(Player *player)
{
timer.reset();
((Game*)&Game::Instance())->onDisableFnc(this);
this->active = false;
player->DamageLife(-hpValue);
}

View File

@ -8,11 +8,11 @@ using namespace GameLogic;
using namespace Oyster::Physics;
const float MOVE_FORCE = 30;
const float KEY_TIMER = 0.03f;
const float AFFECTED_TIMER = 1.0f;
Player::Player()
:DynamicObject()
{
Player::initPlayerData();
AffectedObjects.Reserve(15);
this->weapon = NULL;
this->teamID = -1;
}
@ -22,7 +22,6 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)
{
this->weapon = new Weapon(2,this);
Player::initPlayerData();
AffectedObjects.Reserve(15);
this->teamID = teamID;
}
@ -31,16 +30,15 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom
{
this->weapon = new Weapon(2,this);
Player::initPlayerData();
AffectedObjects.Reserve(15);
this->teamID = teamID;
}
Player::~Player(void)
{
if(weapon)
if(this->weapon)
{
delete weapon;
weapon = NULL;
delete this->weapon;
this->weapon = NULL;
}
}
void Player::initPlayerData()
@ -57,7 +55,7 @@ void Player::initPlayerData()
this->key_strafeRight = 0;
this->key_strafeLeft = 0;
this->key_jump = 0;
this->invincibleCooldown = 0;
this->RecentlyAffected = 0;
this->deathTimer = 0;
this->rotationUp = 0;
@ -65,16 +63,19 @@ void Player::initPlayerData()
void Player::BeginFrame()
{
if( this->playerState != PLAYER_STATE_DEAD && PLAYER_STATE_DIED)
if( this->playerState != PLAYER_STATE_DEAD && this->playerState != PLAYER_STATE_DIED)
{
weapon->Update(0.002f);
Oyster::Math::Float maxSpeed = 30;
// Rotate player accordingly
this->rigidBody->AddRotationAroundY(this->rotationUp);
this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized());
this->rotationUp = 0.0f;
this->rotationUp = 0;
// Direction data
Oyster::Math::Float4x4 xform;
xform = this->rigidBody->GetState().GetOrientation();
@ -138,7 +139,7 @@ void Player::BeginFrame()
if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING)
{
if(this->playerState != PLAYER_STATE::PLAYER_STATE_IDLE)
this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Idle);
this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Idle);
this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
}
}
@ -174,7 +175,7 @@ void Player::BeginFrame()
if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING)
{
if(this->playerState != PLAYER_STATE::PLAYER_STATE_WALKING)
this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Walk);
this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Walk);
this->playerState = PLAYER_STATE::PLAYER_STATE_WALKING;
}
}
@ -196,7 +197,7 @@ void Player::BeginFrame()
this->rigidBody->ApplyImpulse(up*this->rigidBody->GetState().mass * 20);
if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING)
this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Jump);
this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Jump);
this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING;
}
}
@ -204,7 +205,7 @@ void Player::BeginFrame()
{
if(this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING)
{
this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Idle);
this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Idle);
this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
}
}
@ -213,16 +214,6 @@ void Player::BeginFrame()
void Player::EndFrame()
{
//check if there are any objects that can be removed from the AffectedObjects list
for(int i = 0; i < this->AffectedObjects.Size(); i++)
{
if(this->AffectedObjects[i] && (this->AffectedObjects[i]->GetRigidBody()->GetState().previousVelocity).GetMagnitude() <= 0.1f)
{
this->AffectedObjects[i]->RemoveAffectedBy();
this->AffectedObjects.Remove(i);
}
}
}
void Player::Move(const PLAYER_MOVEMENT &movement)
@ -292,7 +283,7 @@ void Player::SetLookDir(const Oyster::Math3D::Float3& lookDir)
}
void Player::TurnLeft(Oyster::Math3D::Float deltaRadians)
{
this->rotationUp = deltaRadians;
this->rotationUp += deltaRadians;
}
void Player::Jump()
@ -340,8 +331,14 @@ PLAYER_STATE Player::GetState() const
}
void Player::DamageLife(int damage)
{
if(damage != 0)
{
this->playerStats.hp -= damage;
if(this->playerStats.hp > 100)
this->playerStats.hp = 100;
// send hp to client
this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp);
@ -350,23 +347,9 @@ void Player::DamageLife(int damage)
this->playerStats.hp = 0;
this->playerState = PLAYER_STATE_DIED;
}
}
}
void Player::AddAffectedObject(DynamicObject &AffectedObject)
{
//check if object already exists in the list, if so then do not add
for(int i = 0; i < AffectedObjects.Size(); i++)
{
if(AffectedObjects[i]->GetID() == AffectedObject.GetID())
{
//object already exists, exit function
return;
}
}
//else you add the object to the stack
AffectedObjects.Push(&AffectedObject);
}
bool Player::deathTimerTick(float dt)
{
this->deathTimer -= dt;

View File

@ -68,8 +68,6 @@ namespace GameLogic
void TurnLeft(Oyster::Math3D::Float deltaRadians);
void AddAffectedObject(DynamicObject &AffectedObject);
/********************************************************
* Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody
* Will be called when the physics detect a collision
@ -90,6 +88,7 @@ namespace GameLogic
Oyster::Math::Float4x4 GetOrientation() const;
int GetTeamID() const;
PLAYER_STATE GetState() const;
Oyster::Math::Float GetRecentlyAffected();
void DamageLife(int damage);
void setDeathTimer(float deathTimer);
@ -104,8 +103,6 @@ namespace GameLogic
void initPlayerData();
private:
Utility::DynamicMemory::DynamicArray<DynamicObject*> AffectedObjects;
int teamID;
Weapon *weapon;
PLAYER_STATE playerState;
@ -122,7 +119,7 @@ namespace GameLogic
float deathTimer;
bool hasTakenDamage;
float invincibleCooldown;
Oyster::Math::Float RecentlyAffected;
PlayerStats playerStats;
PlayerScore playerScore;

View File

@ -1010,4 +1010,46 @@ namespace GameLogic
private:
Oyster::Network::CustomNetProtocol protocol;
};
//#define protocol_Gameplay_ObjectCollision 370
struct Protocol_ObjectCollision :public Oyster::Network::CustomProtocolObject
{
short objectID;
int collisionID;
// TODO: maybe position, impact, and velocity
Protocol_ObjectCollision()
{
this->protocol[0].value = protocol_Gameplay_ObjectCollision;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
this->protocol[2].type = Oyster::Network::NetAttributeType_Int;
this->objectID = -1;
this->collisionID = -1;
}
Protocol_ObjectCollision(Oyster::Network::CustomNetProtocol& p)
{
this->objectID = p[1].value.netShort;
this->collisionID = p[2].value.netInt;
}
Protocol_ObjectCollision( int id, int collisionID)
{
this->protocol[0].value = protocol_Gameplay_ObjectCollision;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
this->protocol[2].type = Oyster::Network::NetAttributeType_Int;
this->objectID = id;
this->collisionID = collisionID;
}
Oyster::Network::CustomNetProtocol GetProtocol() override
{
this->protocol[1].value = objectID;
this->protocol[2].value = collisionID;
return protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
#endif // !GAMELOGIC_PLAYER_PROTOCOLS_H

View File

@ -73,6 +73,7 @@
#define protocol_Gameplay_ObjectDie 367
#define protocol_Gameplay_ObjectDisconnectPlayer 368
#define protocol_Gameplay_ObjectAction 369
#define protocol_Gameplay_ObjectCollision 370
#define protocol_GameplayMAX 399

View File

@ -105,6 +105,7 @@ namespace DanBias
static void ObjectDead ( GameLogic::IObjectData* victim, GameLogic::IObjectData* killer, float seconds );
static void PickupEvent ( GameLogic::IObjectData* movedObject, int pickupEffectID );
static void ActionEvent ( GameLogic::IObjectData* movedObject , int actionID );
static void CollisionEvent ( GameLogic::IObjectData* Object , int collisionID );
//Private member variables
private:
Utility::DynamicMemory::DynamicArray<gClient> gClients;

View File

@ -25,9 +25,6 @@ GameClient::GameClient(Utility::DynamicMemory::SmartPointer<Oyster::Network::Net
}
GameClient::~GameClient()
{
if(this->player)
this->player->Inactivate();
delete this->player;
this->isReady = false;

View File

@ -152,7 +152,7 @@ using namespace DanBias;
}
void GameSession::ObjectEnabled( GameLogic::IObjectData* movedObject )
{
GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID()).GetProtocol());
GameSession::gameSession->Send(Protocol_ObjectEnable(movedObject->GetID()).GetProtocol());
}
void GameSession::ObjectDamaged( GameLogic::IObjectData* movedObject, float hp )
{
@ -176,6 +176,11 @@ using namespace DanBias;
// send action protocol
GameSession::gameSession->Send(Protocol_ObjectAction(movedObject->GetID(), actionID).GetProtocol());
}
void GameSession::CollisionEvent( GameLogic::IObjectData* movedObject , int collisionID )
{
// send action protocol
GameSession::gameSession->Send(Protocol_ObjectCollision(movedObject->GetID(), collisionID).GetProtocol());
}
//*****************************************************//
//****************** Protocol methods *****************//
//******************************************************************************************************************//

View File

@ -114,6 +114,7 @@ bool GameSession::Create(GameDescription& desc, bool forceStart)
this->gameInstance.SetDeadSubscription(GameSession::ObjectDead);
this->gameInstance.SetActionSubscription(GameSession::ActionEvent);
this->gameInstance.SetPickupSubscription(GameSession::PickupEvent);
this->gameInstance.SetCollisionSubscription(GameSession::CollisionEvent);
this->gameInstance.SetFPS(60);
this->description.clients.Clear();

View File

@ -168,6 +168,14 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
ParseObject(&buffer[counter], &header->healthValue, 4);
counter += 4;
// DEBUG
header->position[1] = 150;
header->spawnTime = 5;
header->boundingVolume.box.mass = 0;
header->typeID = ObjectType_Static;
header->healthValue = 50;
// !DEBUG
objects.push_back(header);
break;
}

View File

@ -95,16 +95,26 @@ namespace GameLogic
enum PlayerAction
{
PlayerAction_Jump,
PlayerAction_Walk,
PlayerAction_Idle,
PlayerAction_Jump = 0,
PlayerAction_Walk = 1,
PlayerAction_Idle = 2,
};
// continue ID counting from playerAction
enum WeaponAction
{
WeaponAtcion_PrimaryShoot,
WeaponAction_SecondaryShoot
WeaponAction_PrimaryShoot = 3,
WeaponAction_SecondaryShoot = 4,
WeaponAction_UtilityActivate = 5,
WeaponAction_Reload = 6,
WeaponAction_EnergyDepleted = 7,
};
// TODO: add more collision Events
enum CollisionEvent
{
CollisionEvent_BasicCollision,
};
enum PickupType
{
PickupType_Health,

View File

@ -177,7 +177,6 @@ void SimpleRigidBody::AddRotationAroundY(::Oyster::Math::Float angle)
this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w());
}
void SimpleRigidBody::SetAngularFactor(Float factor)
{
this->rigidBody->setAngularFactor(factor);

View File

@ -29,7 +29,7 @@ namespace Oyster
void SetRotation(Math::Quaternion quaternion);
void SetRotation(Math::Float3 eulerAngles);
void SetRotation(::Oyster::Math::Float4x4 rotation);
void AddRotationAroundY(Math::Float angle);
void AddRotationAroundY(::Oyster::Math::Float angle);
void SetAngularFactor(Math::Float factor);
void SetMass(Math::Float mass);