# 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

```cpp
// 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

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

## Protected attributes

```cpp
// 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.

```cpp
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.

```cpp
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.

```cpp
Room &_room;
```

### \_id

The id of the entity.

```cpp
u_int _id;
```

### \_box

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

```cpp
BoundingBox<short> _box;
```

### \_exist

The existence of the entity (alive).

```cpp
bool _exist;
```

### \_deletable

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

```cpp
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.

```cpp
std::chrono::system_clock::time_point _lastMove;
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://redboard.gitbook.io/r-type-1/server/entities/aentity.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
