bonus has been done, just need to remove comments when bombholder will be push + decide the time before they got remove

This commit is contained in:
EternalRat
2021-06-02 16:13:18 +02:00
parent 1cb90f9ac3
commit 8b7a24ff1f
7 changed files with 186 additions and 5 deletions
+6
View File
@@ -16,6 +16,10 @@ set(SOURCES
sources/Runner/Runner.hpp
sources/Map/Map.cpp
sources/Map/Map.hpp
sources/Bonus/Bonus.cpp
sources/Bonus/Bonus.hpp
sources/Component/Bonus/BonusComponent.cpp
sources/Component/Bonus/BonusComponent.hpp
sources/Component/Position/PositionComponent.cpp
sources/Component/Position/PositionComponent.hpp
sources/Component/Movable/MovableComponent.cpp
@@ -28,6 +32,8 @@ set(SOURCES
sources/Component/Keyboard/KeyboardComponent.hpp
sources/Component/Health/HealthComponent.cpp
sources/Component/Health/HealthComponent.hpp
sources/Component/Bonus/BonusComponent.cpp
sources/Component/Bonus/BonusComponent.hpp
sources/System/Movable/MovableSystem.hpp
sources/System/Movable/MovableSystem.cpp
sources/System/Controllable/ControllableSystem.cpp
+38
View File
@@ -0,0 +1,38 @@
//
// Created by HENRY Benjamin on 02/06/2021.
//
#include "Bonus.hpp"
//#include "Component/BombHolderComponent/BombHolderComponent.hpp"
namespace BBM {
void Bonus::BombUpBonus(const WAL::Entity &entity, const WAL::Entity &other)
{
auto &bombHolder = other.getComponent<BombHolderComponent>();
bombHolder.maxBombCount++;
}
void Bonus::DamageIncreasedBonus(const WAL::Entity &entity, const WAL::Entity &other)
{
auto &bombHolder = other.getComponent<BombHolderComponent>();
//bombHolder.damage++;
}
void Bonus::ExplosionRangeBonus(const WAL::Entity &entity, const WAL::Entity &other)
{
auto &bombHolder = other.getComponent<BombHolderComponent>();
//bombHolder.explosionRange++;
}
void Bonus::SpeedUpBonus(const WAL::Entity &entity, const WAL::Entity &other)
{
auto &movable = other.getComponent<MovableComponent>();
movable.addForce(Vector3f(1, 0, 1));
}
void Bonus::IgnoreWallsBonus(const WAL::Entity &entity, const WAL::Entity &other)
{
auto &bombHolder = other.getComponent<BombHolderComponent>();
//bombHolder.ignoreWall = false;
}
}
+18
View File
@@ -0,0 +1,18 @@
//
// Created by HENRY Benjamin on 02/06/2021.
//
#pragma once
#include "Entity/Entity.hpp"
namespace BBM {
class Bonus {
public:
static void BombUpBonus(const WAL::Entity &entity, const WAL::Entity &other);
static void DamageIncreasedBonus(const WAL::Entity &entity, const WAL::Entity &other);
static void ExplosionRangeBonus(const WAL::Entity &entity, const WAL::Entity &other);
static void SpeedUpBonus(const WAL::Entity &entity, const WAL::Entity &other);
static void IgnoreWallsBonus(const WAL::Entity &entity, const WAL::Entity &other);
};
}
@@ -0,0 +1,21 @@
//
// Created by Benjamin Henry on 2021-06-01.
//
#include "BonusComponent.hpp"
namespace BBM {
BonusComponent::BonusComponent(WAL::Entity &entity)
: WAL::Component(entity)
{}
WAL::Component *BonusComponent::clone(WAL::Entity &entity) const
{
return new BonusComponent(entity);
}
BonusComponent::BonusType BonusComponent::getRandomBonusType() const
{
return (static_cast<BonusType>(std::rand() % IGNOREWALLS));
}
}
@@ -0,0 +1,47 @@
//
// Created by Benjamin Henry on 2021-06-01.
//
#pragma once
#include "Component/Component.hpp"
#include "Entity/Entity.hpp"
#include <chrono>
using namespace std::chrono_literals;
namespace BBM
{
class BonusComponent : public WAL::Component
{
public:
enum BonusType {
NOTHING,
BOMBSTOCK,
SPEEDUP,
EXPLOSIONINC,
DAMAGEINC,
IGNOREWALLS
};
std::chrono::nanoseconds disappearTimer = 10s;
BonusType getRandomBonusType() const;
//! @inherit
WAL::Component *clone(WAL::Entity &entity) const override;
//! @brief A Bonus component can't be instantiated, it should be derived.
explicit BonusComponent(WAL::Entity &entity);
//! @brief A Bonus component can't be instantiated, it should be derived.
BonusComponent(const BonusComponent &) = default;
//! @brief default destructor
~BonusComponent() override = default;
//! @brief A Bonus component can't be assigned
BonusComponent &operator=(const BonusComponent &) = delete;
};
}
+46 -4
View File
@@ -3,24 +3,66 @@
// Edited by Benjamin Henry on 2021-05-20.
//
#include <Component/Position/PositionComponent.hpp>
#include <Component/Renderer/Drawable3DComponent.hpp>
#include <map>
#include "HealthSystem.hpp"
#include "Component/Health/HealthComponent.hpp"
#include "Component/Controllable/ControllableComponent.hpp"
#include "Component/Bonus/BonusComponent.hpp"
#include "Entity/Entity.hpp"
#include "Bonus/Bonus.hpp"
namespace RAY3D = RAY::Drawables::Drawables3D;
namespace BBM
{
HealthSystem::HealthSystem()
HealthSystem::HealthSystem(WAL::Wal &wal)
: WAL::System({
typeid(HealthComponent)
})
}),
_wal(wal)
{}
void HealthSystem::_createBonus(Vector3f position, BonusComponent::BonusType bonusType, std::chrono::nanoseconds timer)
{
std::map<BonusComponent::BonusType, std::string> 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"}
};
std::vector<std::function<void (const WAL::Entity &, const WAL::Entity &)>> func = {
&Bonus::BombUpBonus, &Bonus::SpeedUpBonus, &Bonus::ExplosionRangeBonus,
&Bonus::DamageIncreasedBonus, &Bonus::IgnoreWallsBonus
};
if (bonusType == BonusComponent::BonusType::NOTHING)
return;
std::cout << "Bonus spawned" << std::endl;
this->_wal.scene->addEntity("Bonus")
.addComponent<PositionComponent>(position)
.addComponent<HealthComponent>(1)
//.addComponent<CollisionComponent>(1, func[bonusType -1])
//.addComponent<TimerComponent>(timer, &[](WAL::Entity &bonus){
// std::cout << "Bonus disappeared" << std::endl;
// bonus.scheduleDeletion();
// })
.addComponent<Drawable3DComponent<RAY3D::Model>>(map.at(bonusType) + ".obj", std::make_pair(MAP_DIFFUSE, "assets/items/items.png"));
}
void HealthSystem::onFixedUpdate(WAL::Entity &entity)
{
auto &health = entity.getComponent<HealthComponent>();
auto &position = entity.getComponent<PositionComponent>();
if (health.getHealthPoint() == 0)
if (health.getHealthPoint() == 0) {
if (entity.hasComponent<BonusComponent>()) {
auto &bonus = entity.getComponent<BonusComponent>();
auto bonusType = bonus.getRandomBonusType();
this->_createBonus(position.position, bonusType, bonus.disappearTimer);
}
health.onDeath(entity);
}
}
}
+10 -1
View File
@@ -5,6 +5,9 @@
#pragma once
#include <Component/Bonus/BonusComponent.hpp>
#include "Models/Vector3.hpp"
#include "Wal.hpp"
#include "System/System.hpp"
namespace BBM
@@ -12,12 +15,18 @@ namespace BBM
//! @brief A system to handle Health entities.
class HealthSystem : public WAL::System
{
private:
//! @brief A reference to the engine to spawn new entities.
WAL::Wal &_wal;
//! @brief Spawn a bonus at the specified position.
void _createBonus(Vector3f position, BonusComponent::BonusType bonusType, std::chrono::nanoseconds timer);
public:
//! @inherit
void onFixedUpdate(WAL::Entity &entity) override;
//! @brief A default constructor
HealthSystem();
HealthSystem(WAL::Wal &wal);
//! @brief A Health system is copy constructable
HealthSystem(const HealthSystem &) = default;
//! @brief A default destructor