diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index 5c0f169..e8c1fc7 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp @@ -33,6 +33,7 @@ https://github.com/sago007/saland #include "../sago/SagoMisc.hpp" #include "../sago/SagoTextField.hpp" #include "globals.hpp" +#include "../common.h" #include "model/placeables.hpp" #include "model/spells.hpp" #include "model/Player.hpp" @@ -162,7 +163,7 @@ struct Game::GameImpl { std::shared_ptr human; float center_x = 0; float center_y = 0; - bool drawCollision = true; + bool drawCollision = Config::getInstance()->getInt("draw_collision"); int topx = 0.0; int topy = 0.0; int world_mouse_x = 0; //Mouse coordinates relative to the world @@ -356,7 +357,7 @@ void Game::Draw(SDL_Renderer* target) { } Projectile* projectile = dynamic_cast (p.get()); if (projectile) { - DrawProjectile(target, globalData.spriteHolder.get(), projectile, SDL_GetTicks(), data->topx, data->topy, true); + DrawProjectile(target, globalData.spriteHolder.get(), projectile, SDL_GetTicks(), data->topx, data->topy, data->drawCollision); } } for (size_t i = 0; i < data->gameRegion.world.tm.layers.size(); ++i) { @@ -571,9 +572,16 @@ void Game::Update() { } } auto& vp = data->gameRegion.placeables; - vp.erase(std::remove_if(std::begin(vp), std::end(vp), [](std::shared_ptr p) { + size_t preSize = vp.size(); + vp.erase(std::remove_if(vp.begin(), vp.end(), [](std::shared_ptr& p) { + if (p->removeMe) { + std::cout << "Found something to remove: "<< p->X << "," << p->Y << "\n" ; + } return p->removeMe; - }), std::end(vp)); + }), vp.end()); + if (vp.size() != preSize) { + std::cout << "Before: " << preSize << ", after: " << vp.size() << "\n"; + } data->center_x = std::round(data->human->X); data->center_y = std::round(data->human->Y); int mousex; diff --git a/src/saland/GameDraw.cpp b/src/saland/GameDraw.cpp index a2cad7d..35eacb5 100644 --- a/src/saland/GameDraw.cpp +++ b/src/saland/GameDraw.cpp @@ -24,6 +24,33 @@ https://github.com/sago007/saland #include "GameDraw.hpp" #include #include +#include "../sago/SagoTextField.hpp" + +struct TextCache +{ + sago::SagoTextField* getLabel(const std::string& text); +private: + std::map > labels; +}; + +sago::SagoTextField* TextCache::getLabel(const std::string& text) { + const auto& theLabel = labels.find(text); + if (theLabel != labels.end()) { + return labels[text].get(); + } + std::shared_ptr newField = std::make_shared(); + newField->SetHolder(&globalData.spriteHolder->GetDataHolder()); + newField->SetFont("freeserif"); + newField->SetFontSize(12); + newField->SetOutline(0, {255,255,0,255}); + newField->SetText(text); + labels[text] = newField; + return labels[text].get(); +} + + +TextCache textCache; + static void Draw(SDL_Renderer* target, SDL_Texture* t, int x, int y, const SDL_Rect& part) { SDL_Rect pos = {}; @@ -39,6 +66,7 @@ static void DrawCollision(SDL_Renderer* target, const Placeable* entity, int off circleRGBA(target, entity->X - offsetX, entity->Y - offsetY, entity->Radius, 255, 255, 0, 255); + textCache.getLabel(entity->id)->Draw(target, entity->X - offsetX + entity->Radius + 4, entity->Y - offsetY, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::center); } } diff --git a/src/saland/model/placeables.hpp b/src/saland/model/placeables.hpp index 8208c36..9a6bf3f 100644 --- a/src/saland/model/placeables.hpp +++ b/src/saland/model/placeables.hpp @@ -31,6 +31,7 @@ const float pixel2unit = 32.0f; class Placeable { public: + std::string id = "noid"; float health = 10.0; float X = 20.0; float Y = 20.0;