From 3009e34ac3768df0509191bcb63e16e4b0441096 Mon Sep 17 00:00:00 2001 From: EternalRat <44569175+EternalRat@users.noreply.github.com> Date: Tue, 8 Jun 2021 20:12:09 +0200 Subject: [PATCH] increased range + damage bonus added, just miss ignorewalls now & sprite for the explosionrange bonus --- CMakeLists.txt | 2 + sources/Component/Bomb/BasicBombComponent.cpp | 19 ++++++++++ sources/Component/Bomb/BasicBombComponent.hpp | 38 +++++++++++++++++++ .../BombHolder/BombHolderComponent.hpp | 4 ++ sources/Items/Bonus.cpp | 6 +-- .../System/BombHolder/BombHolderSystem.cpp | 16 +++++--- .../System/BombHolder/BombHolderSystem.hpp | 4 +- 7 files changed, 76 insertions(+), 13 deletions(-) create mode 100644 sources/Component/Bomb/BasicBombComponent.cpp create mode 100644 sources/Component/Bomb/BasicBombComponent.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 09365555..4475da2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,6 +91,8 @@ set(SOURCES sources/Component/Animator/AnimatorComponent.hpp sources/System/Animator/AnimatorSystem.cpp sources/System/Animator/AnimatorSystem.hpp + sources/Component/Bomb/BasicBombComponent.cpp + sources/Component/Bomb/BasicBombComponent.hpp ) add_executable(bomberman sources/main.cpp diff --git a/sources/Component/Bomb/BasicBombComponent.cpp b/sources/Component/Bomb/BasicBombComponent.cpp new file mode 100644 index 00000000..4c6f74af --- /dev/null +++ b/sources/Component/Bomb/BasicBombComponent.cpp @@ -0,0 +1,19 @@ +// +// Created by Utilisateur on 08/06/2021. +// + +#include "BasicBombComponent.hpp" + +namespace BBM +{ + BasicBombComponent::BasicBombComponent(WAL::Entity &entity, int damage, float explosionRadius) + : WAL::Component(entity), + damage(damage), + explosionRadius(explosionRadius) + {} + + WAL::Component *BasicBombComponent::clone(WAL::Entity &entity) const + { + return new BasicBombComponent(entity, this->damage, this->explosionRadius); + } +} \ No newline at end of file diff --git a/sources/Component/Bomb/BasicBombComponent.hpp b/sources/Component/Bomb/BasicBombComponent.hpp new file mode 100644 index 00000000..f9225a54 --- /dev/null +++ b/sources/Component/Bomb/BasicBombComponent.hpp @@ -0,0 +1,38 @@ +// +// Created by Utilisateur on 08/06/2021. +// + +#pragma once + +#include "Component/Component.hpp" +#include "Entity/Entity.hpp" +#include + +using namespace std::chrono_literals; + +namespace BBM +{ + class BasicBombComponent : public WAL::Component + { + public: + //! @brief The radius of the explosion. + const float explosionRadius = 3; + //! @brief The damage made by the explosion on an entity + const int damage = 1; + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief A component can't be instantiated, it should be derived. + explicit BasicBombComponent(WAL::Entity &entity, int damage, float explosionRadius); + + //! @brief A component can't be instantiated, it should be derived. + BasicBombComponent(const BasicBombComponent &) = default; + + //! @brief default destructor + ~BasicBombComponent() override = default; + + //! @brief A component can't be assigned + BasicBombComponent &operator=(const BasicBombComponent &) = delete; + }; +} \ No newline at end of file diff --git a/sources/Component/BombHolder/BombHolderComponent.hpp b/sources/Component/BombHolder/BombHolderComponent.hpp index 03906e84..75a0f0f9 100644 --- a/sources/Component/BombHolder/BombHolderComponent.hpp +++ b/sources/Component/BombHolder/BombHolderComponent.hpp @@ -25,6 +25,10 @@ namespace BBM std::chrono::nanoseconds refillRate = 5000ms; //! @brief The number of nanosecond before the next bomb refill. std::chrono::nanoseconds nextBombRefill = refillRate; + //! @brief The radius of the explosion. + float explosionRadius = 3; + //! @brief The damage made by the explosion on an entity + int damage = 1; //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; diff --git a/sources/Items/Bonus.cpp b/sources/Items/Bonus.cpp index 9da6e4c1..dd6337c0 100644 --- a/sources/Items/Bonus.cpp +++ b/sources/Items/Bonus.cpp @@ -20,8 +20,7 @@ namespace BBM { { if (player.hasComponent()) { auto &bombHolder = player.getComponent(); - std::cout << "Explosion is supposed to deal 1 more damage here" << std::endl; - //bombHolder.damage++; + bombHolder.damage++; } } @@ -29,8 +28,7 @@ namespace BBM { { if (player.hasComponent()) { auto &bombHolder = player.getComponent(); - std::cout << "Explosion is supposed to be 1 range higher here" << std::endl; - //bombHolder.explosionRange++; + bombHolder.explosionRadius++; } } diff --git a/sources/System/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index 2d46b3b8..7ca6ed67 100644 --- a/sources/System/BombHolder/BombHolderSystem.cpp +++ b/sources/System/BombHolder/BombHolderSystem.cpp @@ -2,6 +2,7 @@ // Created by Zoe Roux on 5/31/21. // +#include #include "Component/Timer/TimerComponent.hpp" #include "System/Event/EventSystem.hpp" #include "Component/Renderer/Drawable3DComponent.hpp" @@ -14,7 +15,6 @@ namespace RAY3D = RAY::Drawables::Drawables3D; namespace BBM { std::chrono::nanoseconds BombHolderSystem::explosionTimer = 3s; - float BombHolderSystem::explosionRadius = 3; BombHolderSystem::BombHolderSystem(WAL::Wal &wal) : System(wal) @@ -24,26 +24,30 @@ namespace BBM { bomb.scheduleDeletion(); auto &bombPosition = bomb.getComponent(); - wal.getSystem().dispatchEvent([&bombPosition](WAL::Entity &entity){ + auto &basicBomb = bomb.getComponent(); + wal.getSystem().dispatchEvent([&bombPosition, &basicBomb](WAL::Entity &entity){ auto *health = entity.tryGetComponent(); auto *pos = entity.tryGetComponent(); if (!health || !pos) return; - if (pos->position.distance(bombPosition.position) > BombHolderSystem::explosionRadius) + if (pos->position.distance(bombPosition.position) > basicBomb.explosionRadius) return; // TODO do a raycast here to only remove health to entities that are not behind others. - health->takeDmg(1); + health->takeDmg(basicBomb.damage); }); } - void BombHolderSystem::_spawnBomb(Vector3f position) + void BombHolderSystem::_spawnBomb(Vector3f position, BombHolderComponent &holder) { this->_wal.scene->scheduleNewEntity("Bomb") .addComponent(position) + .addComponent(holder.damage, holder.explosionRadius) .addComponent(BombHolderSystem::explosionTimer, &BombHolderSystem::_bombExplosion) .addComponent("assets/bombs/bomb.obj", std::make_pair(MAP_DIFFUSE, "assets/bombs/bomb_normal.png")); + holder.damage = 1; + holder.explosionRadius = 3; } void BombHolderSystem::onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) @@ -54,7 +58,7 @@ namespace BBM if (controllable.bomb && holder.bombCount > 0) { holder.bombCount--; - this->_spawnBomb(position.position); + this->_spawnBomb(position.position, holder); } if (holder.bombCount < holder.maxBombCount) { holder.nextBombRefill -= dtime; diff --git a/sources/System/BombHolder/BombHolderSystem.hpp b/sources/System/BombHolder/BombHolderSystem.hpp index fd3d4e78..d21cffdb 100644 --- a/sources/System/BombHolder/BombHolderSystem.hpp +++ b/sources/System/BombHolder/BombHolderSystem.hpp @@ -18,15 +18,13 @@ namespace BBM { private: //! @brief Spawn a bomb at the specified position. - void _spawnBomb(Vector3f position); + void _spawnBomb(Vector3f position, BombHolderComponent &holder); //! @brief The method triggered when the bomb explode. static void _bombExplosion(WAL::Entity &bomb, WAL::Wal &); public: //! @brief The explosion time of new bombs. static std::chrono::nanoseconds explosionTimer; - //! @brief The radius of the explosion. - static float explosionRadius; //! @inherit void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) override;