mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-25 07:34:01 +00:00
PlayerBonus system & component made (containing timer)
This commit is contained in:
@@ -93,6 +93,10 @@ set(SOURCES
|
||||
sources/System/Animator/AnimatorSystem.hpp
|
||||
sources/Component/Bomb/BasicBombComponent.cpp
|
||||
sources/Component/Bomb/BasicBombComponent.hpp
|
||||
sources/Component/Bonus/PlayerBonusComponent.hpp
|
||||
sources/Component/Bonus/PlayerBonusComponent.cpp
|
||||
sources/System/Bonus/PlayerBonusSystem.hpp
|
||||
sources/System/Bonus/PlayerBonusSystem.cpp
|
||||
)
|
||||
add_executable(bomberman
|
||||
sources/main.cpp
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// Created by hbenjamin on 09/06/2021.
|
||||
//
|
||||
|
||||
#include "PlayerBonusComponent.hpp"
|
||||
|
||||
namespace BBM {
|
||||
PlayerBonusComponent::PlayerBonusComponent(WAL::Entity &entity)
|
||||
: WAL::Component(entity)
|
||||
{}
|
||||
|
||||
WAL::Component *PlayerBonusComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new PlayerBonusComponent(entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// Created by hbenjamin on 09/06/2021.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Component/Component.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
#include <chrono>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class PlayerBonusComponent : public WAL::Component
|
||||
{
|
||||
public:
|
||||
|
||||
//! @brief The number of seconds before a speed bonus expire. This variable is used to reset the nextSpeedBonusRate value.
|
||||
std::chrono::nanoseconds speedBonusRate = 15s;
|
||||
//! @brief The number of nanosecond before the expiration of a speed bonus.
|
||||
std::chrono::nanoseconds nextSpeedBonusRate = speedBonusRate;
|
||||
//! @brief The number of seconds before a damage bonus expire. This variable is used to reset the nextDamageBonusRate value.
|
||||
std::chrono::nanoseconds damageBonusRate = 20s;
|
||||
//! @brief The number of nanosecond before the expiration of a damage bonus.
|
||||
std::chrono::nanoseconds nextDamageBonusRate = damageBonusRate;
|
||||
//! @brief The number of seconds before a range bonus expire. This variable is used to reset the nextRangeBonusRate value.
|
||||
std::chrono::nanoseconds rangeBonusRate = 10s;
|
||||
//! @brief The number of nanosecond before the expiration of a range bonus.
|
||||
std::chrono::nanoseconds nextRangeBonusRate = rangeBonusRate;
|
||||
//! @brief The number of seconds before a ignoreWalls expire. This variable is used to reset the nextSpeedBonusRate value.
|
||||
std::chrono::nanoseconds ignoreWallsBonusRate = 15s;
|
||||
//! @brief The number of nanosecond before the expiration of a ignoreWalls bonus.
|
||||
std::chrono::nanoseconds nextIgnoreWallsBonusRate = ignoreWallsBonusRate;
|
||||
|
||||
//! @inherit
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
//! @brief A Bonus component can't be instantiated, it should be derived.
|
||||
explicit PlayerBonusComponent(WAL::Entity &entity);
|
||||
|
||||
//! @brief A Bonus component can't be instantiated, it should be derived.
|
||||
PlayerBonusComponent(const PlayerBonusComponent &) = default;
|
||||
|
||||
//! @brief default destructor
|
||||
~PlayerBonusComponent() override = default;
|
||||
|
||||
//! @brief A Bonus component can't be assigned
|
||||
PlayerBonusComponent &operator=(const PlayerBonusComponent &) = delete;
|
||||
};
|
||||
}
|
||||
@@ -27,10 +27,6 @@ namespace BBM
|
||||
bool pause = false;
|
||||
//! @brief The speed applied to every controllable entities.
|
||||
float speed = .25f;
|
||||
//! @brief The number of seconds before a speedbonus expire. This variable is used to reset the nextSpeedBonusRate value.
|
||||
std::chrono::nanoseconds speedBonusRate = 15000ms;
|
||||
//! @brief The number of nanosecond before the expiration of a speed bonus.
|
||||
std::chrono::nanoseconds nextSpeedBonusRate = speedBonusRate;
|
||||
|
||||
//! @inherit
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
+12
-3
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <Component/Collision/CollisionComponent.hpp>
|
||||
#include <Component/Controllable/ControllableComponent.hpp>
|
||||
#include <Component/Bonus/PlayerBonusComponent.hpp>
|
||||
#include "Component/Movable/MovableComponent.hpp"
|
||||
#include "Bonus.hpp"
|
||||
#include "Component/BombHolder/BombHolderComponent.hpp"
|
||||
@@ -25,7 +26,9 @@ namespace BBM {
|
||||
return;
|
||||
if (player.hasComponent<BombHolderComponent>()) {
|
||||
auto &bombHolder = player.getComponent<BombHolderComponent>();
|
||||
bombHolder.damage++;
|
||||
auto &playerBonus = player.getComponent<PlayerBonusComponent>();
|
||||
bombHolder.damage = 2;
|
||||
playerBonus.nextDamageBonusRate = playerBonus.damageBonusRate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +38,10 @@ namespace BBM {
|
||||
return;
|
||||
if (player.hasComponent<BombHolderComponent>()) {
|
||||
auto &bombHolder = player.getComponent<BombHolderComponent>();
|
||||
bombHolder.explosionRadius++;
|
||||
auto &playerBonus = player.getComponent<PlayerBonusComponent>();
|
||||
if (bombHolder.explosionRadius <= 6)
|
||||
bombHolder.explosionRadius++;
|
||||
playerBonus.nextRangeBonusRate = playerBonus.rangeBonusRate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,8 +52,9 @@ namespace BBM {
|
||||
if (!player.hasComponent<MovableComponent>())
|
||||
return;
|
||||
auto &controllable = player.getComponent<ControllableComponent>();
|
||||
auto &playerBonus = player.getComponent<PlayerBonusComponent>();
|
||||
controllable.speed = 0.35f;
|
||||
controllable.nextSpeedBonusRate = controllable.speedBonusRate;
|
||||
playerBonus.nextSpeedBonusRate = playerBonus.speedBonusRate;
|
||||
}
|
||||
|
||||
void Bonus::IgnoreWallsBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis)
|
||||
@@ -55,7 +62,9 @@ namespace BBM {
|
||||
if (bonus.shouldDelete())
|
||||
return;
|
||||
if (player.hasComponent<BombHolderComponent>()) {
|
||||
auto &playerBonus = player.getComponent<PlayerBonusComponent>();
|
||||
auto &bombHolder = player.getComponent<BombHolderComponent>();
|
||||
playerBonus.nextIgnoreWallsBonusRate = playerBonus.ignoreWallsBonusRate;
|
||||
std::cout << "Explosion is supposed to pass through walls here" << std::endl;
|
||||
//bombHolder.ignoreWalls = true;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include <System/Animator/AnimatorSystem.hpp>
|
||||
#include <Component/Animator/AnimatorComponent.hpp>
|
||||
#include <System/Levitate/LevitateSystem.hpp>
|
||||
#include <System/Bonus/PlayerBonusSystem.hpp>
|
||||
#include <Component/Bonus/PlayerBonusComponent.hpp>
|
||||
#include "Component/Animation/AnimationsComponent.hpp"
|
||||
#include "System/Animation/AnimationsSystem.hpp"
|
||||
#include "Map/Map.hpp"
|
||||
@@ -58,6 +60,7 @@ namespace BBM
|
||||
.addSystem<HealthSystem>()
|
||||
.addSystem<CollisionSystem>()
|
||||
.addSystem<LevitateSystem>()
|
||||
.addSystem<PlayerBonusSystem>()
|
||||
.addSystem<MovableSystem>();
|
||||
}
|
||||
|
||||
@@ -83,6 +86,7 @@ namespace BBM
|
||||
.addComponent<CollisionComponent>(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75})
|
||||
.addComponent<MovableComponent>()
|
||||
.addComponent<BombHolderComponent>()
|
||||
.addComponent<PlayerBonusComponent>()
|
||||
.addComponent<HealthComponent>(1, [](WAL::Entity &entity) {
|
||||
auto &animation = entity.getComponent<AnimationsComponent>();
|
||||
animation.setAnimIndex(5);
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// Created by hbenjamin on 09/06/2021.
|
||||
//
|
||||
|
||||
#include "PlayerBonusSystem.hpp"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
PlayerBonusSystem::PlayerBonusSystem(WAL::Wal &wal)
|
||||
: System(wal)
|
||||
{}
|
||||
|
||||
void PlayerBonusSystem::onUpdate(WAL::ViewEntity<PlayerBonusComponent, ControllableComponent, BombHolderComponent> &entity, std::chrono::nanoseconds dtime)
|
||||
{
|
||||
auto &controllable = entity.get<ControllableComponent>();
|
||||
auto &holder = entity.get<BombHolderComponent>();
|
||||
auto &playerBonus = entity.get<PlayerBonusComponent>();
|
||||
|
||||
playerBonus.nextSpeedBonusRate -= dtime;
|
||||
if (playerBonus.nextSpeedBonusRate <= 0ns) {
|
||||
playerBonus.nextSpeedBonusRate = playerBonus.speedBonusRate;
|
||||
controllable.speed = 0.25f;
|
||||
}
|
||||
playerBonus.nextIgnoreWallsBonusRate -= dtime;
|
||||
if (playerBonus.nextIgnoreWallsBonusRate <= 0ns) {
|
||||
playerBonus.nextIgnoreWallsBonusRate = playerBonus.ignoreWallsBonusRate;
|
||||
//holder.ignoreWalls = false;
|
||||
}
|
||||
playerBonus.nextDamageBonusRate -= dtime;
|
||||
if (playerBonus.nextDamageBonusRate <= 0ns) {
|
||||
playerBonus.nextDamageBonusRate = playerBonus.damageBonusRate;
|
||||
holder.damage = 1;
|
||||
}
|
||||
playerBonus.nextRangeBonusRate -= dtime;
|
||||
if (playerBonus.nextRangeBonusRate <= 0ns) {
|
||||
playerBonus.nextRangeBonusRate = playerBonus.rangeBonusRate;
|
||||
holder.explosionRadius = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// Created by hbenjamin on 09/06/2021.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <System/System.hpp>
|
||||
#include <Wal.hpp>
|
||||
#include "Models/Vector3.hpp"
|
||||
#include "Component/Bonus/PlayerBonusComponent.hpp"
|
||||
#include "Component/Controllable/ControllableComponent.hpp"
|
||||
#include "Component/BombHolder/BombHolderComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
//! @brief The system that allow one to place bombs.
|
||||
class PlayerBonusSystem : public WAL::System<PlayerBonusComponent, ControllableComponent, BombHolderComponent>
|
||||
{
|
||||
private:
|
||||
public:
|
||||
//! @inherit
|
||||
void onUpdate(WAL::ViewEntity<PlayerBonusComponent, ControllableComponent, BombHolderComponent> &entity, std::chrono::nanoseconds dtime) override;
|
||||
|
||||
//! @brief A default constructor
|
||||
explicit PlayerBonusSystem(WAL::Wal &wal);
|
||||
//! @brief A bomb holder system is copy constructable
|
||||
PlayerBonusSystem(const PlayerBonusSystem &) = default;
|
||||
//! @brief A default destructor
|
||||
~PlayerBonusSystem() override = default;
|
||||
//! @brief A bomb holder system is not assignable.
|
||||
PlayerBonusSystem &operator=(const PlayerBonusSystem &) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -21,12 +21,5 @@ namespace BBM
|
||||
Vector2f move = controllable.move.normalized() * controllable.speed;
|
||||
|
||||
movable.addForce(Vector3f(move.x, controllable.jump, move.y));
|
||||
if (controllable.speed == 0.25f)
|
||||
return;
|
||||
controllable.nextSpeedBonusRate -= dtime;
|
||||
if (controllable.nextSpeedBonusRate <= 0ns) {
|
||||
controllable.nextSpeedBonusRate = controllable.speedBonusRate;
|
||||
controllable.speed = 0.25f;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user