From 0b512305a9cba4dba65e9035e114730144605a0e Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 31 Jul 2014 20:04:53 +1000 Subject: [PATCH] Added last additions from jam (read more) I should also mention that the client is throwing up a warning that HandleCharacterUpdate() is passing to HandleCharacterNew(). --- client/character.hpp | 7 ++++--- client/scenes/in_world.cpp | 42 ++++++++++++++++++++++++++++++------- client/scenes/main_menu.cpp | 1 + server/linit.cpp | 2 ++ 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/client/character.hpp b/client/character.hpp index ca2d9a4..bde4268 100644 --- a/client/character.hpp +++ b/client/character.hpp @@ -25,6 +25,7 @@ //components #include "character_defines.hpp" #include "vector2.hpp" +#include "bounding_box.hpp" #include "statistics.hpp" //graphics @@ -64,8 +65,8 @@ public: Vector2 GetOrigin() const { return origin; } Vector2 SetMotion(Vector2 v) { return motion = v; } Vector2 GetMotion() const { return motion; } - Vector2 SetBounds(Vector2 v) { return bounds = v; } - Vector2 GetBounds() const { return bounds; } + BoundingBox SetBounds(BoundingBox b) { return bounds = b; } + BoundingBox GetBounds() { return bounds; } private: //graphics @@ -84,7 +85,7 @@ private: //position Vector2 origin = {0.0,0.0}; Vector2 motion = {0.0,0.0}; - Vector2 bounds = {CHARACTER_BOUNDS_WIDTH,CHARACTER_BOUNDS_HEIGHT}; + BoundingBox bounds; }; //tmp diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index e8f2d62..59f43ba 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -106,16 +106,41 @@ void InWorld::Update(double delta) { it.second.Update(delta); } - //TODO: Check collisions here - - //update the camera - if(localCharacter) { - camera.x = localCharacter->GetOrigin().x - camera.marginX; - camera.y = localCharacter->GetOrigin().y - camera.marginY; - } - //check the map UpdateMap(); + + //skip the rest + if (!localCharacter) { + return; + } + + //check for collisions with the map + BoundingBox wallBounds = {0, 0, tileSheet.GetTileW(), tileSheet.GetTileH()}; + const int xCount = localCharacter->GetBounds().w / wallBounds.w + 1; + const int yCount = localCharacter->GetBounds().h / wallBounds.h + 1; + + for (int i = -1; i <= xCount; ++i) { + for (int j = -1; j <= yCount; ++j) { + //set the wall's position + wallBounds.x = wallBounds.w * i + snapToBase((double)wallBounds.w, localCharacter->GetOrigin().x); + wallBounds.y = wallBounds.h * j + snapToBase((double)wallBounds.h, localCharacter->GetOrigin().y); + + if (!regionPager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) { + continue; + } + + if ((localCharacter->GetOrigin() + localCharacter->GetBounds()).CheckOverlap(wallBounds)) { + localCharacter->SetOrigin(localCharacter->GetOrigin() - (localCharacter->GetMotion() * delta)); + localCharacter->SetMotion({0,0}); + localCharacter->CorrectSprite(); + SendPlayerUpdate(); + } + } + } + + //update the camera + camera.x = localCharacter->GetOrigin().x - camera.marginX; + camera.y = localCharacter->GetOrigin().y - camera.marginY; } void InWorld::FrameEnd() { @@ -281,6 +306,7 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) { newCharacter.SetOrigin(argPacket->origin); newCharacter.SetMotion(argPacket->motion); + newCharacter.SetBounds({0, 16, 32, 32}); //TODO: magic numbers, fix this (*newCharacter.GetStats()) = argPacket->stats; diff --git a/client/scenes/main_menu.cpp b/client/scenes/main_menu.cpp index 735e2fb..d722141 100644 --- a/client/scenes/main_menu.cpp +++ b/client/scenes/main_menu.cpp @@ -101,6 +101,7 @@ void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) { } void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) { + //TODO: Buttons should only register as "selected" when the left button is used if (startButton.MouseButtonUp(button) == Button::State::HOVER) { SetNextScene(SceneList::LOBBYMENU); } diff --git a/server/linit.cpp b/server/linit.cpp index 1d79c96..072120f 100644 --- a/server/linit.cpp +++ b/server/linit.cpp @@ -38,6 +38,7 @@ #include "region_api.hpp" #include "region_pager_api.hpp" +#include "tile_sheet_api.hpp" #include "room_api.hpp" #include "room_mgr_api.hpp" @@ -58,6 +59,7 @@ static const luaL_Reg loadedlibs[] = { //Tortuga's API {TORTUGA_REGION_NAME, openRegionAPI}, {TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI}, + {TORTUGA_TILE_SHEET_NAME, openTileSheetAPI}, {TORTUGA_ROOM_NAME, openRoomAPI}, {TORTUGA_ROOM_MGR_NAME, openRoomMgrAPI},