diff --git a/assets/heal-ring/heal-ring.bin b/assets/heal-ring/heal-ring.bin new file mode 100644 index 0000000..676b894 Binary files /dev/null and b/assets/heal-ring/heal-ring.bin differ diff --git a/assets/heal-ring/heal-ring.gltf b/assets/heal-ring/heal-ring.gltf new file mode 100644 index 0000000..b835d20 --- /dev/null +++ b/assets/heal-ring/heal-ring.gltf @@ -0,0 +1,142 @@ +{ + "asset":{ + "generator":"Khronos glTF Blender I/O v4.1.63", + "version":"2.0" + }, + "scene":0, + "scenes":[ + { + "name":"Scene", + "nodes":[ + 0 + ] + } + ], + "nodes":[ + { + "mesh":0, + "name":"Torus.001", + "scale":[ + 10, + 10, + 10 + ] + } + ], + "materials":[ + { + "doubleSided":true, + "name":"Material.001", + "pbrMetallicRoughness":{ + "baseColorTexture":{ + "index":0 + }, + "metallicFactor":0, + "roughnessFactor":0.5 + } + } + ], + "meshes":[ + { + "name":"Torus.001", + "primitives":[ + { + "attributes":{ + "POSITION":0, + "NORMAL":1, + "TEXCOORD_0":2 + }, + "indices":3, + "material":0 + } + ] + } + ], + "textures":[ + { + "sampler":0, + "source":0 + } + ], + "images":[ + { + "mimeType":"image/png", + "name":"healthy-green", + "uri":"healthy-green.png" + } + ], + "accessors":[ + { + "bufferView":0, + "componentType":5126, + "count":5184, + "max":[ + 1.0174199342727661, + 0.017349302768707275, + 1.0174199342727661 + ], + "min":[ + -1.0174199342727661, + -0.017349302768707275, + -1.0174199342727661 + ], + "type":"VEC3" + }, + { + "bufferView":1, + "componentType":5126, + "count":5184, + "type":"VEC3" + }, + { + "bufferView":2, + "componentType":5126, + "count":5184, + "type":"VEC2" + }, + { + "bufferView":3, + "componentType":5123, + "count":7776, + "type":"SCALAR" + } + ], + "bufferViews":[ + { + "buffer":0, + "byteLength":62208, + "byteOffset":0, + "target":34962 + }, + { + "buffer":0, + "byteLength":62208, + "byteOffset":62208, + "target":34962 + }, + { + "buffer":0, + "byteLength":41472, + "byteOffset":124416, + "target":34962 + }, + { + "buffer":0, + "byteLength":15552, + "byteOffset":165888, + "target":34963 + } + ], + "samplers":[ + { + "magFilter":9729, + "minFilter":9987 + } + ], + "buffers":[ + { + "byteLength":181440, + "uri":"heal-ring.bin" + } + ] +} diff --git a/assets/heal-ring/healthy-green.png b/assets/heal-ring/healthy-green.png new file mode 100644 index 0000000..c1f899a Binary files /dev/null and b/assets/heal-ring/healthy-green.png differ diff --git a/assets/revive-ring/revive-ring.bin b/assets/revive-ring/revive-ring.bin new file mode 100644 index 0000000..676b894 Binary files /dev/null and b/assets/revive-ring/revive-ring.bin differ diff --git a/assets/revive-ring/revive-ring.gltf b/assets/revive-ring/revive-ring.gltf new file mode 100644 index 0000000..247d301 --- /dev/null +++ b/assets/revive-ring/revive-ring.gltf @@ -0,0 +1,142 @@ +{ + "asset":{ + "generator":"Khronos glTF Blender I/O v4.1.63", + "version":"2.0" + }, + "scene":0, + "scenes":[ + { + "name":"Scene", + "nodes":[ + 0 + ] + } + ], + "nodes":[ + { + "mesh":0, + "name":"Torus.001", + "scale":[ + 10, + 10, + 10 + ] + } + ], + "materials":[ + { + "doubleSided":true, + "name":"Material.001", + "pbrMetallicRoughness":{ + "baseColorTexture":{ + "index":0 + }, + "metallicFactor":0, + "roughnessFactor":0.5 + } + } + ], + "meshes":[ + { + "name":"Torus.001", + "primitives":[ + { + "attributes":{ + "POSITION":0, + "NORMAL":1, + "TEXCOORD_0":2 + }, + "indices":3, + "material":0 + } + ] + } + ], + "textures":[ + { + "sampler":0, + "source":0 + } + ], + "images":[ + { + "mimeType":"image/png", + "name":"revive-yellow", + "uri":"revive-yellow.png" + } + ], + "accessors":[ + { + "bufferView":0, + "componentType":5126, + "count":5184, + "max":[ + 1.0174199342727661, + 0.017349302768707275, + 1.0174199342727661 + ], + "min":[ + -1.0174199342727661, + -0.017349302768707275, + -1.0174199342727661 + ], + "type":"VEC3" + }, + { + "bufferView":1, + "componentType":5126, + "count":5184, + "type":"VEC3" + }, + { + "bufferView":2, + "componentType":5126, + "count":5184, + "type":"VEC2" + }, + { + "bufferView":3, + "componentType":5123, + "count":7776, + "type":"SCALAR" + } + ], + "bufferViews":[ + { + "buffer":0, + "byteLength":62208, + "byteOffset":0, + "target":34962 + }, + { + "buffer":0, + "byteLength":62208, + "byteOffset":62208, + "target":34962 + }, + { + "buffer":0, + "byteLength":41472, + "byteOffset":124416, + "target":34962 + }, + { + "buffer":0, + "byteLength":15552, + "byteOffset":165888, + "target":34963 + } + ], + "samplers":[ + { + "magFilter":9729, + "minFilter":9987 + } + ], + "buffers":[ + { + "byteLength":181440, + "uri":"revive-ring.bin" + } + ] +} diff --git a/assets/revive-ring/revive-yellow.png b/assets/revive-ring/revive-yellow.png new file mode 100644 index 0000000..6a62860 Binary files /dev/null and b/assets/revive-ring/revive-yellow.png differ diff --git a/assets/speedup-ring/speedup-blue.png b/assets/speedup-ring/speedup-blue.png new file mode 100644 index 0000000..04b576c Binary files /dev/null and b/assets/speedup-ring/speedup-blue.png differ diff --git a/assets/speedup-ring/speedup-ring.bin b/assets/speedup-ring/speedup-ring.bin new file mode 100644 index 0000000..676b894 Binary files /dev/null and b/assets/speedup-ring/speedup-ring.bin differ diff --git a/assets/speedup-ring/speedup-ring.gltf b/assets/speedup-ring/speedup-ring.gltf new file mode 100644 index 0000000..b38975c --- /dev/null +++ b/assets/speedup-ring/speedup-ring.gltf @@ -0,0 +1,142 @@ +{ + "asset":{ + "generator":"Khronos glTF Blender I/O v4.1.63", + "version":"2.0" + }, + "scene":0, + "scenes":[ + { + "name":"Scene", + "nodes":[ + 0 + ] + } + ], + "nodes":[ + { + "mesh":0, + "name":"Torus.001", + "scale":[ + 10, + 10, + 10 + ] + } + ], + "materials":[ + { + "doubleSided":true, + "name":"Material.001", + "pbrMetallicRoughness":{ + "baseColorTexture":{ + "index":0 + }, + "metallicFactor":0, + "roughnessFactor":0.5 + } + } + ], + "meshes":[ + { + "name":"Torus.001", + "primitives":[ + { + "attributes":{ + "POSITION":0, + "NORMAL":1, + "TEXCOORD_0":2 + }, + "indices":3, + "material":0 + } + ] + } + ], + "textures":[ + { + "sampler":0, + "source":0 + } + ], + "images":[ + { + "mimeType":"image/png", + "name":"speedup-blue", + "uri":"speedup-blue.png" + } + ], + "accessors":[ + { + "bufferView":0, + "componentType":5126, + "count":5184, + "max":[ + 1.0174199342727661, + 0.017349302768707275, + 1.0174199342727661 + ], + "min":[ + -1.0174199342727661, + -0.017349302768707275, + -1.0174199342727661 + ], + "type":"VEC3" + }, + { + "bufferView":1, + "componentType":5126, + "count":5184, + "type":"VEC3" + }, + { + "bufferView":2, + "componentType":5126, + "count":5184, + "type":"VEC2" + }, + { + "bufferView":3, + "componentType":5123, + "count":7776, + "type":"SCALAR" + } + ], + "bufferViews":[ + { + "buffer":0, + "byteLength":62208, + "byteOffset":0, + "target":34962 + }, + { + "buffer":0, + "byteLength":62208, + "byteOffset":62208, + "target":34962 + }, + { + "buffer":0, + "byteLength":41472, + "byteOffset":124416, + "target":34962 + }, + { + "buffer":0, + "byteLength":15552, + "byteOffset":165888, + "target":34963 + } + ], + "samplers":[ + { + "magFilter":9729, + "minFilter":9987 + } + ], + "buffers":[ + { + "byteLength":181440, + "uri":"speedup-ring.bin" + } + ] +} diff --git a/client/main.cpp b/client/main.cpp index f1a3caf..8005c85 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -139,6 +139,9 @@ int main(int argc, char** argv) { modelPaths.push_back({"../assets/swipe-attack/swipe-attack.gltf", false}); modelPaths.push_back( {"../assets/player-note-attack/player-note-attack.gltf", false}); + modelPaths.push_back({"../assets/heal-ring/heal-ring.gltf", false}); + modelPaths.push_back({"../assets/revive-ring/revive-ring.gltf", false}); + modelPaths.push_back({"../assets/speedup-ring/speedup-ring.gltf", false}); modelPaths.push_back({"../assets/arena/arena.gltf", false}); for (std::pair kv : modelPaths) { diff --git a/client/prefabs/PlayerSkill.cpp b/client/prefabs/PlayerSkill.cpp index b2f7fa1..c2dd76a 100644 --- a/client/prefabs/PlayerSkill.cpp +++ b/client/prefabs/PlayerSkill.cpp @@ -9,6 +9,12 @@ std::string playerAttackPath = "../assets/player-note-attack/player-note-attack.gltf"; +std::string playerHealPath = + "../assets/heal-ring/heal-ring.gltf"; +std::string playerRevivePath = + "../assets/revive-ring/revive-ring.gltf"; +std::string playerSpeedBoostPath = + "../assets/speedup-ring/speedup-ring.gltf"; PlayerSkill::PlayerSkill() : Entity() { PlayerSkillType* skillType = new PlayerSkillType(this); @@ -31,15 +37,21 @@ void PlayerSkill::initComponent(int skillType) { printf("PlayerAttack!\n"); break; case (int)SkillType::HEAL: - // model = new Model(AssetManager::Instance().GetModel(path)); + GetComponent()->SetScale(glm::vec3(1.0f)); + meshRenderer = new RendererComponent(this, ShaderType::STANDARD); + model = new Model(AssetManager::Instance().GetModel(playerHealPath)); printf("PlayerHeal!\n"); break; case (int)SkillType::REVIVE: - // model = new Model(AssetManager::Instance().GetModel(path)); + GetComponent()->SetScale(glm::vec3(1.0f)); + meshRenderer = new RendererComponent(this, ShaderType::STANDARD); + model = new Model(AssetManager::Instance().GetModel(playerRevivePath)); printf("PlayerRevive!\n"); break; case (int)SkillType::SPEED_BOOST: - // model = new Model(AssetManager::Instance().GetModel(path)); + GetComponent()->SetScale(glm::vec3(1.0f)); + meshRenderer = new RendererComponent(this, ShaderType::STANDARD); + model = new Model(AssetManager::Instance().GetModel(playerSpeedBoostPath)); printf("PlayerSpeedBoost!\n"); break; } diff --git a/server/prefabs/EnemyMover.cpp b/server/prefabs/EnemyMover.cpp index 7d6102d..1d4c095 100644 --- a/server/prefabs/EnemyMover.cpp +++ b/server/prefabs/EnemyMover.cpp @@ -3,6 +3,8 @@ #include "Client.hpp" #include "Enemy.hpp" #include "CollisionManager.hpp" +#include "Health.hpp" +#include EnemyMover::EnemyMover(GameObject* owner) : @@ -27,9 +29,12 @@ void EnemyMover::Update(float deltaTime) { return; } - targetPlayer = clients[0]->p; - float minDistance = glm::distance(clients[0]->p->GetComponent()->GetPosition(), position); - for (int i = 1; i < clients.size(); ++i) { + float minDistance = std::numeric_limits::infinity(); + for (int i = 0; i < clients.size(); ++i) { + // only target alive players + if (clients[i]->p->GetComponent()->GetDead()) { + continue; + } Player* currPlayer = clients[i]->p; float currDistance = glm::distance(currPlayer->GetComponent()->GetPosition(), position); if (currDistance < minDistance) { @@ -56,6 +61,17 @@ void EnemyMover::Update(float deltaTime) { } else { position = glm::vec3(); collider->SetPosition(glm::vec3()); + if (CollisionManager::instance().checkCollisionCylinder(collider)) { + if (transparent) { + CollisionManager::instance().remove(owner); + } + } + else { + if (transparent) { + CollisionManager::instance().add(owner); + transparent = false; + } + } } } diff --git a/server/prefabs/EnemyMover.hpp b/server/prefabs/EnemyMover.hpp index 3634b12..7427dea 100644 --- a/server/prefabs/EnemyMover.hpp +++ b/server/prefabs/EnemyMover.hpp @@ -12,6 +12,7 @@ class EnemyMover : public IComponent { float baseSpeed = 0.66f; glm::vec3& position; glm::vec3& rotation; + bool transparent = true; EnemyMover(GameObject* owner); diff --git a/server/prefabs/Heal.hpp b/server/prefabs/Heal.hpp index 9aeac2e..9a957c2 100644 --- a/server/prefabs/Heal.hpp +++ b/server/prefabs/Heal.hpp @@ -12,6 +12,8 @@ class Heal : public PlayerSkill { int amount; Collider* range; float radius = 10.0f; + float life = 0.3f; + bool dealt = false; Heal(Player* p); Heal(Player* p, int networkId); diff --git a/server/prefabs/Revive.hpp b/server/prefabs/Revive.hpp index 39f7659..5453fa9 100644 --- a/server/prefabs/Revive.hpp +++ b/server/prefabs/Revive.hpp @@ -12,6 +12,8 @@ class Revive : public PlayerSkill { int amount; Collider* range; float radius = 10.0f; + float life = 0.3f; + bool dealt = false; Revive(Player* p); Revive(Player* p, int networkId); diff --git a/server/prefabs/SpeedUp.hpp b/server/prefabs/SpeedUp.hpp index 96bccd2..f4d1782 100644 --- a/server/prefabs/SpeedUp.hpp +++ b/server/prefabs/SpeedUp.hpp @@ -12,6 +12,8 @@ class SpeedUp : public PlayerSkill { int amount; Collider* range; float radius = 10.0f; + float life = 0.3f; + bool dealt = false; SpeedUp(Player* p); SpeedUp(Player* p, int networkId); diff --git a/server/prefabs/playerSkills/Heal.cpp b/server/prefabs/playerSkills/Heal.cpp index 31f6e00..dc7cbaf 100644 --- a/server/prefabs/playerSkills/Heal.cpp +++ b/server/prefabs/playerSkills/Heal.cpp @@ -6,20 +6,29 @@ Heal::Heal(Player* p) : PlayerSkill() { range = new Collider(this, p->GetComponent()); range->SetRadius(radius); this->GetComponent()->SetState(SkillType::HEAL); + this->GetComponent()->SetPosition(p->GetComponent()->GetPosition()); } Heal::Heal(Player* p, int networkId) : PlayerSkill(networkId) { range = new Collider(this, p->GetComponent()); range->SetRadius(radius); this->GetComponent()->SetState(SkillType::HEAL); + this->GetComponent()->SetPosition(p->GetComponent()->GetPosition()); } void Heal::update(float deltaTime) { - std::vector hitObjects = CollisionManager::instance().doPlayerEffect(range); - for (GameObject* g : hitObjects) { - if (Player* p = dynamic_cast(g)) { - p->GetComponent()->AddStatusEffect(new HealEffect(p->GetComponent())); + if (!dealt) { + std::vector hitObjects = CollisionManager::instance().doPlayerEffect(range); + for (GameObject* g : hitObjects) { + if (Player* p = dynamic_cast(g)) { + p->GetComponent()->AddStatusEffect(new HealEffect(p->GetComponent())); + } } + dealt = true; + } + + life -= deltaTime; + if (life < 0) { + exist = false; } - exist = false; } \ No newline at end of file diff --git a/server/prefabs/playerSkills/Revive.cpp b/server/prefabs/playerSkills/Revive.cpp index 936aaa9..45ac4dd 100644 --- a/server/prefabs/playerSkills/Revive.cpp +++ b/server/prefabs/playerSkills/Revive.cpp @@ -5,20 +5,29 @@ Revive::Revive(Player* p) : PlayerSkill() { range = new Collider(this, p->GetComponent()); range->SetRadius(radius); this->GetComponent()->SetState(SkillType::REVIVE); + this->GetComponent()->SetPosition(p->GetComponent()->GetPosition()); } Revive::Revive(Player* p, int networkId) : PlayerSkill(networkId) { range = new Collider(this, p->GetComponent()); range->SetRadius(radius); this->GetComponent()->SetState(SkillType::REVIVE); + this->GetComponent()->SetPosition(p->GetComponent()->GetPosition()); } void Revive::update(float deltaTime) { - std::vector hitObjects = CollisionManager::instance().doPlayerEffect(range); - for (GameObject* g : hitObjects) { - if (Player* p = dynamic_cast(g)) { - p->GetComponent()->revive(); + if (!dealt) { + std::vector hitObjects = CollisionManager::instance().doPlayerEffect(range); + for (GameObject* g : hitObjects) { + if (Player* p = dynamic_cast(g)) { + p->GetComponent()->revive(); + } } + dealt = true; + } + + life -= deltaTime; + if (life < 0) { + exist = false; } - exist = false; } \ No newline at end of file diff --git a/server/prefabs/playerSkills/SpeedUp.cpp b/server/prefabs/playerSkills/SpeedUp.cpp index 9654972..95d1619 100644 --- a/server/prefabs/playerSkills/SpeedUp.cpp +++ b/server/prefabs/playerSkills/SpeedUp.cpp @@ -6,20 +6,29 @@ SpeedUp::SpeedUp(Player* p) : PlayerSkill() { range = new Collider(this, p->GetComponent()); range->SetRadius(radius); this->GetComponent()->SetState(SkillType::SPEED_BOOST); + this->GetComponent()->SetPosition(p->GetComponent()->GetPosition()); } SpeedUp::SpeedUp(Player* p, int networkId) : PlayerSkill(networkId) { range = new Collider(this, p->GetComponent()); range->SetRadius(radius); this->GetComponent()->SetState(SkillType::SPEED_BOOST); + this->GetComponent()->SetPosition(p->GetComponent()->GetPosition()); } void SpeedUp::update(float deltaTime) { - std::vector hitObjects = CollisionManager::instance().doPlayerEffect(range); - for (GameObject* g : hitObjects) { - if (Player* p = dynamic_cast(g)) { - p->GetComponent()->AddStatusEffect(new SpeedBoost(p->GetComponent())); + if (!dealt) { + std::vector hitObjects = CollisionManager::instance().doPlayerEffect(range); + for (GameObject* g : hitObjects) { + if (Player* p = dynamic_cast(g)) { + p->GetComponent()->AddStatusEffect(new SpeedBoost(p->GetComponent())); + } } + dealt = true; + } + + life -= deltaTime; + if (life < 0) { + exist = false; } - exist = false; } \ No newline at end of file diff --git a/server/src/CollisionManager.cpp b/server/src/CollisionManager.cpp index 2c51b1c..2d62bd8 100644 --- a/server/src/CollisionManager.cpp +++ b/server/src/CollisionManager.cpp @@ -237,7 +237,10 @@ bool CollisionManager::checkCollisionCylinder(Collider* cyl) { if (collisionCylinderBoundary(cyl)) { return true; } - GameObject* cylOwner = colliderOwners.at(cyl); + GameObject* cylOwner = nullptr; + if (colliderOwners.find(cyl) != colliderOwners.end()) { + cylOwner = colliderOwners.at(cyl); + } for (const auto& pair : colliderOwners) { if (cylOwner != pair.second) { if (!pair.first->GetIsSector() && !pair.first->GetIsPoint() &&