IEntity

The IEntity interface 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.

All methods are pure virtual and must be implemented in each entity. Here is the list of the methods and a short description of what they are supposed to do.

Public member functions

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

Member functions documentation

refresh

This function refreshes the entity (move, shoot, etc.). It is called by the game loop at each frame. This function must be implemented in each entity and take care of its own time management.

virtual void refresh() = 0;

position

This function returns the position of the entity.

virtual std::pair<short, short> position() const = 0;

Returns

A pair of short containing the position of the entity (x, y).

id

This function returns the id of the entity.

virtual u_int id() const = 0;

Returns

An unsigned int containing the id of the entity.

isOutOfScreen

This function checks if the entity is out of the screen. It is used by the game loop to delete the entity if it is out of the screen.

virtual bool isOutOfScreen() const = 0;

Returns

A boolean containing true if the entity is out of the screen, false otherwise.

collide

This function checks if the entity collide with another entity. It is used by the game loop to manage the collision between entities.

virtual bool collide(const IEntity &other) = 0;

Parameters

  • other: A reference to the other entity to check collision with.

Returns

A boolean containing true if the entity collide with the other entity, false otherwise.

box

This function returns the bounding box of the entity. It is used by the collide function to compare the bounging boxes.

virtual const BoundingBox<short> &box() const = 0;

Returns

A const reference to the bounding box of the entity.

killEntity

This function kills the entity.

virtual void killEntity() = 0;

getExist

This function checks if the entity exist (is alive).

virtual bool getExist() const = 0;

Returns

A boolean containing true if the entity exist (is alive), false otherwise.

getDeletable

This function checks if the entity is deletable (is dead).

virtual bool getDeletable() const = 0;

Returns

A boolean containing true if the entity is deletable (is dead), false otherwise.