Making walls breakables

This commit is contained in:
Zoe Roux
2021-06-07 21:47:04 +02:00
parent 7234d51130
commit fe9a650427
5 changed files with 15 additions and 6 deletions
+3 -2
View File
@@ -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
+1 -1
View File
@@ -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
View File
@@ -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));
}
+1
View File
@@ -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);
});
}