cmdfx 0.2.0
Lightweight game engine for your terminal
Loading...
Searching...
No Matches
motion.h File Reference

Velocity and Acceleration functions. More...

Go to the source code of this file.

Functions

double * Sprite_getMotion (CmdFX_Sprite *sprite)
 Gets the motion array of a sprite.
 
double Sprite_getVelocityX (CmdFX_Sprite *sprite)
 Gets the X velocity of a sprite.
 
int Sprite_setVelocityX (CmdFX_Sprite *sprite, double velocity)
 Sets the X velocity of a sprite.
 
double Sprite_getVelocityY (CmdFX_Sprite *sprite)
 Gets the Y velocity of a sprite.
 
int Sprite_setVelocityY (CmdFX_Sprite *sprite, double velocity)
 Sets the Y velocity of a sprite.
 
double Sprite_getAccelerationX (CmdFX_Sprite *sprite)
 Gets the X acceleration of a sprite.
 
int Sprite_setAccelerationX (CmdFX_Sprite *sprite, double acceleration)
 Sets the X acceleration of a sprite.
 
double Sprite_getAccelerationY (CmdFX_Sprite *sprite)
 Gets the Y acceleration of a sprite.
 
int Sprite_setAccelerationY (CmdFX_Sprite *sprite, double acceleration)
 Sets the Y acceleration of a sprite.
 
int Sprite_isAboutToCollide (CmdFX_Sprite *sprite1, CmdFX_Sprite *sprite2)
 Whether a sprite is about to collide with another sprite.
 
CmdFX_Sprite ** Sprite_getAboutToCollideSprites (CmdFX_Sprite *sprite)
 Gets all of the sprites the sprite is about to collide with.
 
int Sprite_resetAllMotion (CmdFX_Sprite *sprite)
 Resets all motion of a sprite.
 
int Engine_isMotionDebugEnabled ()
 Whether motion debugging is enabled.
 
void Engine_enableMotionDebug ()
 Enables motion debugging.
 
void Engine_disableMotionDebug ()
 Disables motion debugging.
 
void Engine_applyMotion (CmdFX_Sprite *sprite)
 Applies the motion of a sprite.
 

Detailed Description

Velocity and Acceleration functions.

Author
Gregory Mitchell (me@gm.nosp@m.itch.nosp@m.215.x.nosp@m.yz)
Version
0.1.4
Date
2025-04-01

Function Documentation

◆ Engine_applyMotion()

void Engine_applyMotion ( CmdFX_Sprite * sprite)

Applies the motion of a sprite.

This method applies the motion of a sprite by updating its position based on its velocity and acceleration. The motion is applied in the opposite direction of the Y axis, so the sprite will move up when the Y velocity is positive and down when the Y velocity is negative.

Parameters
spriteThe sprite to use.

◆ Engine_disableMotionDebug()

void Engine_disableMotionDebug ( )

Disables motion debugging.

This method disables motion debugging, which will stop printing all sprite motion updates to the console.

Returns
0 if successful, -1 if an error occurred.

◆ Engine_enableMotionDebug()

void Engine_enableMotionDebug ( )

Enables motion debugging.

This method enables motion debugging, which will print all sprite motion updates to the console at (3, <sprite id + 1>).

Returns
0 if successful, -1 if an error occurred.

◆ Engine_isMotionDebugEnabled()

int Engine_isMotionDebugEnabled ( )

Whether motion debugging is enabled.

If motion debugging is enabled, the physics engine will print all sprite motion updates to the console at (3, <sprite id + 1>).

Returns
1 if motion debugging is enabled, 0 if motion debugging is disabled.

◆ Sprite_getAboutToCollideSprites()

CmdFX_Sprite ** Sprite_getAboutToCollideSprites ( CmdFX_Sprite * sprite)

Gets all of the sprites the sprite is about to collide with.

This array gets all of the sprites this sprite is about to collide with based on its velocity and acceleration. It will include all sprites in Sprite_getCollidingSprites that are not static.

Parameters
spriteThe sprite to use.
Returns
A null-terminated array of sprites that are about to collide with the sprite, or 0 if none.

◆ Sprite_getAccelerationX()

double Sprite_getAccelerationX ( CmdFX_Sprite * sprite)

Gets the X acceleration of a sprite.

Parameters
spriteThe sprite to use.
Returns
The X acceleration of the sprite.

◆ Sprite_getAccelerationY()

double Sprite_getAccelerationY ( CmdFX_Sprite * sprite)

Gets the Y acceleration of a sprite.

Parameters
spriteThe sprite to use.
Returns
The Y acceleration of the sprite.

◆ Sprite_getMotion()

double * Sprite_getMotion ( CmdFX_Sprite * sprite)

Gets the motion array of a sprite.

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
The motion array of the sprite, or 0 if the sprite has no motion array or an error occurred.

◆ Sprite_getVelocityX()

double Sprite_getVelocityX ( CmdFX_Sprite * sprite)

Gets the X velocity of a sprite.

Parameters
spriteThe sprite to use.
Returns
The X velocity of the sprite.

◆ Sprite_getVelocityY()

double Sprite_getVelocityY ( CmdFX_Sprite * sprite)

Gets the Y velocity of a sprite.

Parameters
spriteThe sprite to use.
Returns
The Y velocity of the sprite.

◆ Sprite_isAboutToCollide()

int Sprite_isAboutToCollide ( CmdFX_Sprite * sprite1,
CmdFX_Sprite * sprite2 )

Whether a sprite is about to collide with another sprite.

This method checks if the sprite is about to collide with another sprite based on its velocity and acceleration.

Parameters
sprite1The sprite to use.
sprite2The other sprite to check against.
Returns
1 if the sprite is about to collide with the other sprite, 0 if not.

◆ Sprite_resetAllMotion()

int Sprite_resetAllMotion ( CmdFX_Sprite * sprite)

Resets all motion of a sprite.

This method resets all motion of a sprite, including its velocity and acceleration. The sprite will be set to its default state, with no motion applied.

Parameters
spriteThe sprite to use.
Returns
0 if successful, -1 if an error occurred.

◆ Sprite_setAccelerationX()

int Sprite_setAccelerationX ( CmdFX_Sprite * sprite,
double acceleration )

Sets the X acceleration of a sprite.

Parameters
spriteThe sprite to use.
accelerationThe X acceleration to set.
Returns
0 if successful, -1 if an error occurred.

◆ Sprite_setAccelerationY()

int Sprite_setAccelerationY ( CmdFX_Sprite * sprite,
double acceleration )

Sets the Y acceleration of a sprite.

Parameters
spriteThe sprite to use.
accelerationThe Y acceleration to set.
Returns
0 if successful, -1 if an error occurred.

◆ Sprite_setVelocityX()

int Sprite_setVelocityX ( CmdFX_Sprite * sprite,
double velocity )

Sets the X velocity of a sprite.

Parameters
spriteThe sprite to use.
velocityThe X velocity to set.
Returns
0 if successful, -1 if an error occurred.

◆ Sprite_setVelocityY()

int Sprite_setVelocityY ( CmdFX_Sprite * sprite,
double velocity )

Sets the Y velocity of a sprite.

Parameters
spriteThe sprite to use.
velocityThe Y velocity to set.
Returns
0 if successful, -1 if an error occurred.