From 423e6d0d35162b6f4bee6ec465bb24922b1e0cb1 Mon Sep 17 00:00:00 2001 From: Vectozavr <60608292+vectozavr@users.noreply.github.com> Date: Sat, 9 Oct 2021 18:38:24 +0700 Subject: [PATCH] OS Windows support --- Player.h | 7 ------- Shooter.cpp | 7 +++---- Source.cpp | 2 +- engine/World.cpp | 21 +++++++++++++-------- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/Player.h b/Player.h index 31b29fc..02c6b0f 100644 --- a/Player.h +++ b/Player.h @@ -38,8 +38,6 @@ private: sf::Sound _fullHealthSound; sf::Sound _fullAbilitySound; - std::string _name = "im"; - std::vector> _weapons; size_t _selectedWeapon = 0; @@ -67,14 +65,9 @@ public: setCollisionCallBack([this](const std::string& objName, std::shared_ptr obj) {collisionWithObject(objName, obj);}); }; - [[nodiscard]] std::string name() const { return "Player_" + _name; } - void setHealth(double h) { _health = h; } - void setAbility(double a) { - _ability = a; - } [[nodiscard]] double health() const { return _health; } [[nodiscard]] double ability() const { return _ability; } diff --git a/Shooter.cpp b/Shooter.cpp index 2616db9..0f37bf4 100644 --- a/Shooter.cpp +++ b/Shooter.cpp @@ -6,7 +6,6 @@ #include #include "engine/animation/AColor.h" #include "engine/animation/AFunction.h" -#include "engine/animation/ATranslate.h" #include "engine/animation/ARotate.h" #include "engine/animation/Timeline.h" @@ -86,7 +85,7 @@ void Shooter::start() { camera->translateToPoint(player->position() + Point4D{0, 1.8, 0}); player->attach(camera, "camera"); - world->addBody(player, player->name()); + world->addBody(player, "Player"); player->translate(Point4D{0, 10, 0}); client = std::make_shared(player); @@ -201,7 +200,7 @@ void Shooter::play() { } void Shooter::spawnPlayer(sf::Uint16 id) { - std::string name = "Player_" + std::to_string(id); + std::string name = "Enemy_" + std::to_string(id); std::shared_ptr newPlayer = std::make_shared(); newPlayer->setCollision(false); @@ -230,7 +229,7 @@ void Shooter::spawnPlayer(sf::Uint16 id) { } void Shooter::removePlayer(sf::Uint16 id) { - std::string name = "Player_" + std::to_string(id); + std::string name = "Enemy_" + std::to_string(id); world->removeBody(name); world->removeBody(name + "_head"); world->removeBody(name + "_eye1"); diff --git a/Source.cpp b/Source.cpp index 2e83cda..11fc60f 100644 --- a/Source.cpp +++ b/Source.cpp @@ -1,5 +1,5 @@ // -// Created by Èâàí Èëüèí on 06.02.2021. +// Created by Ivan Ilin on 06.02.2021. // #include "Shooter.h" diff --git a/engine/World.cpp b/engine/World.cpp index 64b62d9..a2e6c38 100644 --- a/engine/World.cpp +++ b/engine/World.cpp @@ -25,7 +25,7 @@ std::pair World::rayCast(const Point4D& from, const Point4D& to double minDistance = 10000; for(auto& object : _objects) { - if((object.first.find("im") != std::string::npos) || (object.first.find("nr") != std::string::npos)) + if((object.first.find("Player") != std::string::npos) || (object.first.find("Bonus") != std::string::npos)) continue; for(auto& tri : object.second->triangles()) { @@ -63,16 +63,21 @@ void World::checkCollision(const std::string& body) { _objects[body]->setInCollision(false); - for (auto &obj : _objects) { - if(obj.first != body) { - std::pair gjk = _objects[body]->checkGJKCollision(obj.second); + for (auto it = _objects.begin(); it != _objects.end();) { + + auto obj = it->second; + std::string name = it->first; + it++; + + if(name != body) { + std::pair gjk = _objects[body]->checkGJKCollision(obj); if (gjk.first) { - if (obj.second->isCollider()) { - CollisionPoint epa = _objects[body]->EPA(gjk.second, obj.second); - Solver::solveCollision(_objects[body], obj.second, epa); + if (obj->isCollider()) { + CollisionPoint epa = _objects[body]->EPA(gjk.second, obj); + Solver::solveCollision(_objects[body], obj, epa); } if (_objects[body]->collisionCallBack() != nullptr) - _objects[body]->collisionCallBack()(obj.first, obj.second); + _objects[body]->collisionCallBack()(name, obj); } } }