mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-27 08:13:18 +00:00
HealthComponent / HealthSystem
Component and system for health
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
// Edited by Louis Auzuret on 2021-05-20.
|
||||
//
|
||||
|
||||
#include "./Camera.hpp"
|
||||
|
||||
Camera::Camera(std::string name)
|
||||
: WAL::Entity(name)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
// Edited by Louis Auzuret on 2021-05-20.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "lib/wal/sources/Entity/Entity.hpp"
|
||||
#include "lib/wal/sources/Models/Vector3.hpp"
|
||||
|
||||
class Camera : public WAL::Entity
|
||||
{
|
||||
private:
|
||||
std::string _name;
|
||||
protected:
|
||||
public:
|
||||
Camera(std::string name);
|
||||
~Camera();
|
||||
|
||||
//! @brief camera zoom in
|
||||
void zoomIn(WAL::Vector3f) const;
|
||||
//! @brief camera zoom out
|
||||
void zoomOut(WAL::Vector3f) const;
|
||||
//! @brief camera zoom on
|
||||
void zoomOn(WAL::Entity &) const;
|
||||
|
||||
};
|
||||
@@ -1,95 +0,0 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
// Edited by Louis Auzuret on 2021-05-20.
|
||||
//
|
||||
|
||||
#include "BombComponent.hpp"
|
||||
|
||||
BombComponent::BombComponent(WAL::Entity &entity, BombType bombType, unsigned int ownerUid)
|
||||
: WAL::Component(entity)
|
||||
{
|
||||
this->_bombType = bombType;
|
||||
this->_ownerUid = ownerUid;
|
||||
this->_isGhosting = bombType == BombComponent::DANGEROUS ? true : false;
|
||||
this->_isBreakingWall = false;
|
||||
this->_explosionDist = 0;
|
||||
this->_explosionHeight = 0;
|
||||
this->_countdown = 0;
|
||||
this->_explosionDamage = 0;
|
||||
}
|
||||
|
||||
BombComponent::~BombComponent()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
unsigned BombComponent::getCountdown() const
|
||||
{
|
||||
return (this->_countdown);
|
||||
}
|
||||
|
||||
unsigned BombComponent::getExplosionDist() const
|
||||
{
|
||||
return (this->_explosionDist);
|
||||
}
|
||||
|
||||
unsigned BombComponent::getExplosionHeight() const
|
||||
{
|
||||
return (this->_explosionHeight);
|
||||
}
|
||||
|
||||
unsigned BombComponent::getExplosionDamage() const
|
||||
{
|
||||
return (this->_explosionDamage);
|
||||
}
|
||||
|
||||
unsigned BombComponent::getOwnerUid() const
|
||||
{
|
||||
return (this->_ownerUid);
|
||||
}
|
||||
|
||||
bool BombComponent::isBreakingWall() const
|
||||
{
|
||||
return (this->_isBreakingWall);
|
||||
}
|
||||
|
||||
bool BombComponent::isGhosting() const
|
||||
{
|
||||
return (this->_isGhosting);
|
||||
}
|
||||
|
||||
void BombComponent::setCountdown(unsigned countdown)
|
||||
{
|
||||
this->_countdown = countdown;
|
||||
}
|
||||
|
||||
void BombComponent::setExplosionDist(unsigned explosionDist)
|
||||
{
|
||||
this->_explosionDist = explosionDist;
|
||||
}
|
||||
|
||||
void BombComponent::setExplosionHeight(unsigned explosionHeight)
|
||||
{
|
||||
this->_explosionHeight = explosionHeight;
|
||||
}
|
||||
|
||||
void BombComponent::setExplosionDamage(unsigned explosionDamage)
|
||||
{
|
||||
this->_explosionDamage = explosionDamage;
|
||||
}
|
||||
|
||||
void BombComponent::setOwnerUid(unsigned ownerUid)
|
||||
{
|
||||
this->_ownerUid = ownerUid;
|
||||
}
|
||||
|
||||
void BombComponent::setBreakingWall(bool isBreakingWall)
|
||||
{
|
||||
this->_isBreakingWall = isBreakingWall;
|
||||
}
|
||||
|
||||
void BombComponent::setGhosting(bool isGhosting)
|
||||
{
|
||||
this->_isBreakingWall = isBreakingWall;
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
// Edited by Louis Auzuret on 2021-05-20.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "lib/wal/sources/Component/Component.hpp"
|
||||
#include "lib/wal/sources/Entity/Entity.hpp"
|
||||
#include "lib/wal/sources/Models/Vector3.hpp"
|
||||
|
||||
class BombComponent : public WAL::Component
|
||||
{
|
||||
|
||||
public:
|
||||
//! @brief Enum of bomb type
|
||||
enum BombType {
|
||||
CLASSIC,
|
||||
REMOTE,
|
||||
STICKY,
|
||||
DANGEROUS,
|
||||
THROWABLE
|
||||
};
|
||||
//! @brief Constructor
|
||||
BombComponent(WAL::Entity &entity, BombType bombType, unsigned int ownerUid);
|
||||
~BombComponent() override = default;
|
||||
//! @brief A bomb component is copyable
|
||||
BombComponent(const BombComponent &) = default;
|
||||
//! @brief A bomb component is assignable
|
||||
BombComponent &operator=(const BombComponent &) = delete;
|
||||
|
||||
//! @brief Get the remaining time of the bomb
|
||||
unsigned getCountdown() const;
|
||||
//! @brief Get the explosion dist of the bomb
|
||||
unsigned getExplosionDist() const;
|
||||
//! @brief Get the explosion height of the bomb
|
||||
unsigned getExplosionHeight() const;
|
||||
//! @brief Get the damage of the bomb
|
||||
unsigned getExplosionDamage() const;
|
||||
//! @brief Get the owner uid
|
||||
unsigned getOwnerUid() const;
|
||||
//! @brief Is able to break wall
|
||||
bool isBreakingWall() const;
|
||||
//! @brief Is able to pass through wall
|
||||
bool isGhosting() const;
|
||||
|
||||
//! @brief Set the remaining time of the bomb
|
||||
void setCountdown(unsigned countdown);
|
||||
//! @brief Set the explosion dist of the bomb
|
||||
void setExplosionDist(unsigned explosionDist);
|
||||
//! @bries Set the explosion height of the bomb
|
||||
void setExplosionHeight(unsigned explosionHeight);
|
||||
//! @brief Set the damage of the bomb
|
||||
void setExplosionDamage(unsigned explosionDamage);
|
||||
//! @brief Set the owner uid
|
||||
void setOwnerUid(unsigned isOwnerUid);
|
||||
//! @brief Set ability to break wall
|
||||
void setBreakingWall(bool isBreakingWall);
|
||||
//! @brief set ability to pass through wall
|
||||
void setGhosting(bool isGhosting);
|
||||
|
||||
private:
|
||||
//! @brief Direction enum
|
||||
enum Direction {
|
||||
UP,
|
||||
RIGHT,
|
||||
DOWN,
|
||||
LEFT,
|
||||
VERTICAL, // UP + DOWN
|
||||
HORIZONTAL, // RIGHT + LEFT
|
||||
CLASSIC, // UP + LEFT + RIGHT + DOWN
|
||||
ALL, // SQUARE AROUND
|
||||
};
|
||||
|
||||
//! @brief Pass through walls
|
||||
bool _isGhosting;
|
||||
//! @brief Is bomb breaking wall
|
||||
bool _isBreakingWall;
|
||||
//! @brief Explosion range of the bomb
|
||||
unsigned _explosionDist;
|
||||
//! @brief Explosion height
|
||||
unsigned _explosionHeight;
|
||||
//! @brief The time remaining before the explosion
|
||||
unsigned _countdown;
|
||||
//! @brief The damage of the bomb (on player)
|
||||
unsigned _explosionDamage;
|
||||
//! @brief The owner uid of the bomb
|
||||
unsigned _ownerUid;
|
||||
//! @brief bombType
|
||||
BombComponent::BombType _bombType;
|
||||
|
||||
protected:
|
||||
};
|
||||
@@ -1,83 +0,0 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
// Edited by Louis Auzuret on 2021-05-20.
|
||||
//
|
||||
|
||||
#include "CharacterComponent.hpp"
|
||||
|
||||
CharacterComponent::CharacterComponent(WAL::Entity &entity, BombComponent::BombType bombType)
|
||||
: WAL::Component(entity)
|
||||
{
|
||||
this->_bombType = bombType;
|
||||
this->_canTriggerRemote = false;
|
||||
this->_healthPoint = 1;
|
||||
this->_isHuman = false;
|
||||
this->_maxBombCount = 1;
|
||||
this->_playerNumber = ++this->_nextPlayer;
|
||||
}
|
||||
|
||||
CharacterComponent::~CharacterComponent()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
unsigned CharacterComponent::getPlayerNumber() const
|
||||
{
|
||||
return (this->_playerNumber);
|
||||
}
|
||||
|
||||
unsigned CharacterComponent::getHealthPoint() const
|
||||
{
|
||||
return (this->_healthPoint);
|
||||
}
|
||||
|
||||
unsigned CharacterComponent::getMaxBombCount() const
|
||||
{
|
||||
return(this->_maxBombCount);
|
||||
}
|
||||
|
||||
BombComponent::BombType CharacterComponent::getBombType() const
|
||||
{
|
||||
return (this->_bombType);
|
||||
}
|
||||
|
||||
bool CharacterComponent::isHuman() const
|
||||
{
|
||||
return (this->_isHuman);
|
||||
}
|
||||
|
||||
bool CharacterComponent::canTriggerRemote() const
|
||||
{
|
||||
return (this->_canTriggerRemote);
|
||||
}
|
||||
|
||||
void CharacterComponent::setPlayerNumber(unsigned playerNumber)
|
||||
{
|
||||
this->_playerNumber = playerNumber;
|
||||
}
|
||||
|
||||
void CharacterComponent::setHealthPoint(unsigned healthPoint)
|
||||
{
|
||||
this->_healthPoint = healthPoint;
|
||||
}
|
||||
|
||||
unsigned CharacterComponent::setMaxBombCount(unsigned maxBombCount)
|
||||
{
|
||||
this->_maxBombCount = maxBombCount;
|
||||
}
|
||||
|
||||
BombComponent::BombType CharacterComponent::setBombType(BombComponent::BombType bombType)
|
||||
{
|
||||
this->_bombType = bombType;
|
||||
}
|
||||
|
||||
bool CharacterComponent::setIsHuman(bool isHuman)
|
||||
{
|
||||
this->_isHuman = isHuman;
|
||||
}
|
||||
|
||||
bool CharacterComponent::setCanTriggerRemote(bool canTriggerRemote)
|
||||
{
|
||||
this->_canTriggerRemote = canTriggerRemote;
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
// Edited by Louis Auzuret on 2021-05-20.
|
||||
//
|
||||
|
||||
#include "lib/wal/sources/Component/Component.hpp"
|
||||
#include "sources/Component/Bomb/BombComponent.hpp"
|
||||
#include "lib/wal/sources/Models/Vector3.hpp"
|
||||
|
||||
class CharacterComponent : public WAL::Component
|
||||
{
|
||||
private:
|
||||
//! @brief player number
|
||||
unsigned _playerNumber;
|
||||
//! @brief health point of the character
|
||||
unsigned _healthPoint;
|
||||
//! @brief maximum number of bombs a character can put
|
||||
unsigned _maxBombCount;
|
||||
//! @brief bomb type of the character
|
||||
BombComponent::BombType _bombType;
|
||||
//! @brief is player a human being
|
||||
bool _isHuman;
|
||||
//! @brief Remote bomb trigger available
|
||||
bool _canTriggerRemote;
|
||||
static unsigned _nextPlayer;
|
||||
protected:
|
||||
public:
|
||||
|
||||
CharacterComponent(WAL::Entity &entity, BombComponent::BombType bombType);
|
||||
~CharacterComponent() override = default;
|
||||
//! @brief A character component is copyable
|
||||
CharacterComponent(const CharacterComponent &) = default;
|
||||
//! @brief A character component is assignable
|
||||
CharacterComponent &operator=(const CharacterComponent &) = delete;
|
||||
|
||||
//! @brief get player number
|
||||
unsigned getPlayerNumber() const;
|
||||
//! @brief get health point of the character
|
||||
unsigned getHealthPoint() const;
|
||||
//! @brief get maximum number of bombs a character can put
|
||||
unsigned getMaxBombCount() const;
|
||||
//! @brief get bomb type of the character
|
||||
BombComponent::BombType getBombType() const;
|
||||
//! @brief is player a human being
|
||||
bool isHuman() const;
|
||||
//! @brief trigger can be remote
|
||||
bool canTriggerRemote() const;
|
||||
|
||||
//! @brief set player number
|
||||
void setPlayerNumber(unsigned playerNumber);
|
||||
//! @brief set health point of the character
|
||||
void setHealthPoint(unsigned healthPoint);
|
||||
//! @brief set maximum number of bombs a character can put
|
||||
unsigned setMaxBombCount(unsigned maxBombCount);
|
||||
//! @brief set bomb type of the character
|
||||
BombComponent::BombType setBombType(BombComponent::BombType bombType);
|
||||
//! @brief set if player is a human being
|
||||
bool setIsHuman(bool isHuman);
|
||||
//! @brief Remote bomb trigger available
|
||||
bool setCanTriggerRemote(bool canTriggerRemote);
|
||||
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
// Edited by Louis Auzuret on 2021-05-20.
|
||||
//
|
||||
|
||||
#include "HealthComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
HealthComponent::HealthComponent(WAL::Entity &entity)
|
||||
: WAL::Component(entity),
|
||||
_healthPoint()
|
||||
{}
|
||||
|
||||
HealthComponent::HealthComponent(WAL::Entity &entity, unsigned int healthPoint)
|
||||
: WAL::Component(entity),
|
||||
_healthPoint(healthPoint)
|
||||
{}
|
||||
|
||||
WAL::Component *HealthComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new HealthComponent(entity);
|
||||
}
|
||||
|
||||
void HealthComponent::addHealthPoint(unsigned int healthPoint)
|
||||
{
|
||||
this->_healthPoint += healthPoint;
|
||||
}
|
||||
|
||||
void HealthComponent::takeDmg(unsigned int damage)
|
||||
{
|
||||
if (damage >= this->_healthPoint)
|
||||
this->die();
|
||||
else
|
||||
this->_healthPoint -= damage;
|
||||
}
|
||||
|
||||
void HealthComponent::die(void)
|
||||
{
|
||||
this->setDisable(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
// Edited by Louis Auzuret on 2021-05-20.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "lib/wal/sources/Component/Component.hpp"
|
||||
#include "lib/wal/sources/Entity/Entity.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class HealthComponent : public WAL::Component
|
||||
{
|
||||
|
||||
private:
|
||||
//! @brief life of an entity
|
||||
unsigned int _healthPoint;
|
||||
|
||||
public:
|
||||
//! @brief add health to the entity
|
||||
void addHealthPoint(unsigned int healthPoint);
|
||||
|
||||
//! @brief reduce health
|
||||
void takeDmg(unsigned int damage);
|
||||
|
||||
//! @brief health to 0
|
||||
void die(void);
|
||||
|
||||
//! @inherit
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
//! @brief A component can't be instantiated, it should be derived.
|
||||
explicit HealthComponent(WAL::Entity &entity);
|
||||
|
||||
//! @brief Constructor
|
||||
HealthComponent(WAL::Entity &entity, unsigned int healthPoint);
|
||||
|
||||
//! @brief A component can't be instantiated, it should be derived.
|
||||
HealthComponent(const HealthComponent &) = default;
|
||||
|
||||
//! @brief default destructor
|
||||
~HealthComponent() override = default;
|
||||
|
||||
//! @brief A component can't be assigned
|
||||
HealthComponent &operator=(const HealthComponent &) = delete;
|
||||
|
||||
friend class HealthSystem;
|
||||
};
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
// Edited by Louis Auzuret on 2021-05-20.
|
||||
//
|
||||
|
||||
#include "PowerUpComponent.hpp"
|
||||
|
||||
PowerUpComponent::PowerUpComponent(WAL::Entity &entity, PowerUpType powerType, int duration, bool infinite)
|
||||
: WAL::Component(entity)
|
||||
{
|
||||
this->_duration = duration;
|
||||
this->_isInfinite = infinite;
|
||||
this->_powerUpType = powerType;
|
||||
}
|
||||
|
||||
PowerUpComponent::~PowerUpComponent()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool PowerUpComponent::getIsInfinite() const
|
||||
{
|
||||
return (this->_isInfinite);
|
||||
}
|
||||
|
||||
unsigned PowerUpComponent::getDuration() const
|
||||
{
|
||||
return (this->_duration);
|
||||
}
|
||||
|
||||
PowerUpComponent::PowerUpType PowerUpComponent::getPowerUpType() const
|
||||
{
|
||||
return (this->_powerUpType);
|
||||
}
|
||||
|
||||
void PowerUpComponent::setIsInfinite(bool isInfinite)
|
||||
{
|
||||
this->_isInfinite = isInfinite;
|
||||
}
|
||||
|
||||
void PowerUpComponent::setDuration(unsigned duration)
|
||||
{
|
||||
this->_duration = duration;
|
||||
}
|
||||
|
||||
void PowerUpComponent::setPowerUpType(PowerUpType powerUpType)
|
||||
{
|
||||
this->_powerUpType = powerUpType;
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
// Edited by Louis Auzuret on 2021-05-20.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "lib/wal/sources/Component/Component.hpp"
|
||||
#include "lib/wal/sources/Entity/Entity.hpp"
|
||||
|
||||
class PowerUpComponent : public WAL::Component
|
||||
{
|
||||
public:
|
||||
|
||||
enum PowerUpType {
|
||||
SPEED,
|
||||
FIREPOWER,
|
||||
BOMBCOUNT,
|
||||
BOMBKICK
|
||||
};
|
||||
|
||||
PowerUpComponent(WAL::Entity &entity, PowerUpType powerType, int duration, bool infinite = false);
|
||||
~PowerUpComponent();
|
||||
//! @brief A power up component is copyable
|
||||
PowerUpComponent(const PowerUpComponent &) = default;
|
||||
//! @brief A power up component is assignable
|
||||
PowerUpComponent &operator=(const PowerUpComponent &) = delete;
|
||||
|
||||
//! @brief Get is the power up infinite
|
||||
bool getIsInfinite() const;
|
||||
//! @brief Get duration
|
||||
unsigned getDuration() const;
|
||||
//! @brief Get power up type
|
||||
PowerUpType getPowerUpType() const;
|
||||
|
||||
//! @brief Set if bomb duration infinite
|
||||
void setIsInfinite(bool isInfinite);
|
||||
//! @brief Set duration
|
||||
void setDuration(unsigned duration);
|
||||
//! @brief Set power up type
|
||||
void setPowerUpType(PowerUpType powerUpType);
|
||||
|
||||
protected:
|
||||
private:
|
||||
|
||||
|
||||
//! @brief Is the power up infinite
|
||||
bool _isInfinite;
|
||||
//! @brief Duration of the power up
|
||||
unsigned _duration;
|
||||
//! @brief Power up type
|
||||
PowerUpType _powerUpType;
|
||||
|
||||
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
// Edited by Louis Auzuret on 2021-05-20.
|
||||
//
|
||||
|
||||
#include "HealthSystem.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
const std::type_info &HealthSystem::getComponent() const
|
||||
{
|
||||
return typeid(HealthComponent);
|
||||
}
|
||||
|
||||
void HealthSystem::onFixedUpdate(WAL::Entity &entity)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
// Edited by Louis Auzuret on 2021-05-20.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Components/Health/HealthComponent.hpp"
|
||||
#include "lib/wal/sources/System/System.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class HealthSystem : public WAL::System
|
||||
{
|
||||
public:
|
||||
//! @inherit
|
||||
const std::type_info &getComponent() const override;
|
||||
//! @inherit
|
||||
void onFixedUpdate(Entity &entity) override;
|
||||
|
||||
//! @brief A default constructor
|
||||
HealthSystem() = default;
|
||||
//! @brief A health system is copy constructable
|
||||
HealthSystem(const HealthSystem &) = default;
|
||||
//! @brief A default destructor
|
||||
~HealthSystem() override = default;
|
||||
//! @brief A health system is assignable.
|
||||
HealthSystem &operator=(const HealthSystem &) = default;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user