From e327f64702158fa44ccecbe22f8950962d7e1108 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Fri, 31 Jan 2014 16:33:16 +0100 Subject: [PATCH] GL - can play with two characters --- Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 6 ++++++ .../DanBiasGame/GameClientState/GameState.cpp | 19 +++++++++++++++++-- .../DanBiasGame/GameClientState/GameState.h | 3 ++- .../GameClientState/LobbyState.cpp | 3 --- .../GameClientState/LoginState.cpp | 2 +- Code/Game/GameLogic/Game_PlayerData.cpp | 3 ++- Code/Game/GameLogic/Level.cpp | 2 +- Code/Game/GameLogic/Object.cpp | 2 +- .../Implementation/GameSession_Gameplay.cpp | 14 ++++++++------ 9 files changed, 38 insertions(+), 16 deletions(-) diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index 06f200bf..205f826f 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -157,7 +157,13 @@ namespace DanBias m_data->recieverObj->gameClientState = new Client::LobbyState(); break; case Client::GameClientState::ClientState_Game: + if(m_data->serverOwner) + DanBias::GameServerAPI::GameStart(); m_data->recieverObj->gameClientState = new Client::GameState(); + if(m_data->serverOwner) + ((Client::GameState*)m_data->recieverObj->gameClientState)->setClientId(2); + else + ((Client::GameState*)m_data->recieverObj->gameClientState)->setClientId(3); break; default: return E_FAIL; diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 43b25ba7..cd281717 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -114,6 +114,18 @@ bool GameState::LoadModels(std::wstring mapFile) privData->object.push_back(obj); privData->object[privData->object.size() -1 ]->Init(modelData); + // add player model 2 + modelData.world = Oyster::Math3D::Float4x4::identity; + translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(10, 320, 0)); + + modelData.world = modelData.world * translate; + modelData.visible = true; + modelData.modelPath = L"..\\Content\\Models\\char_white.dan"; + modelData.id = 3; + // load models + obj = new C_Player(); + privData->object.push_back(obj); + privData->object[privData->object.size() -1 ]->Init(modelData); return true; @@ -137,7 +149,10 @@ bool GameState::InitCamera(Oyster::Math::Float3 startPos) privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view); return true; } - +void GameState::setClientId(int id) +{ + myId = id; +} GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyInput) { switch (privData->state) @@ -344,7 +359,7 @@ void GameState::Protocol( ObjPos* pos ) //camera->setRight((Oyster::Math::Float3(world[0], world[1], world[2]))); //camera->setUp((Oyster::Math::Float3(world[4], world[5], world[6]))); //camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10]))); - if(i == 2) // playerobj + if(i == myId) // playerobj { camera->SetPosition(Oyster::Math::Float3(world[12], world[13]+2.2f, world[14]-1)); camera->UpdateViewMatrix(); diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.h b/Code/Game/DanBiasGame/GameClientState/GameState.h index f8f1b67b..04d5b791 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.h +++ b/Code/Game/DanBiasGame/GameClientState/GameState.h @@ -26,6 +26,7 @@ private: bool key_Jump; Camera* camera; + int myId; struct myData; myData* privData; public: @@ -36,7 +37,7 @@ public: bool LoadModels(std::wstring mapFile) ; bool InitCamera(Oyster::Math::Float3 startPos) ; gameStateState LoadGame(); - + void setClientId(int id); void readKeyInput(InputClass* KeyInput); bool Render()override; bool Release()override; diff --git a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp index 35a5f295..538408c5 100644 --- a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp @@ -87,12 +87,9 @@ GameClientState::ClientState LobbyState::Update(float deltaTime, InputClass* Key // update animation // send data to server // check data from server - if( KeyInput->IsKeyPressed(DIK_G)) { - if(!DanBias::GameServerAPI::GameStart()) - return GameClientState::ClientState_Same; return ClientState_Game; } diff --git a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp index 4d1079bc..9beb6657 100644 --- a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp @@ -109,7 +109,7 @@ GameClientState::ClientState LoginState::Update(float deltaTime, InputClass* Key if( KeyInput->IsKeyPressed(DIK_J)) { // game ip - nwClient->Connect(15151, "193.11.184.109"); + nwClient->Connect(15151, "127.0.0.1"); if (!nwClient->IsConnected()) { diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 8f303cea..e19af2f3 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -7,9 +7,10 @@ Game::PlayerData::PlayerData() { //set some stats that are appropriate to a player Oyster::Physics::API::SimpleBodyDescription sbDesc; - sbDesc.centerPosition = Oyster::Math::Float3(0,320,0); + sbDesc.centerPosition = Oyster::Math::Float3(0,308,0); sbDesc.size = Oyster::Math::Float3(4,7,4); sbDesc.mass = 70; + sbDesc.restitutionCoeff = 0.5; //create rigid body Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release(); diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index cb3abe49..50737eb9 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -32,7 +32,7 @@ void Level::InitiateLevel(float radius) ICustomBody::State state; rigidBody->GetState(state); - state.SetRestitutionCoeff(0.01); + state.SetRestitutionCoeff(0.2); rigidBody->SetState(state); levelObj = new StaticObject(rigidBody, LevelCollisionBefore, LevelCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_WORLD); diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index fc0ac4c4..a0823247 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -123,7 +123,7 @@ void Object::BeginFrame() { Oyster::Math3D::SnapAngularAxis(Oyster::Math::Float4(setState.GetAngularAxis(), 0), Oyster::Math::Float4::standard_unit_y, -Oyster::Math::Float4(setState.GetGravityNormal()), axis); setState.SetRotation(axis.xyz); - + setState.SetAngularMomentum(Float3::null); Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y); debug += setState.GetGravityNormal(); } diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index c0041301..8235c903 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -86,12 +86,14 @@ namespace DanBias if(dynamic_cast (movedObject)) { IPlayerData* temp = (IPlayerData*)movedObject; - temp->GetID(); + + int id = temp->GetID(); Oyster::Math::Float4x4 world = temp->GetOrientation(); - Protocol_ObjectPosition p(world, 2); + Protocol_ObjectPosition p(world, id); GameSession::gameSession->Send(*p.GetProtocol()); } + GameLogic::IObjectData* obj = NULL; if(dynamic_cast(movedObject)) { @@ -100,10 +102,10 @@ namespace DanBias { if(obj->GetObjectType() == OBJECT_TYPE_WORLD) { - obj->GetID(); + int id = obj->GetID(); Oyster::Math::Float4x4 world =obj->GetOrientation(); - Protocol_ObjectPosition p(world, 0); + Protocol_ObjectPosition p(world, id); GameSession::gameSession->Send(*p.GetProtocol()); } } @@ -114,9 +116,9 @@ namespace DanBias { if(obj->GetObjectType() == OBJECT_TYPE_BOX) { - obj->GetID(); + int id = obj->GetID(); Oyster::Math::Float4x4 world = obj->GetOrientation(); - Protocol_ObjectPosition p(world, 1); + Protocol_ObjectPosition p(world, id); GameSession::gameSession->Send(*p.GetProtocol()); } }