redhand::Actor class

The Actor is the simple class used to diplay most things in redhand.

Constructors, destructors, conversion operators

Actor()
Construct a new Actor object with no image.
Actor(redhand::image_properties prop)
Construct a new Actor object with the supplied image.
Actor(std::filesystem::path img_location)
Construct a new Actor object with the supplied image.

Public functions

void act(game_loop_event evt) virtual
The act method is called by the world to give actors a chance to perform some action.
auto getX() -> float
This returns the x position of the Actor in the world.
auto getY() -> float
This returns the y position of the Actor in the world.
void setImage(std::shared_ptr<redhand::texture2D> img)
Set the Image of the Actor and automatically resizes accordingly.
void setImage(std::filesystem::path img)
Set the Image of the Actor and automatically resizes accordingly.
void setImage(redhand::image_properties img)
Set the Image of the Actor and automatically resizes accordingly.
void setActorScale(float scale)
scale the actor by the given factor
void scaleActor(float scale = 1.0f)
scale the Actor by the given factor
auto getActorScale() -> float
Get the scaling factor of the actor.
auto getSize() -> glm::vec2
Get the size of the Actor (width and height)
auto getImage() -> std::shared_ptr<redhand::texture2D>
Get the Image attached to the actor.
auto getRotation() -> float virtual
Get the Rotation of the actor in degrees.
auto getPosition() -> glm::vec2 virtual
Get the Position of the Actor.
auto getName() -> std::string_view
Get the Name of the Actor.
void move(float distance)
move the actor in the rotated direction by the specefied distance
void move(std::chrono::nanoseconds frameTime)
move the actor using the specified speed.
void move(glm::vec2 delta) virtual
move the actor by a given amount of units
void setSpeed(float speed)
Set the movement Speed of the Actor in units per seconds.
void turn(float delta)
Turn the actor by a given amount of degrees.
void turnTowards(glm::vec2 point)
Specify a point the actor should turn towards.
auto getHitbox() -> std::vector<glm::vec2> virtual
Get the Hitbox of the game_object.

Protected functions

void setPosition(glm::vec2 location) virtual
Set the Position of the actor to the given point.
void setName(std::string name) virtual
Set the Name of the Actor.
void setColorAlpha(float alpha) virtual
Set the alpha of this objects color.
void setRotaionAxis(glm::vec3)
This allows you to change tha axis objects rotate around.
void updateBufferData(std::vector<glm::vec2> points, std::vector<std::array<unsigned int, 3>> indicies, std::vector<glm::vec3> colors)
push new data into the opengl buffers

Private functions

void onLoop(game_loop_event evt) override
This is the onLoop function just calls act and is needed by the complexWorld for the gameLoopEvent.

Function documentation

void redhand::Actor::act(game_loop_event evt) virtual

The act method is called by the world to give actors a chance to perform some action.

Parameters
evt This is the event, that holds a pointer to the engine and the time difference from the last call

float redhand::Actor::getX()

This returns the x position of the Actor in the world.

Returns float The x position

float redhand::Actor::getY()

This returns the y position of the Actor in the world.

Returns float The y position

void redhand::Actor::setImage(std::shared_ptr<redhand::texture2D> img)

Set the Image of the Actor and automatically resizes accordingly.

Parameters
img The image that the Actor will now own

void redhand::Actor::setImage(std::filesystem::path img)

Set the Image of the Actor and automatically resizes accordingly.

Parameters
img The location of the image the actor will use now

void redhand::Actor::setImage(redhand::image_properties img)

Set the Image of the Actor and automatically resizes accordingly.

Parameters
img The location of the image the actor will use now

void redhand::Actor::setActorScale(float scale)

scale the actor by the given factor

Parameters
scale the scale the actor shuld have now

void redhand::Actor::scaleActor(float scale = 1.0f)

scale the Actor by the given factor

Parameters
scale the factor the actor will be scaled with

float redhand::Actor::getActorScale()

Get the scaling factor of the actor.

Returns float the scale of the actor

glm::vec2 redhand::Actor::getSize()

Get the size of the Actor (width and height)

Returns glm::vec2 the dimensions of the Actor

std::shared_ptr<redhand::texture2D> redhand::Actor::getImage()

Get the Image attached to the actor.

Returns std::shared_ptr<redhand::texture2D> the image attached to the actor

float redhand::Actor::getRotation() virtual

Get the Rotation of the actor in degrees.

Returns float the rotation in degrees

glm::vec2 redhand::Actor::getPosition() virtual

Get the Position of the Actor.

Returns glm::vec2 The position in the world

std::string_view redhand::Actor::getName()

Get the Name of the Actor.

Returns std::string the name of the actor

void redhand::Actor::move(float distance)

move the actor in the rotated direction by the specefied distance

Parameters
distance The distance the actor should move

void redhand::Actor::move(std::chrono::nanoseconds frameTime)

move the actor using the specified speed.

Parameters
frameTime The time difference between the function calls

This function is supposed to be called in the act function by supplying evt.getFrameTime() as parameter to this function.

void redhand::Actor::move(glm::vec2 delta) virtual

move the actor by a given amount of units

Parameters
delta the units the actor should move

void redhand::Actor::setSpeed(float speed)

Set the movement Speed of the Actor in units per seconds.

Parameters
speed the speed in units per second

void redhand::Actor::turn(float delta)

Turn the actor by a given amount of degrees.

Parameters
delta how much degrees the actor should rotate

void redhand::Actor::turnTowards(glm::vec2 point)

Specify a point the actor should turn towards.

Parameters
point the point the actor should look at

std::vector<glm::vec2> redhand::Actor::getHitbox() virtual

Get the Hitbox of the game_object.

Returns std::vector<glm::vec2> the hitbox of the game_object.

void redhand::Actor::setPosition(glm::vec2 location) virtual protected

Set the Position of the actor to the given point.

Parameters
location the new position of the actor

void redhand::Actor::setName(std::string name) virtual protected

Set the Name of the Actor.

Parameters
name THe name the aactor should have

void redhand::Actor::setColorAlpha(float alpha) virtual protected

Set the alpha of this objects color.

Parameters
alpha value of this objects color

void redhand::Actor::updateBufferData(std::vector<glm::vec2> points, std::vector<std::array<unsigned int, 3>> indicies, std::vector<glm::vec3> colors) protected

push new data into the opengl buffers

Parameters
points the new set of points used to describe triangles
indicies the indixes that each form a single triangle
colors the colors each of the points should have (size must be 0 or size of points)

void redhand::Actor::onLoop(game_loop_event evt) override private

This is the onLoop function just calls act and is needed by the complexWorld for the gameLoopEvent.

Parameters
evt The game_loop_event containing a pointer to the engine and a time difference