diff --git a/include/AssetManager.h b/include/AssetManager.h index 4d6931e..4992dd2 100644 --- a/include/AssetManager.h +++ b/include/AssetManager.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "Entity.h" @@ -24,7 +25,7 @@ public: ~AssetManager(); void createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, const char* texturePath, Entity::TeamLabel teamLabel); - void createPowerup(Vector2D pos, PowerupType type); + void createPowerup(Vector2D pos, std::function pickupFunc, std::string texturePath); Vector2D calculateSpawnPosition(); PowerupType calculateType(); diff --git a/include/PowerupComponent.h b/include/PowerupComponent.h index f83ea29..53f365b 100644 --- a/include/PowerupComponent.h +++ b/include/PowerupComponent.h @@ -1,19 +1,16 @@ #pragma once +#include #include "Component.h" -#include "AssetManager.h" class PowerupComponent : public Component { public: - PowerupComponent(PowerupType type); + PowerupComponent(std::function func); ~PowerupComponent() {}; void update() override; - void heartEffect(Entity* player); - void movementSpeedEffect(Entity* player); - void atkSpeedEffect(Entity* player); private: - void (PowerupComponent::*pickupFunc)(Entity* player); + std::function pickupFunc; }; \ No newline at end of file diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp index a73d585..f759b19 100644 --- a/src/AssetManager.cpp +++ b/src/AssetManager.cpp @@ -48,25 +48,21 @@ void AssetManager::createProjectile(Vector2D pos, Vector2D velocity, int scale, projectile.setTeam(teamLabel); } -void AssetManager::createPowerup(Vector2D pos, PowerupType type) { +void AssetManager::createPowerup(Vector2D pos, std::function pickupFunc, std::string texturePath) { TextureDict textureDict; auto& powerups(man->addEntity()); powerups.addComponent(pos.x, pos.y, 32, 32, 1); //32x32 is standard size for objects - auto it = textureDict.powerupDictionary.find(type); - if (it == textureDict.powerupDictionary.end()) { - std::cout << "it end" << std::endl; - } try { - powerups.addComponent(it->second.data()); + powerups.addComponent(texturePath.c_str()); } catch (std::runtime_error e) { std::cout << e.what() << std::endl; } powerups.addComponent("powerup", 0.6f); - powerups.addComponent(type); + powerups.addComponent(pickupFunc); powerups.addGroup((size_t)Entity::GroupLabel::POWERUPS); } diff --git a/src/PowerupComponent.cpp b/src/PowerupComponent.cpp index bc52917..48de1be 100644 --- a/src/PowerupComponent.cpp +++ b/src/PowerupComponent.cpp @@ -7,22 +7,9 @@ #include "Constants.h" #include -PowerupComponent::PowerupComponent(PowerupType type) +PowerupComponent::PowerupComponent(std::function func) { - switch (type) - { - case PowerupType::HEART: - this->pickupFunc = (&PowerupComponent::heartEffect); - break; - case PowerupType::WALKINGSPEED: - this->pickupFunc = (&PowerupComponent::movementSpeedEffect); - break; - case PowerupType::SHOOTINGSPEED: - this->pickupFunc = (&PowerupComponent::atkSpeedEffect); - break; - default: - break; - } + this->pickupFunc = func; } void PowerupComponent::update() @@ -35,23 +22,7 @@ void PowerupComponent::update() {}, true)) != nullptr) { - (this->*pickupFunc)(player); + (this->pickupFunc)(player); this->entity->destroy(); } -} - -void PowerupComponent::heartEffect(Entity* player) -{ - if(player->getComponent().getHealth() < 5) - player->getComponent().modifyHealth(1); -} - -void PowerupComponent::movementSpeedEffect(Entity* player) -{ - player->getComponent().modifyStatDur(Stats::MOVEMENT_SPEED, BUFF_DURATION); -} - -void PowerupComponent::atkSpeedEffect(Entity* player) -{ - player->getComponent().modifyStatDur(Stats::ATTACK_SPEED, BUFF_DURATION); } \ No newline at end of file