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

Force-related physics declarations. More...

Go to the source code of this file.

Functions

CmdFX_Vector ** Sprite_getAllForces (CmdFX_Sprite *sprite)
 Gets all of the forces acting on a sprite.
 
int Sprite_getAllForcesCount (CmdFX_Sprite *sprite)
 Gets the number of forces acting on a sprite.
 
CmdFX_VectorSprite_getNetForce (CmdFX_Sprite *sprite)
 Gets the net force acting on a sprite.
 
int Sprite_addForce (CmdFX_Sprite *sprite, CmdFX_Vector *force)
 Adds a force to a sprite.
 
int Sprite_removeForce (CmdFX_Sprite *sprite, CmdFX_Vector *force)
 Removes a force from a sprite.
 
int Sprite_removeAllForces (CmdFX_Sprite *sprite)
 Removes all forces from a sprite.
 
int Sprite_clearAllForces ()
 Removes all forces for every sprite and frees the array.
 
double Sprite_getFrictionCoefficient (CmdFX_Sprite *sprite)
 Gets the friction coefficient of a sprite.
 
int Sprite_setFrictionCoefficient (CmdFX_Sprite *sprite, double coefficient)
 Sets the friction coefficient of a sprite.
 
int Sprite_resetFrictionCoefficient (CmdFX_Sprite *sprite)
 Resets the friction coefficient of a sprite.
 
int Sprite_addForceFor (CmdFX_Sprite *sprite, CmdFX_Vector *force, int duration)
 Adds a temporary force to a sprite.
 

Detailed Description

Force-related physics declarations.

Author
Gregory Mitchell (me@gm.nosp@m.itch.nosp@m.215.x.nosp@m.yz)
Version
0.1.1
Date
2025-02-09

Function Documentation

◆ Sprite_addForce()

int Sprite_addForce ( CmdFX_Sprite * sprite,
CmdFX_Vector * force )

Adds a force to a sprite.

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

◆ Sprite_addForceFor()

int Sprite_addForceFor ( CmdFX_Sprite * sprite,
CmdFX_Vector * force,
int duration )

Adds a temporary force to a sprite.

Parameters
spriteThe sprite to use.
forceThe force to add.
durationThe duration of the force, in milliseconds.
Returns
0 if successful, -1 if an error occurred.

◆ Sprite_clearAllForces()

int Sprite_clearAllForces ( )

Removes all forces for every sprite and frees the array.

This will free all forces in the sprite's force array, and then free the array itself.

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

◆ Sprite_getAllForces()

CmdFX_Vector ** Sprite_getAllForces ( CmdFX_Sprite * sprite)

Gets all of the forces acting on a sprite.

Parameters
spriteThe sprite to use.
Returns
The forces acting on the sprite as a vector array.

◆ Sprite_getAllForcesCount()

int Sprite_getAllForcesCount ( CmdFX_Sprite * sprite)

Gets the number of forces acting on a sprite.

Parameters
spriteThe sprite to use.
Returns
The number of forces acting on the sprite.

◆ Sprite_getFrictionCoefficient()

double Sprite_getFrictionCoefficient ( CmdFX_Sprite * sprite)

Gets the friction coefficient of a sprite.

The friction coefficient is a value between 0 and 1 that determines how much a sprite will slow down when moving on the ground.

If the sprite does not have a custom friction coefficient, the default value of Engine_getDefaultFrictionCoefficient will be returned.

Parameters
spriteThe sprite to use.
Returns
The friction coefficient of the sprite.

◆ Sprite_getNetForce()

CmdFX_Vector * Sprite_getNetForce ( CmdFX_Sprite * sprite)

Gets the net force acting on a sprite.

This creates a new vector that is the sum of all the forces acting on the sprite. The vector should be freed after use.

Parameters
spriteThe sprite to use.
Returns
The net force acting on the sprite.

◆ Sprite_removeAllForces()

int Sprite_removeAllForces ( CmdFX_Sprite * sprite)

Removes all forces from a sprite.

Removing all forces will free all forces in the sprite's force array, and then free the array itself.

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

◆ Sprite_removeForce()

int Sprite_removeForce ( CmdFX_Sprite * sprite,
CmdFX_Vector * force )

Removes a force from a sprite.

The force will be removed if it is found in the sprite's force array and will not be freed.

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

◆ Sprite_resetFrictionCoefficient()

int Sprite_resetFrictionCoefficient ( CmdFX_Sprite * sprite)

Resets the friction coefficient of a sprite.

The friction coefficient will be reset to the default value.

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

◆ Sprite_setFrictionCoefficient()

int Sprite_setFrictionCoefficient ( CmdFX_Sprite * sprite,
double coefficient )

Sets the friction coefficient of a sprite.

The friction coefficient is a value between 0 and 1 that determines how much a sprite will slow down when moving on the ground.

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