35 PRETTY_DEBUG <<
"Setting the sprite content" << std::endl;
38 _bullet.setSprite(*bullet);
40 _bullet.setVisible(
true);
41 _bullet.setEnemy(
true);
44 _bullet.setPosition({ 1,1 });
45 _bullet.setDirection({ -1,0 });
46 _bullet.setSize({ 0.5, 0.5 });
49 _collision.update(_sprite.getCollision());
50 _collision.setPosition(_bullet.getPosition());
53 PRETTY_DEBUG <<
"Collision info: " << _collision << std::endl;
59 _collision.setPosition(pos);
60 _sprite.setPosition(pos);
61 _bullet.setPosition(pos);
62 PRETTY_DEBUG <<
"collision: " << _collision <<
"sprite: " << _sprite <<
"bullet:" << _bullet << std::endl;
67 _collision.setDimension(dim);
68 _sprite.setDimension(dim);
82 _sprite.setVisible(visible);
87 _bullet.setSize(size);
92 PRETTY_DEBUG <<
"Enemy Position: X = " << _collision.getPositionX()
93 <<
", Y = " << _collision.getPositionY()
94 <<
", Width = " << _collision.getWidth()
95 <<
", Height = " << _collision.getHeight() << std::endl;
100 <<
", Height = " << second.
getHeight() << std::endl;
103 PRETTY_DEBUG <<
"Setting the tolerance for the collision" << std::endl;
104 const float tolerance = 30.0f;
107 PRETTY_DEBUG <<
"Calculating the overlap of X" << std::endl;
108 const bool xOverlap = (std::abs(_collision.getPositionX() - second.
getPositionX()) <= (tolerance + (_collision.getWidth() + second.
getWidth())));
111 PRETTY_DEBUG <<
"Calculating the overlap of Y" << std::endl;
112 const bool yOverlap = (std::abs(_collision.getPositionY() - second.
getPositionY()) <= (tolerance + (_collision.getHeight() + second.
getHeight())));
116 PRETTY_DEBUG <<
"Checking if x and y are overlapping" << std::endl;
117 const bool overlapping = xOverlap && yOverlap;
131 if (_delayBeforeShot == 0) {
132 _delayBeforeShot = _randInt(20, 80);
137 PRETTY_DEBUG <<
"User Position: " << _collision << std::endl;
138 PRETTY_DEBUG <<
"bullet: " << _bullet <<
", shot: " << shot << std::endl;
140 return std::optional(shot);
205const int GUI::ECS::Demo::EnemyBrain::_randInt(
int min,
int max)
207 static std::random_device
rd;
208 static std::mt19937 gen(
rd());
209 std::uniform_int_distribution<> dist(min, max);
217 std::string indentation =
"";
218 for (
unsigned int i = 0; i < indent; ++i) {
221 std::string result = indentation +
"Enemy brain:\n";
225 result += indentation +
"- Delay before shot: '" +
Recoded::myToString(_delayBeforeShot) +
"'\n";
226 result += indentation +
"- Bullet: {\n" + _bullet.getInfo(indent + 1) + indentation +
"}\n";
227 result += indentation +
"- Collision: {\n" + _collision.getInfo(indent + 1) + indentation +
"}\n";
228 result += indentation +
"- Sprite: {\n" + _sprite.getInfo(indent + 1) + indentation +
"}\n";
Declaration of the EnemyBrain class and its related functionality.
#define PRETTY_DEBUG
Debug log with details and colour.
Represents a drawable and interactive sprite in the ECS system.
Represents a bullet entity in the game.
void setPosition(const std::pair< float, float > &pos)
Sets the position of the bullet.
void tick()
Advances the bullet's state by one tick.
void setDamage(const int damage)
Sets the damage dealt by the bullet.
The EnemyBrain class represents the logic and behavior of an enemy entity.
const bool getVisible() const
Gets the visibility status of the enemy.
const std::optional< GUI::ECS::Demo::Bullet > tick()
Updates the enemy's state and determines if it should fire a bullet.
void update(const GUI::ECS::Demo::EnemyBrain ©)
Updates the sprite by copying another EnemyBrain.
void setVisible(const bool visible)
Sets the visibility of the enemy.
const GUI::ECS::Systems::Collision getCollision() const
Gets the collision data for the enemy.
void setPosition(const std::pair< float, float > &pos)
Sets the position of the enemy.
const bool isColliding(const GUI::ECS::Systems::Collision &second) const
Checks if the enemy is colliding with another entity.
const GUI::ECS::Demo::Bullet getBullet() const
Gets the bullet data for the enemy.
const std::string getInfo(const unsigned int indent=0) const
This is a function meant for debugging purposes It will dump the current state of the variables upon ...
const GUI::ECS::Components::SpriteComponent render()
Renders the enemy's sprite.
EnemyBrain & operator=(const GUI::ECS::Demo::EnemyBrain ©)
Overloads the assignment operator to copy from another EnemyBrain.
void setHealth(const long int health)
Sets the health of the enemy.
void setSprite(const std::shared_ptr< GUI::ECS::Components::SpriteComponent > &sprite, const std::shared_ptr< GUI::ECS::Components::SpriteComponent > &bullet)
Sets the sprite components for the enemy and its bullet.
const bool isVisible() const
Checks if the enemy is visible.
const long int getHealth() const
Gets the health of the enemy.
void setDimension(const std::pair< float, float > &size)
Sets the dimensions of the enemy.
const GUI::ECS::Components::SpriteComponent getSprite() const
Gets the sprite data for the enemy.
EnemyBrain(const std::uint32_t entityId=0)
Default constructor.
void setBulletSize(const std::pair< float, float > &size)
Sets the size of the bullet.
Represents a rectangular component that can detect collisions and mouse interactions,...
const float getWidth() const
Gets the width of the component.
const float getHeight() const
Gets the height of the component.
const float getPositionY() const
Gets the Y-coordinate of the component's position.
const float getPositionX() const
Gets the X-coordinate of the component's position.
std::ostream & operator<<(std::ostream &os, const Bullet &item)
Outputs the sprite's info to a stream.
const std::string myToString(const Rect< RectType > &rectangle)
Converts a Rect<T> object to its string representation.