cmdfx 0.2.1
Lightweight game engine for your terminal
Loading...
Searching...
No Matches
CmdFX::SpriteMotion Class Referencefinal

A C++ wrapper around a CmdFX_Sprite struct for motion-related functions. More...

#include <motion.hpp>

Public Member Functions

 SpriteMotion (std::unique_ptr< Sprite > sprite)
 
 SpriteMotion (CmdFX_Sprite *sprite)
 
std::vector< double > getMotion ()
 Gets the motion array of a sprite as a vector.
 
double getVelocityX ()
 
int setVelocityX (double velocity)
 
double getVelocityY ()
 
int setVelocityY (double velocity)
 
double getAccelerationX ()
 
int setAccelerationX (double acceleration)
 
double getAccelerationY ()
 
int setAccelerationY (double acceleration)
 
bool isAboutToCollide (Sprite &sprite2)
 
bool isAboutToCollide (std::unique_ptr< Sprite > sprite2)
 
std::vector< std::unique_ptr< Sprite > > getAboutToCollideSprites ()
 
int resetAllMotion ()
 

Detailed Description

A C++ wrapper around a CmdFX_Sprite struct for motion-related functions.

This class provides methods to get and set the velocity and acceleration of a sprite, check for potential collisions, and reset the motion of a sprite. The destructor will reset all motion when the object is destroyed.

Member Function Documentation

◆ getMotion()

std::vector< double > CmdFX::SpriteMotion::getMotion ( )
inline

Gets the motion array of a sprite as a vector.

The motion array is the internal array that stores the velocity and acceleration of a sprite. The motion array is a 4-element array, where the elements are:

  • 0: X velocity
  • 1: Y velocity
  • 2: X acceleration
  • 3: Y acceleration

The motion array is used by the physics engine to calculate the motion of a sprite. The array is freed from Sprite_resetAllMotion and Sprite_free, so it should not be freed manually.

Parameters
spriteThe sprite to use.
Returns
A vector containing the motion values, or an empty vector if the sprite has no motion array or an error occurred.

The documentation for this class was generated from the following file: