Play action animation

This commit is contained in:
Linda Andersson 2014-02-25 16:08:45 +01:00
parent 2996627c56
commit f2bb50804c
6 changed files with 208 additions and 38 deletions

View File

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

View File

@ -72,7 +72,7 @@ namespace DanBias
void SetTint(Oyster::Math::Float3);
void SetGlowTint(Oyster::Math::Float3);
void SetVisible(bool visible);
// RB DEBUG
void updateRBWorld();

View File

@ -12,6 +12,7 @@
#include "GamingUI.h"
#include "RespawnUI.h"
#include "StatsUI.h"
#include <ObjectDefines.h>
using namespace ::DanBias::Client;
using namespace ::Oyster;
@ -131,7 +132,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;
@ -420,18 +421,62 @@ 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);
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 )
{
if(currGameUI == gameUI)
{
// set my HP
((GamingUI*)currGameUI)->SetHPtext(std::to_wstring(decoded.healthLost));
}
}
}
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectHealthStatus:
{
@ -441,39 +486,73 @@ 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 );
if( object )
{
if( this->privData->myId == decoded.object_ID )
{
this->privData->camera.SetPosition( decoded.position );
}
object->setPos( decoded.position );
// RB DEBUG
(*this->privData->dynamicObjects)[decoded.object_ID]->setRBPos ( decoded.position );
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 );
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
(*this->privData->dynamicObjects)[decoded.object_ID]->setRBScale ( decoded.scale );
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( object )
{
if( this->privData->myId == decoded.object_ID )
{
this->privData->camera.SetRotation( rotation );
}
(*this->privData->dynamicObjects)[decoded.object_ID]->setRot( rotation );
object->setRot( rotation );
// RB DEBUG
(*this->privData->dynamicObjects)[decoded.object_ID]->setRBRot ( rotation );
object->setRBRot( rotation );
// !RB DEBUG
}
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectPositionRotation:
{
@ -506,17 +585,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 );
}
}*/
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectCreate:
@ -613,6 +721,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;
}
}

View File

@ -80,7 +80,6 @@ namespace GameLogic
private:
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<Player>> playerObjects;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<Player>> deadPlayerObjects;
TeamManager teamManager;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<StaticObject>> staticObjects;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<DynamicObject>> dynamicObjects;

View File

@ -137,6 +137,15 @@ void Player::BeginFrame()
}
}
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)
{
@ -166,6 +175,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
@ -183,9 +198,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;
}
}
}
}

View File

@ -948,29 +948,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;