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;
140 PRETTY_DEBUG <<
"User Position: " << _collision << std::endl;
141 PRETTY_DEBUG <<
"bullet: " << _bullet <<
", shot: " << shot << std::endl;
204const int GUI::ECS::Online::EnemyBrain::_randInt(
int min,
int max)
206 static std::random_device
rd;
207 static std::mt19937 gen(
rd());
208 std::uniform_int_distribution<> dist(min, max);
216 std::string indentation =
"";
217 for (
unsigned int i = 0; i < indent; ++i) {
220 std::string result = indentation +
"Enemy brain:\n";
224 result += indentation +
"- Delay before shot: '" +
Recoded::myToString(_delayBeforeShot) +
"'\n";
225 result += indentation +
"- Bullet: {\n" + _bullet.getInfo(indent + 1) + indentation +
"}\n";
226 result += indentation +
"- Collision: {\n" + _collision.getInfo(indent + 1) + indentation +
"}\n";
227 result += indentation +
"- Sprite: {\n" + _sprite.getInfo(indent + 1) + indentation +
"}\n";
#define PRETTY_DEBUG
Debug log with details and colour.
Declaration of the EnemyBrain class and its related functionality.
Represents a drawable and interactive sprite in the ECS system.
Represents a bullet entity in the game.
void setDamage(const int damage)
Sets the damage dealt by the bullet.
void setPosition(const std::pair< float, float > &pos)
Sets the position of the bullet.
void tick()
Advances the bullet's state by one tick.
The EnemyBrain class represents the logic and behavior of an enemy entity.
const GUI::ECS::Components::SpriteComponent render()
Renders the enemy's sprite.
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 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 ...
void setVisible(const bool visible)
Sets the visibility of the enemy.
const bool isVisible() const
Checks if the enemy is visible.
const bool isColliding(const GUI::ECS::Systems::Collision &second) const
Checks if the enemy is colliding with another entity.
void setPosition(const std::pair< float, float > &pos)
Sets the position of the enemy.
EnemyBrain & operator=(const GUI::ECS::Online::EnemyBrain ©)
Overloads the assignment operator to copy from another EnemyBrain.
EnemyBrain(const std::uint32_t entityId=0)
Default constructor.
void setDimension(const std::pair< float, float > &size)
Sets the dimensions of the enemy.
const long int getHealth() const
Gets the health of the enemy.
const GUI::ECS::Online::Bullet shoot(const std::uint32_t id)
Make the enemy shoot a projectile with a defined id.
const bool getVisible() const
Gets the visibility status of the enemy.
const GUI::ECS::Components::SpriteComponent getSprite() const
Gets the sprite data for the enemy.
void setBulletSize(const std::pair< float, float > &size)
Sets the size of the bullet.
const GUI::ECS::Systems::Collision getCollision() const
Gets the collision data for the enemy.
void update(const GUI::ECS::Online::EnemyBrain ©)
Updates the sprite by copying another EnemyBrain.
void tick()
Updates the enemy's state and determines if it should fire a bullet.
const GUI::ECS::Online::Bullet getBullet() const
Gets the bullet data for the enemy.
void setHealth(const long int health)
Sets the health of the enemy.
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.