From 3bf9f59f5a752311104a1c53c768b63457910661 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Tue, 4 Feb 2014 11:13:02 +0100 Subject: [PATCH 1/2] GL - Player dies and respawns --- Code/Game/GameLogic/CollisionManager.cpp | 2 +- Code/Game/GameLogic/Player.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 5c226362..37916799 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -35,7 +35,7 @@ using namespace GameLogic; //return Physics::ICustomBody::SubscriptMessage_none; break; case OBJECT_TYPE::OBJECT_TYPE_WORLD: - int test = 5; + PlayerVObject(*player,*realObj, kineticEnergyLoss); break; } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 235fab13..81c1b6d8 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -61,6 +61,7 @@ Player::~Player(void) void Player::BeginFrame() { weapon->Update(0.002f); + if(playerState == PLAYER_STATE_DEAD) Respawn(Oyster::Math::Float3(0,308,0)); Object::BeginFrame(); } @@ -132,6 +133,7 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint) this->life = 100; this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; this->lookDir = Oyster::Math::Float4(1,0,0); + this->setState.SetCenterPosition(spawnPoint); } void Player::Rotate(const Oyster::Math3D::Float4 lookDir) @@ -187,5 +189,13 @@ PLAYER_STATE Player::GetState() const void Player::DamageLife(int damage) { this->life -= damage; + this->life = 0; + + if(this->life <= 0) + { + this->life = 0; + playerState = PLAYER_STATE_DEAD; + //do stuff that makes you dead + } } From 1261ed734fd4547f614e6ffca42a0d22586311cc Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 4 Feb 2014 11:36:10 +0100 Subject: [PATCH 2/2] GL - Updated level loader. --- .../GameLogic/LevelLoader/LevelParser.cpp | 50 +++++++++++++++---- .../GameLogic/LevelLoader/ObjectDefines.h | 16 +++--- .../GameLogic/LevelLoader/ParseFunctions.cpp | 30 ++++++++++- .../GameLogic/LevelLoader/ParseFunctions.h | 1 + 4 files changed, 78 insertions(+), 19 deletions(-) diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp index 3a20f192..088c3916 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp @@ -30,13 +30,14 @@ std::vector> LevelParser::Parse(std::string filen //Read format version FormatVersion levelFormatVersion; - //ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion)); + ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion)); + counter += sizeof(levelFormatVersion); if(this->formatVersion != levelFormatVersion) { //Do something if it's not the same version } - while(counter < bufferSize) + while(counter < bufferSize) { //Get typeID ObjectTypeHeader typeID; @@ -55,9 +56,8 @@ std::vector> LevelParser::Parse(std::string filen case ObjectType_Static: case ObjectType_Dynamic: { ObjectHeader* header = new ObjectHeader; - ParseObject(&buffer[counter], header, sizeof(*header)); + ParseObject(&buffer[counter], *header, counter); objects.push_back(header); - counter += sizeof(*header); break; } @@ -124,7 +124,8 @@ LevelMetaData LevelParser::ParseHeader(std::string filename) //Read format version FormatVersion levelFormatVersion; - //ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion)); + ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion)); + counter += sizeof(levelFormatVersion); if(this->formatVersion != levelFormatVersion) { //Do something if it's not the same version @@ -142,11 +143,42 @@ LevelMetaData LevelParser::ParseHeader(std::string filename) ParseLevelMetaData(&buffer[counter], levelHeader, counter); return levelHeader; break; - case ObjectType_Dynamic: - //Do not call parse this object, since we are only interested in the LevelMetaData - //Only increase the counter size - counter += sizeof(ObjectHeader); + + //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. + case ObjectType_Static: case ObjectType_Dynamic: + { + ObjectHeader header; + ParseObject(&buffer[counter], header, counter); break; + } + + case ObjectType_Light: + { + LightType lightType; + ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); + + switch(lightType) + { + case LightType_PointLight: + { + counter += sizeof(PointLight); + break; + } + case LightType_DirectionalLight: + { + counter += sizeof(DirectionalLight); + break; + } + case LightType_SpotLight: + { + counter += sizeof(SpotLight); + break; + } + default: + //Undefined LightType. + break; + } + } default: //Couldn't find typeID. FAIL!!!!!! diff --git a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h index 21e3a7e3..553db824 100644 --- a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h +++ b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h @@ -28,6 +28,7 @@ namespace GameLogic UsePhysics_UseFullPhysics, UsePhysics_IgnoreGravity, UsePhysics_IgnorePhysics, + UsePhysics_IgnoreCollision, UsePhysics_Count, UsePhysics_Unknown = -1 @@ -82,12 +83,13 @@ namespace GameLogic struct PhysicsObject { + UsePhysics usePhysics; float mass; - float elasticity; + float inertiaMagnitude[3]; + float inertiaRotation[3]; float frictionCoeffStatic; float frictionCoeffDynamic; - float inertiaTensor[16]; - UsePhysics usePhysics; + }; struct LevelMetaData : ObjectTypeHeader @@ -97,17 +99,15 @@ namespace GameLogic std::string levelDescription; std::string levelAuthor; int maxNumberOfPlayer; - float worldSize; - int overviewPictureID; + int worldSize; + std::string overviewPicturePath; std::vector gameModesSupported; }; struct ObjectHeader : public ObjectTypeHeader { //Model, - int ModelID; - //Texture - int TextureID; + std::string ModelFile; //Position float position[3]; //Rotation diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp index f456b2d7..8d51f308 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp @@ -20,11 +20,33 @@ namespace GameLogic memcpy(header, buffer, size); } + void ParseObject(char* buffer, ObjectHeader& header, int& size) + { + char tempName[128]; + int tempSize = 0; + int start = 0; + + memcpy(&header.typeID, &buffer[start], 4); + start += 4; + + memcpy(&tempSize, &buffer[start], 4); + start += 4; + + memcpy(&tempName, &buffer[start], tempSize); + header.ModelFile.assign(&tempName[0], &tempName[tempSize]); + start += tempSize; + + memcpy(&header.position, &buffer[start], 36); + start += 36; + + size += start; + } + void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size) { int start = 0; int tempSize; - char tempName[100]; + char tempName[128]; memcpy(&header.typeID, &buffer[start], 4); start += 4; @@ -59,9 +81,13 @@ namespace GameLogic memcpy(&header.worldSize, &buffer[start], 4); start += 4; - memcpy(&header.overviewPictureID, &buffer[start], 4); + memcpy(&tempSize, &buffer[start], 4); start += 4; + memcpy(&tempName, &buffer[start], tempSize); + header.overviewPicturePath.assign(&tempName[0], &tempName[tempSize]); + start += tempSize; + memcpy(&tempSize, &buffer[start], 4); start += 4; diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h index 554b95db..f68a9289 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h @@ -19,6 +19,7 @@ namespace GameLogic */ void ParseObject(char* buffer, void *header, int size); + void ParseObject(char* buffer, ObjectHeader& header, int& size); void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); } }