mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-28 16:43:29 +00:00
increased range + damage bonus added, just miss ignorewalls now & sprite for the explosionrange bonus
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// Created by Utilisateur on 08/06/2021.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Component/Component.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
#include <chrono>
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -20,8 +20,7 @@ namespace BBM {
|
||||
{
|
||||
if (player.hasComponent<BombHolderComponent>()) {
|
||||
auto &bombHolder = player.getComponent<BombHolderComponent>();
|
||||
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<BombHolderComponent>()) {
|
||||
auto &bombHolder = player.getComponent<BombHolderComponent>();
|
||||
std::cout << "Explosion is supposed to be 1 range higher here" << std::endl;
|
||||
//bombHolder.explosionRange++;
|
||||
bombHolder.explosionRadius++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Created by Zoe Roux on 5/31/21.
|
||||
//
|
||||
|
||||
#include <Component/Bomb/BasicBombComponent.hpp>
|
||||
#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<PositionComponent>();
|
||||
wal.getSystem<EventSystem>().dispatchEvent([&bombPosition](WAL::Entity &entity){
|
||||
auto &basicBomb = bomb.getComponent<BasicBombComponent>();
|
||||
wal.getSystem<EventSystem>().dispatchEvent([&bombPosition, &basicBomb](WAL::Entity &entity){
|
||||
auto *health = entity.tryGetComponent<HealthComponent>();
|
||||
auto *pos = entity.tryGetComponent<PositionComponent>();
|
||||
|
||||
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<PositionComponent>(position)
|
||||
.addComponent<BasicBombComponent>(holder.damage, holder.explosionRadius)
|
||||
.addComponent<TimerComponent>(BombHolderSystem::explosionTimer, &BombHolderSystem::_bombExplosion)
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>("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<PositionComponent, BombHolderComponent, ControllableComponent> &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;
|
||||
|
||||
@@ -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<PositionComponent, BombHolderComponent, ControllableComponent> &entity, std::chrono::nanoseconds dtime) override;
|
||||
|
||||
Reference in New Issue
Block a user