Manifest Entities

These entities exist inside the game realm and are mostly loaded from the manifest files one way or another. They all derieve from the base class dook::Entity.

Base Entity Class

Every single entity inherits this class, this class holds the general bookkeeping information on entites to keep track of where they were initiated.

Each entity includes a dook::EntityType for easier distinguishing.

Each of these object also often carry a dook::SourceInfo field to see where in the manifest file they are included.

struct SourceInfo

Holds debug info about a src file.

Used to hold which file and line pair a specific resource originates from.

enum dook::EntityType

Values:

enumerator STATE
enumerator COMMAND
enumerator LEVEL
enumerator CHARACTER
enumerator OBJECT
class Entity

Subclassed by dook::Command, dook::Level, dook::Object, dook::State

Public Functions

inline const SourceInfo &source_info() const

Location the entity parsed from.

Return the originating filename and line.

inline const EntityType &type() const

Get the type of the entity.

inline Entity(std::string name, EntityType type, SourceInfo source)

Construct a new Entity object.

Parameters:
  • name – Name of the entity.

  • source – Source file/call the entity. originates from.

  • type – Type of the entity.

Media files

Used by object and characters to hold multimedia info.

class Texture

Subclassed by dook::NullTexture, dook::SDLTexture

Public Functions

void animate()

Take a step in animation.

Loops back to texture resource.

void reset()

Reset the animation.

inline const std::optional<Rect> &draw_rectangle() const

Return currently active draw rectangle.

bool is_animation_completed() const

Check if animation step is the last one.

True if this is the final possible animation to draw.

Returns:

true If the draw rectangle touches the end of the texture.

Returns:

false otherwise.

class NullTexture : public dook::Texture

Empty texture object.

Noop texture class to use for null service providers or testing.

class Audio

Subclassed by dook::NullAudio

Public Functions

inline Audio(std::string file_name)

Construct a new Audio object.

Parameters:

file_name – Location of the audio file.

class NullAudio : public dook::Audio

Objects & Characters

Objects & Characters are the moving parts of the engine, they use the above Entities to interact with each other.

class State : public dook::Entity

Reperesents states used in the object state machines.

class Command : public dook::Entity

Reperesents state switching commands used for objects.

class Object : public dook::Entity

Subclassed by dook::Character

Public Functions

inline Object(std::string name, State base_state, State terminal_state, Position position, SourceInfo source)

Construct a new Object object.

Parameters:
  • name – Name of the object.

  • base_state – Base state of the object, initilizes as this and eventually reverts to this when, if, the time comes.

  • terminal_state – When reached, object is determined to be removable.

  • position – The location of the object in 2D space.

  • source – Information about the parsing source for this object.

inline Object(std::string name, State base_state, State terminal_state, Position position)

Construct a new Object object.

Parameters:
  • name – Name of the object.

  • base_state – Base state of the object, initilizes as this and eventually reverts to this when, if, the time comes.

  • terminal_state – When reached, object is determined

  • positionPosition of the object in 2D space. to be removable.

virtual bool execute(const Command &command)

Execute a command.

bool can_remove() const

Check if the object is in terminal state with completed anim.

const Texture &texture() const

Get the current texture of the object.

Texture &texture()

Get a modifiable reference to the current texture.

Returns:

Texture& texture reference.

const State &state() const

Get the current state of the object.

virtual void tick()

Perform a tick on an object.

void reset()

Reset the object to its initial state.

bool at_base_state()

Check if the object is at base state.

Returns:

true

Returns:

false

Position &position()

Get the object position.

Returns:

Position& Pass the object position by reference.

void set_texture_for_state(const State &state, std::unique_ptr<Texture> texture)

Set the texture for the given state.

Parameters:
  • stateObject state the texture will be active in.

  • textureTexture to be displayed when the object is active.

struct CharacterStates

Each character must have these states.

Define which concrete dook::State objects each character’s state is assigned to.

struct CharacterStats

Holds information about character behaviour and abilities.

Public Members

AIType behaviour

Determines AI behaviour.

float max_health

Max health this character can hae.

float health

Current character health.

float detection_range

Range in metres this character can detect other characters

float attack_range

Range at which the character can hurt other characters.

float attack

Amount of attack points, ie: when attacking the other character’s health is subtracted by this amount.

float health_recovery_per_tick

Amount of health points recovered per tick when the character have not been damaged for some ticks.

float speed

Walking speed of the character.

class Character : public dook::Object

Moving objects that interact with the player.

Template Parameters:
  • T – Type of their raw texture.

  • S – Type of their raw audio.

Public Functions

inline Character(std::string name, CharacterStats stats, CharacterStates states, Position position, SourceInfo source)

Construct a new Character object.

Parameters:
  • name – Name of the character.

  • base_state – Base state for the object, initilized and reverts to this state.

  • terminal_state – When reached, the character is deemed removable.

  • stats – Stats for character.

  • source – Information about the entity parse.

inline Character(std::string name, CharacterStats stats, CharacterStates states, Position position)

Construct a new Character object.

Parameters:
  • name – Name of the character.

  • base_state – Base state for the object, initilized and reverts to this state.

  • terminal_state – When reached, the character is deemed removable.

  • stats – Stats for character.

  • positionPosition of the character.

inline const CharacterStats &stats() const

Get a readonly reference to the stats object.

virtual void tick() override

Perform a tick on an object.

void hurt(float damage)

Hurt a character by applying damage.

Parameters:

damage – Damage to be applied to health.

Levels

Finally, levels tie all of these things together.

class Level : public dook::Entity

Contains information about a single level.

Public Functions

inline Level(std::string name, std::unique_ptr<Texture> background, std::unique_ptr<Texture> foreground, std::unique_ptr<Texture> passability, SourceInfo source)

Construct a new Level object.

Parameters:
  • nameEntity name of the level.

  • background – Background texture that will be rendered before the characters.

  • foreground – Foreground texture that will be rendered in front of the characters.

  • passability – Passability layer that decides which tiles are passable.

  • source – Information about source file.

inline Level(std::string name, std::unique_ptr<Texture> background, std::unique_ptr<Texture> foreground, std::unique_ptr<Texture> passability)

Construct a new Level object.

Parameters:
  • nameEntity name of the level.

  • background – Background texture that will be rendered before the characters.

  • foreground – Foreground texture that will be rendered in front of the characters.

  • passability – Passability layer that decides which tiles are passable.

void register_character(std::shared_ptr<Character> character)

Include a character in this level.

Parameters:

character

std::shared_ptr<Character> main_character()

Get the main character.

Character with ID 0 is the main character.

Returns:

std::shared_ptr<Character> The main character.

std::vector<std::shared_ptr<Object>> objects_within_region(const Rect &region)

Get the objects within the given region.

Parameters:

region – Region to get the objects within.

Returns:

A vector of shared pointers to objects that fall within the region.

void tick()

Let objects take their turns.