diff --git a/client/entities/local_character.cpp b/client/entities/local_character.cpp index 52dcf9f..636ff3b 100644 --- a/client/entities/local_character.cpp +++ b/client/entities/local_character.cpp @@ -21,15 +21,17 @@ */ #include "local_character.hpp" -void LocalCharacter::ProcessCollisions(std::list& boxList) { +bool LocalCharacter::ProcessCollisions(std::list& boxList) { if (CheckCollisionSimple(boxList, origin + motion)) { Vector2 velocity; velocity.x = CorrectVelocityX(boxList, motion.x); velocity.y = CorrectVelocityY(boxList, motion.y); origin += velocity; + return true; } else { origin += motion; + return false; } } @@ -47,10 +49,12 @@ double LocalCharacter::CorrectVelocityX(std::list& boxList, double for (auto& it : boxList) { if (it.CheckOverlap(bounds + origin + Vector2(velocityX, 0) )) { if (velocityX > 0) { - ret = std::min(ret, it.x - origin.x - (bounds.w - bounds.x - 1)); + ret = std::min(ret, it.x - (origin.x + bounds.x + bounds.w -1)); + ret = std::min(ret, 0.0); } else if (velocityX < 0) { - ret = std::max(ret, (it.x + it.w) - origin.x); + ret = std::max(ret, (it.x + it.w) - (origin.x + bounds.x)); + ret = std::max(ret, 0.0); } } } @@ -58,5 +62,18 @@ double LocalCharacter::CorrectVelocityX(std::list& boxList, double } double LocalCharacter::CorrectVelocityY(std::list& boxList, double velocityY) { - return velocityY; + double ret = velocityY; + for (auto& it : boxList) { + if (it.CheckOverlap(bounds + origin + Vector2(0, velocityY) )) { + if (velocityY > 0) { + ret = std::min(ret, it.y - (origin.y + bounds.y + bounds.h -1)); + ret = std::min(ret, 0.0); + } + else if (velocityY < 0) { + ret = std::max(ret, (it.y + it.h) - (origin.y + bounds.y)); + ret = std::max(ret, 0.0); + } + } + } + return ret; } diff --git a/client/entities/local_character.hpp b/client/entities/local_character.hpp index 9726d3e..546b5cd 100644 --- a/client/entities/local_character.hpp +++ b/client/entities/local_character.hpp @@ -33,7 +33,7 @@ public: LocalCharacter() = default; virtual ~LocalCharacter() = default; - void ProcessCollisions(std::list& boxList); + bool ProcessCollisions(std::list& boxList); protected: bool CheckCollisionSimple(std::list& boxList, Vector2 newPos); diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 680d2c0..f28b995 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -154,11 +154,7 @@ void InWorld::Update() { //update all entities for (auto& it : characterMap) { - //skip this player's character - if (it.first == characterIndex) { - continue; - } - it.second.Update(); +// it.second.Update(); } for (auto& it : monsterMap) { it.second.Update(); diff --git a/common/utilities/vector2.hpp b/common/utilities/vector2.hpp index e1688d4..00f4a06 100644 --- a/common/utilities/vector2.hpp +++ b/common/utilities/vector2.hpp @@ -92,6 +92,10 @@ public: return ret; } + //unary operators + Vector2 operator-() { return {-x, -y}; } + + //comparison operators bool operator==(Vector2 v) { return (x == v.x && y == v.y); } bool operator!=(Vector2 v) { return (x != v.x || y != v.y); }