feat(mummy): evita tiles amb decal trigger (Hole) en decidir direcció
This commit is contained in:
1 parent
3e5217066f
commit
3bfca35f3a
5 files changed
+111
-27
No files matched your search
@@ -72,6 +72,7 @@ void EntityManager::forceOpenDoor() {
|
||||
auto EntityManager::add(std::unique_ptr<Entity> entity) -> Entity* {
|
||||
if (entity == nullptr) { return nullptr; }
|
||||
entity->setEventBus(&bus_);
|
||||
entity->setEntityManager(this);
|
||||
Entity* raw = entity.get();
|
||||
entities_.push_back(std::move(entity));
|
||||
// cppcheck-suppress returnDanglingLifetime
|
||||
@@ -80,12 +81,16 @@ auto EntityManager::add(std::unique_ptr<Entity> entity) -> Entity* {
|
||||
|
||||
void EntityManager::setDoor(Door* door) {
|
||||
door_ = door;
|
||||
if (door_ != nullptr) { door_->setEventBus(&bus_); }
|
||||
if (door_ != nullptr) {
|
||||
door_->setEventBus(&bus_);
|
||||
door_->setEntityManager(this);
|
||||
}
|
||||
}
|
||||
|
||||
auto EntityManager::addSarcophagus(std::unique_ptr<Sarcophagus> sarc) -> Sarcophagus* {
|
||||
if (sarc == nullptr) { return nullptr; }
|
||||
sarc->setEventBus(&bus_);
|
||||
sarc->setEntityManager(this);
|
||||
Sarcophagus* raw = sarc.get();
|
||||
entities_.push_back(std::move(sarc));
|
||||
++total_sarcs_;
|
||||
@@ -110,6 +115,24 @@ void EntityManager::notifyPlayerTilePainted(int col, int row) {
|
||||
for (auto& e : entities_) { e->notifyTilePainted(col, row); }
|
||||
}
|
||||
|
||||
auto EntityManager::findFloorTriggerAt(const SDL_FRect& rect) const -> const Entity* {
|
||||
// Cerca lineal sobre `entities_`: cost menyspreable amb poques
|
||||
// desenes d'entitats per sala i una crida per frame des dels
|
||||
// consumidors actius (Player a l'aterratge, Mòmia a la decisió de
|
||||
// direcció). Si esdevé calent, es podria indexar per cel·la del
|
||||
// tilemap. La doble condició filtra exclusivament decals de sòl que
|
||||
// volen rebre triggers — avui Hole; en el futur pinchos plans,
|
||||
// plaques de pressió, charcos.
|
||||
for (const auto& entity : entities_) {
|
||||
if (!entity->triggersOnOverlap()) { continue; }
|
||||
if (!entity->isFloorDecal()) { continue; }
|
||||
const auto BOX = entity->getCollisionRect();
|
||||
const bool OVERLAP = rect.x + rect.w > BOX.x && BOX.x + BOX.w > rect.x && rect.y + rect.h > BOX.y && BOX.y + BOX.h > rect.y;
|
||||
if (OVERLAP) { return entity.get(); }
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto EntityManager::getEntities() const -> std::vector<Entity*> {
|
||||
std::vector<Entity*> out;
|
||||
out.reserve(entities_.size());
|
||||
|
||||
Reference in new issue
Block a user