22 :
EntityNode(0), _sprite(sprite), _fromEnemy(fromEnemy), _speed(speed), _direction(direction), _positionInitial(positionInitial), _damage(damage)
24 _createBullet(positionInitial);
28 :
EntityNode(EntityId), _sprite(sprite), _fromEnemy(fromEnemy), _speed(speed), _direction(direction), _positionInitial(positionInitial), _damage(damage)
30 _createBullet(positionInitial);
49 _sprite.setVisible(visible);
54 _collision.setPosition(pos);
55 _sprite.setPosition(pos);
60 _sprite.update(sprite);
75 _direction = direction;
80 _collision.setDimension(dimension);
81 _sprite.setDimension(dimension);
91 PRETTY_DEBUG <<
"In the bullet tick function" << std::endl;
100 PRETTY_DEBUG <<
"Calculating the new position" << std::endl;
101 PRETTY_DEBUG <<
"Current collision: " << _collision.getPosition() <<
", direction: " << _direction <<
", speed :" <<
Recoded::myToString(_speed) << std::endl;
102 const float offsetX = (_direction.first *
static_cast<int>(_speed));
103 const float offsetY = (_direction.second *
static_cast<int>(_speed));
105 const float finalPositionX = _collision.getPositionX() + offsetX;
106 const float finalPositionY = _collision.getPositionY() + offsetY;
107 PRETTY_DEBUG <<
"finalPositionX = " << finalPositionX <<
", finalPositionY = " << finalPositionY << std::endl;
108 std::pair<float, float> opt = { finalPositionX,finalPositionY };
109 PRETTY_DEBUG <<
"Bullet tick: initial position: " << getPosition() <<
", updated position: " << opt << std::endl;
131 return _collision.getPosition();
141 PRETTY_DEBUG <<
"Enemy Position: X = " << _collision.getPositionX()
142 <<
", Y = " << _collision.getPositionY()
143 <<
", Width = " << _collision.getWidth()
144 <<
", Height = " << _collision.getHeight() << std::endl;
148 <<
", Width = " << second.
getWidth()
149 <<
", Height = " << second.
getHeight() << std::endl;
152 PRETTY_DEBUG <<
"Setting the tolerance for the collision" << std::endl;
153 const float tolerance = 30.0f;
156 PRETTY_DEBUG <<
"Calculating the overlap of X" << std::endl;
157 const bool xOverlap = (std::abs(_collision.getPositionX() - second.
getPositionX()) <= (tolerance + (_collision.getWidth() + second.
getWidth())));
160 PRETTY_DEBUG <<
"Calculating the overlap of Y" << std::endl;
161 const bool yOverlap = (std::abs(_collision.getPositionY() - second.
getPositionY()) <= (tolerance + (_collision.getHeight() + second.
getHeight())));
165 PRETTY_DEBUG <<
"Checking if x and y are overlapping" << std::endl;
166 const bool overlapping = xOverlap && yOverlap;
219 return _positionInitial;
235 std::string indentation =
"";
236 for (
unsigned int i = 0; i < indent; ++i) {
239 std::string result = indentation +
"Bullet:\n";
246 result += indentation +
"- Position Initial: '" +
Recoded::myToString(_positionInitial) +
"'\n";
247 result += indentation +
"- Collision: {\n" + _collision.
getInfo(indent + 1) + indentation +
"}\n";
248 result += indentation +
"- Sprite: {\n" + _sprite.getInfo(indent + 1) + indentation +
"}\n";
253void GUI::ECS::Online::Bullet::_createBullet(
const std::pair<int, int> &positionInitial)
255 _sprite.setPosition(positionInitial);
256 _collision.setPosition(positionInitial);
257 _collision.setDimension(_sprite.getSpritesheet().getCollisionInfo().getDimension());
#define PRETTY_DEBUG
Debug log with details and colour.
File in charge of containing the logic for the bullet class.
Represents a drawable and interactive sprite in the ECS system.
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 ...
Represents a bullet entity in the game.
void setDirection(const std::pair< int, int > &direction)
Sets the direction of the bullet.
const GUI::ECS::Components::SpriteComponent render()
Renders the bullet.
void setVisible(const bool visible)
Sets the visibility of the bullet.
const std::pair< int, int > getPositionInitial() const
Get the initial position that was set for the object.
const int getDamage() const
Get the Damage the bullet will inflict upon impact.
const GUI::ECS::Systems::Collision getCollision() const
Get the Collision component.
void setSprite(const GUI::ECS::Components::SpriteComponent &sprite)
Sets the sprite representing the bullet.
const bool isEnemy() const
void setDamage(const int damage)
Sets the damage dealt by the bullet.
Bullet & operator=(const GUI::ECS::Online::Bullet ©)
Overloads the assignment operator to copy from another Bullet.
Bullet(const std::uint32_t EntityId=0)
Default constructor for the Bullet class.
void setEnemy(const bool enemy)
Marks the bullet as fired by an enemy or not.
void setPosition(const std::pair< float, float > &pos)
Sets the position of the 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 ...
const GUI::ECS::Components::SpriteComponent getSprite() const
Get the Sprite component.
void setSize(const std::pair< float, float > &dimension)
Sets the size of the bullet.
const bool isVisible() const
const unsigned int getSpeed() const
Get the Speed at which the bullet is traveling.
const bool isColliding(const GUI::ECS::Systems::Collision &second) const
const std::pair< float, float > getPosition() const
const std::pair< int, int > getDirection() const
Get the Direction in which the bullet is travelling.
void update(const GUI::ECS::Online::Bullet ©)
Updates the sprite by copying another Bullet.
void setSpeed(const unsigned int speed)
Sets the speed of the bullet.
void tick()
Advances the bullet's state by one tick.
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.