Velocity and Acceleration functions.
More...
Go to the source code of this file.
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
- Copyright
- Copyright (c) 2025
◆ Engine_applyMotion()
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
-
◆ 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()
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
-
- Returns
- A null-terminated array of sprites that are about to collide with the sprite, or
0
if none.
◆ Sprite_getAccelerationX()
Gets the X acceleration of a sprite.
- Parameters
-
- Returns
- The X acceleration of the sprite.
◆ Sprite_getAccelerationY()
Gets the Y acceleration of a sprite.
- Parameters
-
- Returns
- The Y acceleration of the sprite.
◆ Sprite_getMotion()
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
-
- Returns
- The motion array of the sprite, or
0
if the sprite has no motion array or an error occurred.
◆ Sprite_getVelocityX()
Gets the X velocity of a sprite.
- Parameters
-
- Returns
- The X velocity of the sprite.
◆ Sprite_getVelocityY()
Gets the Y velocity of a sprite.
- Parameters
-
- Returns
- The Y velocity of the sprite.
◆ Sprite_isAboutToCollide()
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
-
sprite1 | The sprite to use. |
sprite2 | The other sprite to check against. |
- Returns
- 1 if the sprite is about to collide with the other sprite, 0 if not.
◆ Sprite_resetAllMotion()
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
-
- 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
-
sprite | The sprite to use. |
acceleration | The 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
-
sprite | The sprite to use. |
acceleration | The 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
-
sprite | The sprite to use. |
velocity | The 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
-
sprite | The sprite to use. |
velocity | The Y velocity to set. |
- Returns
- 0 if successful, -1 if an error occurred.