#include "PickupManager.h" #include "TextureManager.h" #include "SoundManager.h" #include "ProjectileComponent.h" #include "GameInternal.h" #include "TransformComponent.h" #include "CollisionHandler.h" #include "ColliderComponent.h" #include "Constants.h" #include "Entity.h" #include "Vector2D.h" #include "PickupComponent.h" #include #include #include "Textures.h" PickupManager::PickupManager(Manager* manager) : man(manager) {} PickupManager::~PickupManager() {} void PickupManager::createPowerup(Vector2D pos, std::function pickupFunc, Textures texture) { auto& powerups(man->addEntity()); powerups.addComponent(pos.x, pos.y, 32, 32, 1); //32x32 is standard size for objects try { powerups.addComponent(texture, 3); } catch (std::runtime_error e) { std::cout << e.what() << std::endl; } powerups.addComponent("powerup", 0.6f); powerups.addComponent(pickupFunc); powerups.addGroup((size_t)Entity::GroupLabel::POWERUPS); } Vector2D PickupManager::calculateSpawnPosition() { Vector2D spawnPos = Vector2D(-1, -1); bool conflict = false; for (int i = 0; i <= SPAWN_ATTEMPTS; i++) { SDL_Rect spawnRect; spawnRect.h = spawnRect.w = 32; spawnRect.x = rand() % (VEGO_Game().config->getFinalConfig().at("screen_width").get() - spawnRect.w); spawnRect.y = rand() % (VEGO_Game().config->getFinalConfig().at("screen_height").get() - spawnRect.h); conflict = false; for (auto cc : this->man->getGame()->collisionHandler->getColliders({ Entity::GroupLabel::MAPTILES })) { if (SDL_HasRectIntersection(&spawnRect, &cc->collider) && strcmp(cc->tag, "projectile")) { conflict = true; break; } } if (conflict) continue; spawnPos = Vector2D(spawnRect.x, spawnRect.y); } return spawnPos; }