From 8708cfbee0d645d74a37f6fc7b35687e2f1f7650 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 27 Dec 2014 23:16:48 +1100 Subject: [PATCH] I give up, I'm just using the stop-dead system for now. --- client/entities/local_character.cpp | 12 ++++++++++++ client/entities/local_character.hpp | 6 ++++++ client/scenes/in_world.cpp | 19 ++++++++++++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/client/entities/local_character.cpp b/client/entities/local_character.cpp index 201ef48..16c1eff 100644 --- a/client/entities/local_character.cpp +++ b/client/entities/local_character.cpp @@ -21,3 +21,15 @@ */ #include "local_character.hpp" +#include + +bool LocalCharacter::ProcessCollisionGrid(std::list boxList) { + for(auto& box : boxList) { + if (box.CheckOverlap(origin + bounds)) { + origin -= motion; + motion = {0, 0}; + return true; + } + } + return false; +} \ No newline at end of file diff --git a/client/entities/local_character.hpp b/client/entities/local_character.hpp index 4493fb4..a462ddc 100644 --- a/client/entities/local_character.hpp +++ b/client/entities/local_character.hpp @@ -23,12 +23,18 @@ #define LOCALCHARACTER_HPP_ #include "base_character.hpp" +#include "bounding_box.hpp" +#include "vector2.hpp" + +#include class LocalCharacter: public BaseCharacter { public: LocalCharacter() = default; virtual ~LocalCharacter() = default; + bool ProcessCollisionGrid(std::list); + private: //NOTE: NO MEMBERS }; diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index a57ab29..7dff310 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -157,7 +157,10 @@ void InWorld::Update() { std::list boxList = GenerateCollisionGrid(localCharacter, tileSheet.GetTileW(), tileSheet.GetTileH()); //process the collisions - std::cout << "boxList.size(): " << boxList.size() << std::endl; + if (localCharacter->ProcessCollisionGrid(boxList)) { + localCharacter->CorrectSprite(); + SendLocalCharacterMotion(); + } //update the camera camera.x = localCharacter->GetOrigin().x - camera.marginX; @@ -672,6 +675,11 @@ void InWorld::HandleCharacterSetRoom(CharacterPacket* const argPacket) { } void InWorld::HandleCharacterSetOrigin(CharacterPacket* const argPacket) { + //TODO: Authentication + if (argPacket->characterIndex == characterIndex) { + return; + } + //check that this character exists std::map::iterator characterIt = characterMap.find(argPacket->characterIndex); if (characterIt != characterMap.end()) { @@ -683,6 +691,11 @@ void InWorld::HandleCharacterSetOrigin(CharacterPacket* const argPacket) { } void InWorld::HandleCharacterSetMotion(CharacterPacket* const argPacket) { + //TODO: Authentication + if (argPacket->characterIndex == characterIndex) { + return; + } + //check that this character exists std::map::iterator characterIt = characterMap.find(argPacket->characterIndex); if (characterIt != characterMap.end()) { @@ -719,10 +732,10 @@ std::list InWorld::GenerateCollisionGrid(Entity* ptr, int tileWidth //NOTE: for loops were too dense to work with, so I've just used while loops //outer loop - wallBounds.x = snapToBase((double)wallBounds.w, ptr->GetOrigin().x) - wallBounds.w; + wallBounds.x = snapToBase((double)wallBounds.w, ptr->GetOrigin().x); while(wallBounds.x < (ptr->GetOrigin() + ptr->GetBounds()).x + ptr->GetBounds().w) { //inner loop - wallBounds.y = snapToBase((double)wallBounds.h, ptr->GetOrigin().y) - wallBounds.h; + wallBounds.y = snapToBase((double)wallBounds.h, ptr->GetOrigin().y); while(wallBounds.y < (ptr->GetOrigin() + ptr->GetBounds()).y + ptr->GetBounds().h) { //check to see if this tile is solid if (regionPager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) {