36 PRETTY_DEBUG <<
"Setting the sprite content" << std::endl;
39 _bullet.setSprite(*bullet);
41 _bullet.setVisible(
true);
42 _bullet.setEnemy(
false);
45 _bullet.setPosition({ 1,1 });
46 _bullet.setDirection({ 1,0 });
47 _bullet.setSize({ 0.5, 0.5 });
50 _collision.update(_sprite.getCollision());
51 _collision.setPosition(_bullet.getPosition());
54 PRETTY_DEBUG <<
"Collision info: " << _collision << std::endl;
60 _collision.setPosition(pos);
61 _sprite.setPosition(pos);
62 _bullet.setPosition(pos);
63 PRETTY_DEBUG <<
"collision: " << _collision <<
"sprite: " << _sprite <<
"bullet:" << _bullet << std::endl;
68 _collision.setDimension(dim);
69 _sprite.setDimension(dim);
83 _sprite.setVisible(visible);
88 _bullet.setSize(size);
93 PRETTY_DEBUG <<
"Enemy Position: X = " << _collision.getPositionX()
94 <<
", Y = " << _collision.getPositionY()
95 <<
", Width = " << _collision.getWidth()
96 <<
", Height = " << _collision.getHeight() << std::endl;
100 <<
", Width = " << second.
getWidth()
101 <<
", Height = " << second.
getHeight() << std::endl;
104 PRETTY_DEBUG <<
"Setting the tolerance for the collision" << std::endl;
105 const float tolerance = 30.0f;
108 PRETTY_DEBUG <<
"Calculating the overlap of X" << std::endl;
109 const bool xOverlap = (std::abs(_collision.getPositionX() - second.
getPositionX()) <= (tolerance + (_collision.getWidth() + second.
getWidth())));
112 PRETTY_DEBUG <<
"Calculating the overlap of Y" << std::endl;
113 const bool yOverlap = (std::abs(_collision.getPositionY() - second.
getPositionY()) <= (tolerance + (_collision.getHeight() + second.
getHeight())));
117 PRETTY_DEBUG <<
"Checking if x and y are overlapping" << std::endl;
118 const bool overlapping = xOverlap && yOverlap;
141 PRETTY_DEBUG <<
"User Position: " << _collision << std::endl;
142 PRETTY_DEBUG <<
"bullet: " << _bullet <<
", shot: " << shot << std::endl;
206 std::string indentation =
"";
207 for (
unsigned int i = 0; i < indent; ++i) {
210 std::string result = indentation +
"Player brain:\n";
214 result += indentation +
"- Bullet: {\n" + _bullet.
getInfo(indent + 1) + indentation +
"}\n";
215 result += indentation +
"- Collision: {\n" + _collision.getInfo(indent + 1) + indentation +
"}\n";
216 result += indentation +
"- Sprite: {\n" + _sprite.getInfo(indent + 1) + indentation +
"}\n";
Declaration of the PlayerBrain class and 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 setSize(const std::pair< float, float > &dimension)
Sets the size of the bullet.
void tick()
Advances the bullet's state by one tick.
Forward declaration of the Bullet class.
const long int getHealth() const
Gets the player's health value.
void setBulletSize(const std::pair< float, float > &size)
Sets the bullet dimensions.
void setPosition(const std::pair< float, float > &pos)
Sets the player's position.
PlayerBrain & operator=(const GUI::ECS::Demo::PlayerBrain ©)
Overloads the assignment operator to copy from another PlayerBrain.
void setVisible(const bool visible)
Sets the player's visibility state.
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 bool isColliding(const GUI::ECS::Systems::Collision &second) const
Checks if the player is colliding with another entity.
void setHealth(const long int health)
Sets the player's health.
void tick()
Updates the player's state for the current frame.
PlayerBrain(const std::uint32_t entityId=0)
Default constructor.
const GUI::ECS::Demo::Bullet shoot() const
Simulates the player shooting a bullet.
void setSprite(const std::shared_ptr< GUI::ECS::Components::SpriteComponent > &sprite, const std::shared_ptr< GUI::ECS::Components::SpriteComponent > &bullet)
Sets the sprite and bullet sprite components for the player.
const bool getVisible() const
Gets the player's visibility state.
const GUI::ECS::Components::SpriteComponent render()
Renders the player's sprite to the screen.
const bool isVisible() const
Checks if the player is currently visible.
const GUI::ECS::Systems::Collision getCollision() const
Gets the player's collision component.
void update(const GUI::ECS::Demo::PlayerBrain ©)
Updates the player's state by copying another PlayerBrain.
void setDimension(const std::pair< float, float > &size)
Sets the player's dimensions.
const GUI::ECS::Demo::Bullet getBullet() const
Gets the player's bullet instance.
const GUI::ECS::Components::SpriteComponent getSprite() const
Gets the player's sprite component.
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 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 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.