diff --git a/Code/Game/GameClient/GameClientState/C_Object.cpp b/Code/Game/GameClient/GameClientState/C_Object.cpp index 67146770..b168b92c 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.cpp +++ b/Code/Game/GameClient/GameClientState/C_Object.cpp @@ -123,7 +123,10 @@ void C_Object::SetGlowTint(Oyster::Math::Float3 tint) model->GlowTint = tint; } - +void C_Object::SetVisible(bool visible) +{ + model->Visible = visible; +} //////////////////////////////////////////////// // RB DEBUG diff --git a/Code/Game/GameClient/GameClientState/C_Object.h b/Code/Game/GameClient/GameClientState/C_Object.h index fd118068..1a8f7517 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.h +++ b/Code/Game/GameClient/GameClientState/C_Object.h @@ -72,7 +72,7 @@ namespace DanBias void SetTint(Oyster::Math::Float3); void SetGlowTint(Oyster::Math::Float3); - + void SetVisible(bool visible); // RB DEBUG void updateRBWorld(); diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 123b3fb2..d9c6fa30 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -12,6 +12,7 @@ #include "GamingUI.h" #include "RespawnUI.h" #include "StatsUI.h" +#include using namespace ::DanBias::Client; using namespace ::Oyster; @@ -135,7 +136,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa p->InitRB( RBData ); // !RB DEBUG // start with runing animation - p->playAnimation( L"run_forwards", true ); + p->playAnimation( L"idle", true ); (this->privData->players)[id] = p; @@ -425,15 +426,59 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState switch(ID) { - case protocol_Gameplay_ObjectPickup: break; /** @todo TODO: implement */ + case protocol_Gameplay_ObjectPickup: + { + Protocol_ObjectPickup decoded(data); + decoded.object_ID; + C_Object *object; + object = (this->privData->players)[decoded.object_ID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.object_ID]; + } + + if( object ) + { + if( this->privData->myId == decoded.object_ID ) + { + // I picked up the pickUp! + } + + if (decoded.pickup_ID == GameLogic::PickupType::PickupType_Health) + { + // object->PickupHealth(); + } + else if (decoded.pickup_ID == GameLogic::PickupType::PickupType_SpeedBoost) + { + // object->PickupSpeed(); + } + } + decoded.pickup_ID; + + + } + return GameClientState::event_processed; case protocol_Gameplay_ObjectDamage: { Protocol_ObjectDamage decoded(data); - if( this->privData->myId == decoded.object_ID ) + C_Object *object; + object = (this->privData->players)[decoded.object_ID]; + if( !object) { - if(currGameUI == gameUI) + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.object_ID]; + } + + if( object ) + { + if( this->privData->myId == decoded.object_ID ) { - ((GamingUI*)currGameUI)->SetHPtext(std::to_wstring(decoded.healthLost)); + if(currGameUI == gameUI) + { + // set my HP + ((GamingUI*)currGameUI)->SetHPtext(std::to_wstring(decoded.healthLost)); + } } } } @@ -446,38 +491,72 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState { Protocol_ObjectPosition decoded(data); - // if is this player. Remember to change camera - if( this->privData->myId == decoded.object_ID ) - this->privData->camera.SetPosition( decoded.position ); + C_Object *object; + object = (this->privData->players)[decoded.object_ID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.object_ID]; + } - (*this->privData->dynamicObjects)[decoded.object_ID]->setPos( decoded.position ); - // RB DEBUG - (*this->privData->dynamicObjects)[decoded.object_ID]->setRBPos ( decoded.position ); - // !RB DEBUG + if( object ) + { + if( this->privData->myId == decoded.object_ID ) + { + this->privData->camera.SetPosition( decoded.position ); + } + + object->setPos( decoded.position ); + // RB DEBUG + object->setRBPos ( decoded.position ); + // !RB DEBUG + } } return GameClientState::event_processed; case protocol_Gameplay_ObjectScale: { Protocol_ObjectScale decoded(data); - (*this->privData->dynamicObjects)[decoded.object_ID]->setScale( decoded.scale ); - // RB DEBUG - (*this->privData->dynamicObjects)[decoded.object_ID]->setRBScale ( decoded.scale ); - // !RB DEBUG + C_Object *object; + object = (this->privData->players)[decoded.object_ID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.object_ID]; + } + + if( object ) + { + object->setScale( decoded.scale ); + // RB DEBUG + object->setRBScale ( decoded.scale ); + // !RB DEBUG + } } return GameClientState::event_processed; case protocol_Gameplay_ObjectRotation: { Protocol_ObjectRotation decoded(data); Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] ); + C_Object *object; + object = (this->privData->players)[decoded.object_ID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.object_ID]; + } - // if is this player. Remember to change camera - if( this->privData->myId == decoded.object_ID ) - this->privData->camera.SetRotation( rotation ); + if( object ) + { + if( this->privData->myId == decoded.object_ID ) + { + this->privData->camera.SetRotation( rotation ); + } - (*this->privData->dynamicObjects)[decoded.object_ID]->setRot( rotation ); - // RB DEBUG - (*this->privData->dynamicObjects)[decoded.object_ID]->setRBRot ( rotation ); - // !RB DEBUG + object->setRot( rotation ); + // RB DEBUG + object->setRBRot( rotation ); + // !RB DEBUG + } } return GameClientState::event_processed; case protocol_Gameplay_ObjectPositionRotation: @@ -511,17 +590,46 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState } } return GameClientState::event_processed; - case protocol_Gameplay_ObjectEnabled: break; /** @todo TODO: implement */ + case protocol_Gameplay_ObjectEnabled: + { + Protocol_ObjectEnable 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 ) + { + object->SetVisible(true); + } + } + return GameClientState::event_processed; case protocol_Gameplay_ObjectDisabled: { Protocol_ObjectDisable 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]; + } - auto object = this->privData->dynamicObjects->find( decoded.objectID ); + if( object ) + { + object->SetVisible(false); + } + + /*auto object = this->privData->dynamicObjects->find( decoded.objectID ); if( object != this->privData->dynamicObjects->end() ) { - object->second = nullptr; - this->privData->dynamicObjects->erase( object ); - } + object->second = nullptr; + this->privData->dynamicObjects->erase( object ); + }*/ + } return GameClientState::event_processed; case protocol_Gameplay_ObjectCreate: @@ -616,6 +724,40 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState } } return GameClientState::event_processed; + case protocol_Gameplay_ObjectAction: + { + Protocol_ObjectAction decoded(data); + + C_Player *player; + player = (this->privData->players)[decoded.objectID]; + + if( player ) + { + if( this->privData->myId == decoded.objectID ) + { + // my player animation + //} + //else + //{ + // HACK for now animate my char + switch (decoded.animationID) + { + case GameLogic::PlayerAction::PlayerAction_Walk: + player->playAnimation(L"run_forwards", true); + break; + case GameLogic::PlayerAction::PlayerAction_Jump: + player->playAnimation(L"movement", true); + break; + case GameLogic::PlayerAction::PlayerAction_Idle: + player->playAnimation(L"idle", true); + break; + default: + break; + } + } + } + } + return GameClientState::event_processed; default: break; } } diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 9fb3dbad..f8d41ba9 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -80,7 +80,6 @@ namespace GameLogic private: Utility::DynamicMemory::DynamicArray> playerObjects; - Utility::DynamicMemory::DynamicArray> deadPlayerObjects; TeamManager teamManager; Utility::DynamicMemory::DynamicArray> staticObjects; Utility::DynamicMemory::DynamicArray> dynamicObjects; diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 91f09c56..52ac9b0c 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -134,7 +134,16 @@ void Player::BeginFrame() rightVelocity *= Oyster::Math::Float3(0.2f*fabs(rightDir.x), 0.2f*fabs(rightDir.y), 0.2f*fabs(rightDir.z)); } } - + + if(walkDirection == Oyster::Math::Float3::null) + { + if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) + { + if(this->playerState != PLAYER_STATE::PLAYER_STATE_IDLE) + this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Idle); + this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; + } + } // Walk if walkdirection is something if(walkDirection != Oyster::Math::Float3::null) { @@ -164,6 +173,12 @@ void Player::BeginFrame() rightVelocity += walkDirection*Oyster::Math::Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z)) * walkSpeed*0.2f; } } + if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) + { + if(this->playerState != PLAYER_STATE::PLAYER_STATE_WALKING) + this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Walk); + this->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; + } } // Adjust velocities so no squaring occurs @@ -181,9 +196,20 @@ void Player::BeginFrame() { Oyster::Math::Float3 up = this->rigidBody->GetState().centerPos.GetNormalized(); 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->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING; } } + else + { + if(this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING) + { + this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Idle); + this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; + } + } } } diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 234a5301..f6170d66 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -941,29 +941,29 @@ namespace GameLogic struct Protocol_ObjectAction :public Oyster::Network::CustomProtocolObject { short objectID; - float animationID; + int animationID; Protocol_ObjectAction() { this->protocol[0].value = protocol_Gameplay_ObjectAction; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Short; - this->protocol[2].type = Oyster::Network::NetAttributeType_Float; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; - objectID = 0; + objectID = -1; animationID = -1; } Protocol_ObjectAction(Oyster::Network::CustomNetProtocol& p) { objectID = p[1].value.netShort; - animationID = p[2].value.netFloat; + animationID = p[2].value.netInt; } - Protocol_ObjectAction(float animID, int id) + Protocol_ObjectAction( int id, float animID) { this->protocol[0].value = protocol_Gameplay_ObjectAction; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Short; - this->protocol[2].type = Oyster::Network::NetAttributeType_Float; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; objectID = id; animationID = animID;