fixed healthsystem, using callbacks to create bonuses and removed bonuscomponent (useless)

This commit is contained in:
HENRY Benjamin
2021-06-09 14:49:37 +02:00
parent 93a4fa792c
commit 3a99e5913b
15 changed files with 88 additions and 152 deletions
+35 -3
View File
@@ -7,9 +7,12 @@
#include "System/Collision/CollisionSystem.hpp"
#include "Map.hpp"
#include <iostream>
#include <Component/Bonus/BonusComponent.hpp>
#include <Items/Bonus.hpp>
#include <Component/Levitate/LevitateComponent.hpp>
#include <Component/Timer/TimerComponent.hpp>
namespace RAY3D = RAY::Drawables::Drawables3D;
using namespace std::chrono_literals;
namespace BBM
{
@@ -29,9 +32,39 @@ namespace BBM
mov->_velocity.z = 0;
}
void MapGenerator::wallDestroyed(WAL::Entity &entity)
void MapGenerator::wallDestroyed(WAL::Entity &entity, WAL::Wal &wal)
{
entity.scheduleDeletion();
auto &position = entity.getComponent<PositionComponent>().position;
static std::map<Bonus::BonusType, std::string> map = {
{Bonus::BonusType::BOMBSTOCK, "assets/items/bombup"},
{Bonus::BonusType::SPEEDUP, "assets/items/speedup"},
//{BonusComponent::BonusType::EXPLOSIONINC, "assets/items/explosion"},
{Bonus::BonusType::DAMAGEINC, "assets/items/fireup"}
};
static std::vector<std::function<void (WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis)>> func = {
&Bonus::BombUpBonus, &Bonus::SpeedUpBonus, //&Bonus::ExplosionRangeBonus,
&Bonus::DamageIncreasedBonus
};
auto bonusType = Bonus::getRandomBonusType();
if (bonusType == Bonus::BonusType::NOTHING)
return;
if (!map.contains(bonusType))
return;
wal.scene->scheduleNewEntity("Bonus")
.addComponent<PositionComponent>(position)
.addComponent<HealthComponent>(1, [](WAL::Entity &entity, WAL::Wal &wal) {
entity.scheduleDeletion();
})
.addComponent<LevitateComponent>(position.y)
.addComponent<CollisionComponent>([](WAL::Entity &bonus, const WAL::Entity &player, CollisionComponent::CollidedAxis axis) {
bonus.scheduleDeletion();
}, func[bonusType - 1], 0.25, .75)
.addComponent<TimerComponent>(5s, [](WAL::Entity &bonus, WAL::Wal &wal){
bonus.scheduleDeletion();
})
.addComponent<Drawable3DComponent, RAY3D::Model>(map.at(bonusType) + ".obj", std::make_pair(MAP_DIFFUSE, "assets/items/items.png"));
}
const std::string MapGenerator::assetsPath = "./assets/";
@@ -150,7 +183,6 @@ namespace BBM
scene->addEntity("Breakable Block")
.addComponent<PositionComponent>(coords)
.addComponent<HealthComponent>(1, &MapGenerator::wallDestroyed)
.addComponent<BonusComponent>()
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
&MapGenerator::wallCollide, 0.25, .75)