mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-29 08:52:06 +00:00
Making walls breakables
This commit is contained in:
@@ -13,9 +13,10 @@ namespace BBM
|
||||
_healthPoint()
|
||||
{}
|
||||
|
||||
HealthComponent::HealthComponent(WAL::Entity &entity, unsigned int healthPoint)
|
||||
HealthComponent::HealthComponent(WAL::Entity &entity, unsigned int healthPoint, WAL::Callback<WAL::Entity &> onDeath)
|
||||
: WAL::Component(entity),
|
||||
_healthPoint(healthPoint)
|
||||
_healthPoint(healthPoint),
|
||||
onDeath(onDeath)
|
||||
{}
|
||||
|
||||
WAL::Component *HealthComponent::clone(WAL::Entity &entity) const
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace BBM
|
||||
explicit HealthComponent(WAL::Entity &entity);
|
||||
|
||||
//! @brief Constructor
|
||||
HealthComponent(WAL::Entity &entity, unsigned int healthPoint);
|
||||
HealthComponent(WAL::Entity &entity, unsigned int healthPoint, WAL::Callback<WAL::Entity &> onDeath = WAL::Callback<WAL::Entity &>());
|
||||
|
||||
//! @brief A Health component can't be instantiated, it should be derived.
|
||||
HealthComponent(const HealthComponent &) = default;
|
||||
|
||||
+6
-1
@@ -30,6 +30,11 @@ namespace BBM
|
||||
// mov->_velocity.z = 0;
|
||||
}
|
||||
|
||||
void MapGenerator::wallDestroyed(WAL::Entity &entity)
|
||||
{
|
||||
entity.scheduleDeletion();
|
||||
}
|
||||
|
||||
const std::string MapGenerator::assetsPath = "./assets/";
|
||||
const std::string MapGenerator::wallAssetsPath = MapGenerator::assetsPath + "map/";
|
||||
const std::string MapGenerator::imageExtension = ".png";
|
||||
@@ -133,7 +138,7 @@ namespace BBM
|
||||
|
||||
scene->addEntity("Breakable Block")
|
||||
.addComponent<PositionComponent>(coords)
|
||||
.addComponent<HealthComponent>(1)
|
||||
.addComponent<HealthComponent>(1, &MapGenerator::wallDestroyed)
|
||||
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>(breakableObj, std::make_pair(MAP_DIFFUSE, breakablePng));
|
||||
}
|
||||
|
||||
@@ -155,6 +155,7 @@ namespace BBM
|
||||
|
||||
public:
|
||||
static void wallCollide(WAL::Entity &entity, const WAL::Entity &wall);
|
||||
static void wallDestroyed(WAL::Entity &entity);
|
||||
|
||||
|
||||
//! @param width Width of the map
|
||||
|
||||
@@ -31,8 +31,10 @@ namespace BBM
|
||||
|
||||
if (!health || !pos)
|
||||
return;
|
||||
if (pos->position.distance(bombPosition.position) <= BombHolderSystem::explosionRadius)
|
||||
health->takeDmg(1);
|
||||
if (pos->position.distance(bombPosition.position) > BombHolderSystem::explosionRadius)
|
||||
return;
|
||||
// TODO do a raycast here to only remove health to entities that are not behind others.
|
||||
health->takeDmg(1);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user