AEntity

The AEntity class is the base of all entitites in the game. The methods in this class are used by all entities to interact with the game and to interact between each other.

This class is derived from the IEntity interface and implements some of its methods.

Some methods remains as pure virtual and must be implemented in each entity.

Public member functions

// Construct a new AEntity
AEntity(Room &room, u_int id, short x, short y, short w, short h);
// Construct a new AEntity
AEntity(Room &room, u_int id, const std::pair<short, short> &pos, const std::pair<short, short> &size);

// Refresh the entity (move, shoot, etc.)
virtual void refresh() = 0;
// Get the position of the entity
virtual std::pair<short, short> position() const;
// Get the id of the entity
virtual u_int id() const;
// Check if the entity is out of the screen
virtual bool isOutOfScreen() const;
// Check if the entity collide with another entity
virtual bool collide(const IEntity &other);
// Get the bounding box of the entity (used to check collision)
virtual const BoundingBox<short> &box() const;
// Kill the entity
// Check if the entity exist (alive)
virtual bool getExist() const;
// Check if the entity is deletable (dead)
virtual bool getDeletable() const;

Protected member functions

// Move the entity
virtual void move(short dx, short dy);

Protected attributes

// The room in which the entity is
Room &_room;
// The id of the entity
u_int _id;
// The bounding box of the entity (position and size)
BoundingBox<short> _box;
// The existence of the entity (alive)
bool _exist;
// The deletability of the entity (dead)
bool _deletable;
// The last time the entity moved
std::chrono::system_clock::time_point _lastMove;

Member functions documentation

Constructor

This constructor creates a new AEntity with the given parameters.

AEntity(Room &room, u_int id, short x, short y, short w, short h);
AEntity(Room &room, u_int id, const std::pair<short, short> &pos, const std::pair<short, short> &size);

Parameters

  • room : The room in which the entity is.

  • id : The id of the entity.

  • x : The x position of the entity.

  • y : The y position of the entity.

  • w : The width of the entity.

  • h : The height of the entity.

  • pos : The position of the entity.

  • size : The size of the entity.

refresh

See IEntity::refresh.

position

See IEntity::position.

id

See IEntity::id.

isOutOfScreen

See IEntity::isOutOfScreen.

collide

See IEntity::collide.

box

See IEntity::box.

killEntity

See IEntity::killEntity.

getExist

See IEntity::getExist.

getDeletable

See IEntity::getDeletable.

move

This function moves the entity by the given amount of delta x and delta y.

virtual void move(short dx, short dy);

Parameters

  • dx : The delta x to move the entity by.

  • dy : The delta y to move the entity by.

Attributes documentation

_room

The room in which the entity is. It is mainly used to send some messages to all clients connected to the room.

Room &_room;

_id

The id of the entity.

u_int _id;

_box

The bounding box of the entity (position and size).

BoundingBox<short> _box;

_exist

The existence of the entity (alive).

bool _exist;

_deletable

The deletability of the entity (dead). This attribute is used by the game loop to delete the entity.

bool _deletable;

_lastMove

The last time the entity moved. This attribute is used to manage the time between each move of the entity by the refresh method.

std::chrono::system_clock::time_point _lastMove;