diff --git a/Shooter.cpp b/Shooter.cpp index 229deb4..3ee97f0 100644 --- a/Shooter.cpp +++ b/Shooter.cpp @@ -77,14 +77,12 @@ void Shooter::start() { world->loadMap(ShooterConsts::MAP_OBJ, Vec3D{5, 5, 5}); - player = std::make_shared(ObjectNameTag("Player")); player->scale(Vec3D(3, 1, 3)); - playerController = std::make_shared(player, keyboard, mouse); // TODO: encapsulate call backs inside Player player->setAddTraceCallBack([this](const Vec3D& from, const Vec3D& to){ client->addTrace(from, to); addFireTrace(from, to); }); player->setDamagePlayerCallBack([this] (sf::Uint16 targetId, double damage) { client->damagePlayer(targetId, damage); }); - player->setRayCastFunction([this](const Vec3D& from, const Vec3D& to) { return world->rayCast(from, to, "weapon Player"); }); + player->setRayCastFunction([this](const Vec3D& from, const Vec3D& to) { return world->rayCast(from, to, "Player Weapon"); }); player->setTakeBonusCallBack([this] (const string& bonusName) { client->takeBonus(bonusName); }); player->setAddWeaponCallBack([this](std::shared_ptr weapon){ addWeapon(std::move(weapon)); }); player->setRemoveWeaponCallBack([this](std::shared_ptr weapon){ removeWeapon(std::move(weapon)); }); @@ -97,9 +95,6 @@ void Shooter::start() { world->addBody(player); player->translate(Vec3D{0, 10, 0}); - client = std::make_shared(player); - server = std::make_shared(); - // connecting to the server InitNetwork(); // Waiting for connect and updating server if it's same window diff --git a/Shooter.h b/Shooter.h index 9041c9e..6c37f25 100644 --- a/Shooter.h +++ b/Shooter.h @@ -17,15 +17,13 @@ class Shooter final : public Engine { private: - std::shared_ptr player; - std::shared_ptr playerController; - - sf::Sound backgroundNoise; + std::shared_ptr player = std::make_shared(ObjectNameTag("Player"));; + std::shared_ptr playerController = std::make_shared(player, keyboard, mouse); Window mainMenu; - std::shared_ptr server; - std::shared_ptr client; + std::shared_ptr server = std::make_shared(); + std::shared_ptr client = std::make_shared(player); bool inGame = false; diff --git a/engine/World.cpp b/engine/World.cpp index 7b41482..6b6f8d4 100644 --- a/engine/World.cpp +++ b/engine/World.cpp @@ -24,10 +24,12 @@ void World::loadBody(const ObjectNameTag& tag, const string &filename, const Vec IntersectionInformation World::rayCast(const Vec3D& from, const Vec3D& to, const std::string& skipTags) { // make vector of tags, that we are going to escape - vector tagsToSkip; + vector tagsToSkip; stringstream s(skipTags); std::string t; - while (s >> t) tagsToSkip.push_back(t); + while (s >> t) { + tagsToSkip.push_back(t); + } bool intersected = false; Vec3D point{}; @@ -38,13 +40,13 @@ IntersectionInformation World::rayCast(const Vec3D& from, const Vec3D& to, const for(auto& [name, body] : _objects) { - - // TODO: check this stuff: - //for (auto& escapeTag : tagsToSkip) - // if(name.str().find(escapeTag) != std::string::npos) - // continue; - - if(name.str().find("Player") != std::string::npos || name.str().find("weapon") != std::string::npos) { + bool escapeThisBody = false; + for (auto& escapeTag : tagsToSkip) { + if (name.str().find(escapeTag) != std::string::npos) { + escapeThisBody = true; + } + } + if(escapeThisBody) { continue; }