File actor.hpp

Defines

RPGPP_MAX_DIRECTION

Typedefs

using json = nlohmann::json

Enums

enum Direction

Direction enum, representing an animation state.

Values:

enumerator RPGPP_DOWN_IDLE

Down Idle state.

enumerator RPGPP_DOWN

Down state.

enumerator RPGPP_UP_IDLE

Up Idle state.

enumerator RPGPP_UP

Up state.

enumerator RPGPP_LEFT_IDLE

Left Idle state.

enumerator RPGPP_LEFT

Left state.

enumerator RPGPP_RIGHT_IDLE

Right Idle state.

enumerator RPGPP_RIGHT

Right state.

Functions

Vector2 calcActorTilePos(Vector2 newPosition, Vector2 worldTileSize, TileSet *tileSet)
class Actor : public ISaveable
#include <actor.hpp>

The Actor class represents an Actor in the game’s world.

See also

Direction

Public Functions

Actor() = default

Empty constructor.

Actor(const std::string &fileName)

Constructor that takes a path to the .ractor file.

Actor(std::unique_ptr<TileSet> tileSet, Vector2 atlasPos, std::string tileSetSource)

Constructor that takes a TileSet, the atlas position of the tile to use, and the path to the TileSet.

Actor(const ActorBin &bin)

Constructor that takes an ActorBin binary structure

virtual json dumpJson() override

Dump this Actor’s data to a nlohmann::json object.

void unload() const

Unload routine. The UnloadTexture function will called here.

void update()

Update routine.

void draw() const

Draw routine.

std::string getSourcePath() const

Get the source file’s path for this Actor.

Vector2 getPosition() const

Get this actor’s position in the world.

void setPosition(Vector2 newPosition)

Set this Actor’s position.

void setTilePosition(Vector2 newPosition, Vector2 tileSize)

Set Actor position relative to a tile in the world.

Vector2 getTilePosition() const

Get this Actor’s tile position.

void moveByVelocity(Vector2 velocity)

Move the Actor using a velocity vector.

Rectangle getRect() const

Get the bounding box of this Actor.

TileSet &getTileSet() const

Get a reference to this Actor’s TileSet.

int getCurrentFrame() const

Get the current frame of this actor.

inline void resetAnimation()

Reset the animation back to frame 0.

Direction getAnimationDirection() const

Get the current direction of this actor.

Vector2 getCurrentAnimationAtlas() const

Get the current animation atlas of this actor.

Rectangle getCurrentAnimationRectangle() const

Get the current animation rectangle of this actor.

Vector2 getAnimationAtlasByIdx(int frameIndex) const

Get an atlas of this actor by frame index.

void setAnimationFrame(int frameIndex)

Set the current frame.

int getAnimationCount() const

Get the current size of the animation in the direction.

void setTileSet(const std::string &newTileSetSource)

Set this Actor’s TileSet using a path to the tileset file.

Rectangle getCollisionRect(Vector2 velocity) const

Get the collision rectangle of this Actor if it was moved by the velocity vector

Rectangle getCollisionRect() const

Get the collision Rectangle of this Actor

Vector2 getCollisionCenter() const

Get collision center point.

void addAnimationFrame(Direction id, Vector2 atlasPos)

Add a frame in the chosen animation. The frame represents an atlas tile from this Actor’s TileSet.

void removeAnimationFrame(Direction id, int frameIndex)

Remove a frame in the chosen animation, specified by an index.

void setAnimationFrame(Direction id, int frameIndex, Vector2 atlasTile)

Change a frame in the chosen animation to another atlas tile from the TileSet.

void addAnimationFrames(Direction id, const std::vector<std::vector<int>> &frames)

Add multiple frames to the chosen animation.

void playAnimation(Direction id)

Temporarily play an animation

bool isTempAnimationPlaying()

Check whether a temporary animation is playing

void changeAnimation(Direction id)

Change the Actor’s current animation and play it.

std::string getTileSetSource() const

Get the path of the used TileSet.

std::array<std::vector<Vector2>, 8> getAnimationsRaw() const

Get an array of this Actor’s animations

std::vector<Vector2> getAnimationRaw(Direction id) const

Get a specific animation

void setCollisionRect(Rectangle rect)

Set the Actor’s collision Rectangle

bool hasInteractable()

Whether this Actor has an Interactable.

void setHasInteractable(bool value)

Set the ‘ownsInteractable’ flag.

Interactable *getInteractable()

Get a pointer to this Actor’s Interactable.

void setInteractableFromPath(const std::string &interPath)

Add an Interactable using an interactable file.

Public Members

std::function<void(int)> onFrameChanged

The callback when the current frame changes.

Private Members

std::string sourcePath
std::unique_ptr<TileSet> tileSet

The used TileSet for this Actor’s sprites.

std::string tileSetSource

The path to the TileSet file.

AtlasTile tile

The currently shown tile from the TileSet.

Vector2 position = {}

Current position in the world of this Actor.

Vector2 tilePosition = {}

Current tile position of this Actor if such is set.

int frameCounter = {}
int frameSpeed = {}
int currentFrame = {}
Rectangle collisionRect = {}

Rectangle, representing the collision of this Actor.

std::array<std::vector<Vector2>, 8> animations

An array of the animations. Each std::vector<Vector2> represents the frames of an animation.

Direction currentAnimation

A Direction enum, showing the current animation that is being played.

Direction lastAnimation
bool tempAnimIsPlayed = false
bool ownsInteractable = false

Whether this Actor has an Interactable.

std::unique_ptr<Interactable> interactable

A smart pointer, owning an Interactable.