// // Created by Tom Augier on 2021-05-20. // Edited by Benjamin Henry on 2021-05-20. // #include #include #include #include #include "Component/Collision/CollisionComponent.hpp" #include #include #include "HealthSystem.hpp" #include "Component/Health/HealthComponent.hpp" #include "Component/Bonus/BonusComponent.hpp" #include "Entity/Entity.hpp" #include "Items/Bonus.hpp" namespace RAY3D = RAY::Drawables::Drawables3D; namespace BBM { HealthSystem::HealthSystem(WAL::Wal &wal) : System(wal) {} void HealthSystem::_createBonus(Vector3f position, BonusComponent::BonusType bonusType, std::chrono::nanoseconds timer) { static std::map map = { {BonusComponent::BonusType::BOMBSTOCK, "assets/items/bombup"}, {BonusComponent::BonusType::SPEEDUP, "assets/items/speedup"}, //{BonusComponent::BonusType::EXPLOSIONINC, "assets/items/explosion"}, {BonusComponent::BonusType::DAMAGEINC, "assets/items/fireup"}, {BonusComponent::BonusType::IGNOREWALLS, "assets/items/wallpass"} }; static std::vector> func = { &Bonus::BombUpBonus, &Bonus::SpeedUpBonus, //&Bonus::ExplosionRangeBonus, &Bonus::DamageIncreasedBonus, &Bonus::IgnoreWallsBonus }; if (bonusType == BonusComponent::BonusType::NOTHING) return; try { this->_wal.scene->scheduleNewEntity("Bonus") .addComponent(position) .addComponent(1, [](WAL::Entity &entity) { entity.scheduleDeletion(); }) .addComponent(position.y) .addComponent([](WAL::Entity &bonus, const WAL::Entity &player, CollisionComponent::CollidedAxis axis) { bonus.scheduleDeletion(); }, func[bonusType - 1], 0.25, .75) .addComponent(timer, [](WAL::Entity &bonus, WAL::Wal &wal){ bonus.scheduleDeletion(); }) .addComponent(map.at(bonusType) + ".obj", std::make_pair(MAP_DIFFUSE, "assets/items/items.png")); } catch (std::out_of_range const &err) {} } void HealthSystem::onFixedUpdate(WAL::ViewEntity &entity) { auto &health = entity.get(); auto &position = entity.get(); if (health.getHealthPoint() == 0) { if (entity->hasComponent() && !entity->shouldDelete()) { auto &bonus = entity->getComponent(); auto bonusType = bonus.getRandomBonusType(); this->_createBonus(position.position, bonusType, bonus.disappearTimer); } health.onDeath(entity); } } }