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

Global physics engine declarations. More...

Go to the source code of this file.

Functions

int Sprite_isStatic (CmdFX_Sprite *sprite)
 Gets whether this sprite is static.
 
int Sprite_setStatic (CmdFX_Sprite *sprite, int isStatic)
 Sets whether this sprite is static.
 
int Engine_getForceOfGravity ()
 Gets the force of gravity, in characters per second squared.
 
int Engine_setForceOfGravity (int force)
 Sets the force of gravity, in characters per second squared.
 
int Engine_getTerminalVelocity ()
 Gets the terminal velocity, in characters per second.
 
int Engine_setTerminalVelocity (int velocity)
 Sets the terminal velocity, in characters per second.
 
int Engine_getGroundY ()
 Gets the Y level of the ground for the physics engine.
 
int Engine_setGroundY (int y)
 Sets the Y level of the ground for the physics engine.
 
double Engine_getDefaultFrictionCoefficient ()
 Gets the default friction coefficient for a sprite.
 
int Engine_setDefaultFrictionCoefficient (double coefficient)
 Sets the default friction coefficient for a sprite.
 
int Engine_getCharacterMass (char c)
 Gets the default mass of a character.
 
int Engine_setCharacterMass (char c, int mass)
 Sets the default mass of a character.
 
int Engine_start ()
 Starts up the physics engine.
 
void Engine_tick ()
 Ticks the physics engine.
 
int Engine_cleanup ()
 Cleans up the physics engine.
 
int Engine_end ()
 Stops the physics engine.
 

Detailed Description

Global physics engine 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

◆ Engine_cleanup()

int Engine_cleanup ( )

Cleans up the physics engine.

This is different from Engine_end, in that it claens up any loose variables before stopping the engine. This is automatically called by Engine_end and is not intended to be called independently to avoid undefined behavior.

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

◆ Engine_end()

int Engine_end ( )

Stops the physics engine.

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

◆ Engine_getCharacterMass()

int Engine_getCharacterMass ( char c)

Gets the default mass of a character.

The mass of a sprite is calculated by the number of non-whitespace characters in a sprite map. ANSI codes have no effect on the mass of a character.

You can modify the output value of Sprite_getDefaultMass by changing the default mass of a character. Every character by default has a mass of 1.

Returns
The default mass of a character.

◆ Engine_getDefaultFrictionCoefficient()

double Engine_getDefaultFrictionCoefficient ( )

Gets the default friction coefficient for a sprite.

The default friction coefficient is a value between 0 and 1 that determines how much friction is applied to a sprite. A value of 0 means no friction, while a value of 1 means full friction, meaning it will stop immediately.

The default value is 0.25.

Returns
The default friction coefficient.

◆ Engine_getForceOfGravity()

int Engine_getForceOfGravity ( )

Gets the force of gravity, in characters per second squared.

This method returns the force of gravity, in characters per second squared. The default value is 1 c/s^2.

Returns
The force of gravity, in c/s^2.

◆ Engine_getGroundY()

int Engine_getGroundY ( )

Gets the Y level of the ground for the physics engine.

The default value is the canvas height. The Y level of the ground helps determine when a sprite has landed on the ground.

Returns
The Y level of the ground.

◆ Engine_getTerminalVelocity()

int Engine_getTerminalVelocity ( )

Gets the terminal velocity, in characters per second.

This method returns the terminal velocity, in characters per second. The default value is 10 c/s.

Returns
The terminal velocity, in c/s.

◆ Engine_setCharacterMass()

int Engine_setCharacterMass ( char c,
int mass )

Sets the default mass of a character.

The mass of a sprite is calculated by the number of non-whitespace characters in a sprite map. ANSI codes have no effect on the mass of a character.

You can modify the output value of Sprite_getDefaultMass by changing the default mass of a character. Every character by default has a mass of 1.

Parameters
cThe character to set the mass of.
massThe default mass of the character.
Returns
0 if successful, -1 if an error occured.

◆ Engine_setDefaultFrictionCoefficient()

int Engine_setDefaultFrictionCoefficient ( double coefficient)

Sets the default friction coefficient for a sprite.

The default friction coefficient is a value between 0 and 1 that determines how much friction is applied to a sprite. A value of 0 means no friction, while a value of 1 means full friction, meaning it will stop immediately.

The default value is 0.25.

Parameters
coefficientThe default friction coefficient.
Returns
0 if successful, -1 if an error occured.

◆ Engine_setForceOfGravity()

int Engine_setForceOfGravity ( int force)

Sets the force of gravity, in characters per second squared.

This method sets the force of gravity, in characters per second squared. The default value is 1 c/s^2.

Parameters
forceThe force of gravity, in c/s^2.
Returns
0 if successful, -1 if an error occurred.

◆ Engine_setGroundY()

int Engine_setGroundY ( int y)

Sets the Y level of the ground for the physics engine.

The default value is the canvas height. The Y level of the ground helps determine when a sprite has landed on the ground.

Parameters
yThe Y level of the ground.
Returns
0 if successful, -1 if an error occurred.

◆ Engine_setTerminalVelocity()

int Engine_setTerminalVelocity ( int velocity)

Sets the terminal velocity, in characters per second.

This method sets the terminal velocity, in characters per second. The default value is 10 c/s.

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

◆ Engine_start()

int Engine_start ( )

Starts up the physics engine.

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

◆ Engine_tick()

void Engine_tick ( )

Ticks the physics engine.

This method ticks the physcis engine, if it is running. This is automatically called once per frame.

◆ Sprite_isStatic()

int Sprite_isStatic ( CmdFX_Sprite * sprite)

Gets whether this sprite is static.

A sprite is static if it is not affected by the physics engine.

Parameters
spriteThe sprite to check.
Returns
1 if the sprite is static, 0 otherwise.

◆ Sprite_setStatic()

int Sprite_setStatic ( CmdFX_Sprite * sprite,
int isStatic )

Sets whether this sprite is static.

A sprite is static if it is not affected by the physics engine. Use this method to set whether a sprite is static or not.

Parameters
spriteThe sprite to modify.
isStatic1 if the sprite is static, 0 otherwise.
Returns
0 if successful, -1 if an error occurred.