Entity handler include header. More...

#include <SDL.h>
#include "AABB.h"
#include "Constants.h"
Include dependency graph for Entity.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Bullet_t
 Bullet handle data. More...
 
struct  Camera_t
 Camera handle data. More...
 
struct  Entity_t
 Entity handle data. More...
 
struct  Sprite_t
 Sprite handle data. More...
 

Typedefs

typedef struct Bullet_t Bullet
 Bullet handle type.
 
typedef struct Camera_t Camera
 Camera handle type.
 
typedef struct Entity_t Entity
 Entity handle type.
 
typedef struct Sprite_t Sprite
 Sprite handle type.
 

Functions

void Entity_Animate (SDL_bool bAnimate, Entity *pstEntity)
 Animate entity. More...
 
void Entity_ConnectHorizontalMapEnds (const Uint16 u16MapWidth, Entity *pstEntity)
 Connect horizontal map ends for entity. More...
 
void Entity_ConnectMapEnds (const Uint16 u16MapWidth, const Uint16 u16MapHeight, Entity *pstEntity)
 Connect all map ends for entity. More...
 
void Entity_ConnectVerticalMapEnds (const Uint16 u16MapHeight, Entity *pstEntity)
 Connect vertical map ends for entity. More...
 
int Entity_Draw (const Entity *pstEntity, const Camera *pstCamera, const Sprite *pstSprite, SDL_Renderer *pstRenderer)
 Draw entity. More...
 
void Entity_Drop (Entity *pstEntity)
 Drop entity. More...
 
void Entity_Free (Entity *pstEntity)
 Free entity. More...
 
void Entity_FreeCamera (Camera *pstCamera)
 Free camera. More...
 
void Entity_FreeSprite (Sprite *pstSprite)
 Free Sprite. More...
 
int Entity_Init (const double dPosX, const double dPosY, const Uint16 u16Width, const Uint16 u16Height, Entity **pstEntity)
 Initialise entity. More...
 
int Entity_InitCamera (Camera **pstCamera)
 Initialise camera. More...
 
int Entity_InitSprite (const char *pacFileName, const Uint16 u16Width, const Uint16 u16Height, const Uint16 u16ImageOffsetX, const Uint16 u16ImageOffsetY, Sprite **pstSprite, SDL_Renderer *pstRenderer)
 Initialise sprite. More...
 
SDL_bool Entity_IsCameraLocked (const Camera *pstCamera)
 Check if camera is locked. More...
 
SDL_bool Entity_IsMoving (const Entity *pstEntity)
 Check if entity is moving. More...
 
SDL_bool Entity_IsRising (const Entity *pstEntity)
 Check if a entity is rising. More...
 
void Entity_Jump (const double dForce, Entity *pstEntity)
 Jump with entity. More...
 
void Entity_LockCamera (Camera *pstCamera)
 Lock camera. More...
 
void Entity_Move (Entity *pstEntity)
 Set entity in motion. More...
 
void Entity_MoveFull (const Direction bOrientation, const double dAcceleration, const double dMaxVelocityX, const Uint8 u8AnimStart, const Uint8 u8AnimEnd, const double dAnimSpeed, const Uint8 u8FrameOffsetY, Entity *pstEntity)
 Move entity with parameters. More...
 
void Entity_Reset (Entity *pstEntity)
 Reset entity flags. More...
 
void Entity_ResetToSpawnPosition (Entity *pstEntity)
 Reset to spawn position. More...
 
int Entity_SetCameraBoundariesToMapSize (const Sint32 s32LogicalWindowWidth, const Sint32 s32LogicalWindowHeight, const Uint16 u16MapWidth, const Uint16 u16MapHeight, Camera *pstCamera)
 Set camera boundaries to map size. More...
 
void Entity_SetCameraTarget (const Sint32 s32LogicalWindowWidth, const Sint32 s32LogicalWindowHeight, const Entity *pstEntity, Camera *pstCamera)
 Set camera target. More...
 
void Entity_SetAnimation (const Uint8 u8AnimStart, const Uint8 u8AnimEnd, const double dAnimSpeed, Entity *pstEntity)
 Set animation for entity. More...
 
void Entity_SetDirection (const Direction eDirection, Entity *pstEntity)
 Set entity direction. More...
 
void Entity_SetFrameOffset (const Uint8 u8OffsetX, const Uint8 u8OffsetY, Entity *pstEntity)
 Set frame offset. More...
 
void Entity_SetPosition (const double dPosX, const double dPosY, Entity *pstEntity)
 Set entity position. More...
 
void Entity_SetSpawnPosition (const double dPosX, const double dPosY, Entity *pstEntity)
 Set entity spawn position. More...
 
void Entity_SetSpeed (const double dAcceleration, const double dMaxVelocityX, Entity *pstEntity)
 Set entity speed. More...
 
void Entity_Stop (Entity *pstEntity)
 Stop entity. More...
 
void Entity_UnlockCamera (Camera *pstCamera)
 Unlock camera. More...
 
void Entity_Update (const double dDeltaTime, const double dGravitation, const Uint8 u8MeterInPixel, Entity *pstEntity)
 Update entity. More...
 

Detailed Description

Entity handler include header.

Function Documentation

◆ Entity_Animate()

void Entity_Animate ( SDL_bool  bAnimate,
Entity pstEntity 
)

Animate entity.

Sets or clears the entity's IS_ANIMATED flag

Parameters
bAnimateSDL_FALSE = Do not animate, SDL_TRUE = Animate
pstEntityPointer to entity handle
Here is the call graph for this function:

◆ Entity_ConnectHorizontalMapEnds()

void Entity_ConnectHorizontalMapEnds ( const Uint16  u16MapWidth,
Entity pstEntity 
)

Connect horizontal map ends for entity.

Connects the horizontal map ends for an entity so it can travel from one side to the other by leaving the map

Parameters
u16MapWidthMap width
pstEntityPointer to entity handle
Here is the caller graph for this function:

◆ Entity_ConnectMapEnds()

void Entity_ConnectMapEnds ( const Uint16  u16MapWidth,
const Uint16  u16MapHeight,
Entity pstEntity 
)

Connect all map ends for entity.

Connects horizontal and vertical map ends for an entity so it can travel from one side to the other by leaving the map

Parameters
u16MapWidthMap width
u16MapHeightMap height
pstEntityPointer to entity handle
Here is the call graph for this function:

◆ Entity_ConnectVerticalMapEnds()

void Entity_ConnectVerticalMapEnds ( const Uint16  u16MapHeight,
Entity pstEntity 
)

Connect vertical map ends for entity.

Connects the vertical map ends for an entity so it can travel from one side to the other by leaving the map

Parameters
u16MapHeightMap height
pstEntityPointer to entity handle
Here is the caller graph for this function:

◆ Entity_Draw()

int Entity_Draw ( const Entity pstEntity,
const Camera pstCamera,
const Sprite pstSprite,
SDL_Renderer *  pstRenderer 
)

Draw entity.

Draws an entity on screen

Parameters
pstEntityPointer to entity handle
pstCameraPointer to camera handle
pstSpritePointer to sprite handle
pstRendererPointer to SDL2 rendering context
Returns
Error code
Return values
0OK
-1Error

◆ Entity_Drop()

void Entity_Drop ( Entity pstEntity)

Drop entity.

Sets the entity's IS_IN_MID_AIR flag

Parameters
pstEntityPointer to entity handle
Here is the call graph for this function:

◆ Entity_Free()

void Entity_Free ( Entity pstEntity)

Free entity.

Frees up allocated memory and unloads entity

Parameters
pstEntityPointer to entity handle

◆ Entity_FreeCamera()

void Entity_FreeCamera ( Camera pstCamera)

Free camera.

Frees up allocated memory and unloads camera

Parameters
pstCameraPointer to camera handle

◆ Entity_FreeSprite()

void Entity_FreeSprite ( Sprite pstSprite)

Free Sprite.

Frees up allocated memory and unloads sprite

Parameters
pstSpritePointer to sprite handle

◆ Entity_Init()

int Entity_Init ( const double  dPosX,
const double  dPosY,
const Uint16  u16Width,
const Uint16  u16Height,
Entity **  pstEntity 
)

Initialise entity.

Initialises entity

Parameters
dPosXInitial position along the x-axis
dPosYInitial position along the y-axis
u16WidthEntity width in pixel
u16HeightEntity height in pixel
pstEntityPointer to entity handle
Returns
Error code
Return values
0OK
-1Error

◆ Entity_InitCamera()

int Entity_InitCamera ( Camera **  pstCamera)

Initialise camera.

Initialises the camera

Parameters
pstCameraPointer to camera handle
Returns
Error code
Return values
0OK
-1Error

◆ Entity_InitSprite()

int Entity_InitSprite ( const char *  pacFileName,
const Uint16  u16Width,
const Uint16  u16Height,
const Uint16  u16ImageOffsetX,
const Uint16  u16ImageOffsetY,
Sprite **  pstSprite,
SDL_Renderer *  pstRenderer 
)

Initialise sprite.

Initialises sprite image

Parameters
pacFileNamePath and filename of the image file to load
u16WidthSprite width in pixel
u16HeightSprite height in pixel
u16ImageOffsetXImage pixel offset along the x-axis in case a partial image should be loaded
u16ImageOffsetYImage pixel offset along the y-axis in case a partial image should be loaded
pstSpritePointer to sprite handle
pstRendererPointer to SDL2 rendering context
Returns
Error code
Return values
0OK
-1Error

◆ Entity_IsCameraLocked()

SDL_bool Entity_IsCameraLocked ( const Camera pstCamera)

Check if camera is locked.

Check whether the camera's IS_LOCKED flag is set or not

Parameters
pstCameraPointer to camera handle
Returns
Current lock state of the camera
Return values
SDL_TRUECamera is locked
SDL_FALSECamera is not locked
Here is the call graph for this function:

◆ Entity_IsMoving()

SDL_bool Entity_IsMoving ( const Entity pstEntity)

Check if entity is moving.

Check whether the entity's IS_MOVING flag is set or not

Parameters
pstEntityPointer to entity handle
Returns
Current moving state of the entity
Return values
SDL_TRUEEntity is moving
SDL_FALSEEntity is not moving
Here is the call graph for this function:

◆ Entity_IsRising()

SDL_bool Entity_IsRising ( const Entity pstEntity)

Check if a entity is rising.

Check if a entity accelerates up along the y-axis

Parameters
pstEntityPointer to entity handle
Returns
Current rising state of the entity
Return values
SDL_TRUEEntity is rising
SDL_FALSEEntity is not rising
Here is the caller graph for this function:

◆ Entity_Jump()

void Entity_Jump ( const double  dForce,
Entity pstEntity 
)

Jump with entity.

Initiates a jump by applying force

Parameters
dForceInitial jump force
pstEntityPointer to entity handle

◆ Entity_LockCamera()

void Entity_LockCamera ( Camera pstCamera)

Lock camera.

Sets the camera's IS_LOCKED flag

Parameters
pstCameraPointer to camera handle
Here is the call graph for this function:

◆ Entity_Move()

void Entity_Move ( Entity pstEntity)

Set entity in motion.

Sets the entity's IS_MOVING flag

Parameters
pstEntityPointer to entity handle
Here is the call graph for this function:

◆ Entity_MoveFull()

void Entity_MoveFull ( const Direction  eDirection,
const double  dAcceleration,
const double  dMaxVelocityX,
const Uint8  u8AnimStart,
const Uint8  u8AnimEnd,
const double  dAnimSpeed,
const Uint8  u8FrameOffsetY,
Entity pstEntity 
)

Move entity with parameters.

Same as Entity_Move() but all parameters can be set at once

Parameters
eDirectionDirection
dAccelerationAcceleration
dMaxVelocityXMaximum velocity along the y-axis
u8AnimStartStart frame
u8AnimEndLast frame
dAnimSpeedAnimation speed
u8FrameOffsetYFrame offset in frames along the y-axis
pstEntityPointer to entity handle
Here is the call graph for this function:

◆ Entity_Reset()

void Entity_Reset ( Entity pstEntity)

Reset entity flags.

Resets all flags of an entity

Parameters
pstEntityPointer to entity handle

◆ Entity_ResetToSpawnPosition()

void Entity_ResetToSpawnPosition ( Entity pstEntity)

Reset to spawn position.

Moves an entity to its configured spawn position

Parameters
pstEntityPointer to entity handle

◆ Entity_SetAnimation()

void Entity_SetAnimation ( const Uint8  u8AnimStart,
const Uint8  u8AnimEnd,
const double  dAnimSpeed,
Entity pstEntity 
)

Set animation for entity.

Sets animation start, end and speed for entity

Parameters
u8AnimStartStart frame
u8AnimEndLast frame
dAnimSpeedAnimation speed
pstEntityPointer to entity handle
Here is the caller graph for this function:

◆ Entity_SetCameraBoundariesToMapSize()

int Entity_SetCameraBoundariesToMapSize ( const Sint32  s32LogicalWindowWidth,
const Sint32  s32LogicalWindowHeight,
const Uint16  u16MapWidth,
const Uint16  u16MapHeight,
Camera pstCamera 
)

Set camera boundaries to map size.

Sets the camera's boundaries to size of the map

Parameters
s32LogicalWindowWidthLogical window width in pixel
s32LogicalWindowHeightLogical window height in pixel
u16MapWidthMap width in pixel
u16MapHeightMap height in pixel
pstCameraPointer to camera handle
Returns
Current state of camera
Return values
0Camera has reached set boundaries
1Camera hasn't reached set boundaries

◆ Entity_SetCameraTarget()

void Entity_SetCameraTarget ( const Sint32  s32LogicalWindowWidth,
const Sint32  s32LogicalWindowHeight,
const Entity pstEntity,
Camera pstCamera 
)

Set camera target.

Sets the camera's target entity that should be tracked

Parameters
s32LogicalWindowWidthLogical window width in pixel
s32LogicalWindowHeightLocical window height in pixel
pstEntityPointer to entity handle
pstCameraPointer to camera handle
Here is the call graph for this function:

◆ Entity_SetDirection()

void Entity_SetDirection ( const Direction  eDirection,
Entity pstEntity 
)

Set entity direction.

Sets the direction of an entity

Parameters
eDirectionDirection
pstEntityPointer to entity handle
Here is the caller graph for this function:

◆ Entity_SetFrameOffset()

void Entity_SetFrameOffset ( const Uint8  u8OffsetX,
const Uint8  u8OffsetY,
Entity pstEntity 
)

Set frame offset.

Sets a frame offset in frames

Parameters
u8OffsetXOffset in frames along the x-axis
u8OffsetYOffset in frames along the y-axis
pstEntityPointer to entity handle
Todo:
Describe this function in more detail
Here is the caller graph for this function:

◆ Entity_SetPosition()

void Entity_SetPosition ( const double  dPosX,
const double  dPosY,
Entity pstEntity 
)

Set entity position.

Sets the absolute position for an entity

Parameters
dPosXPosition along the x-axis
dPosYPosition along the y-axis
pstEntityPointer to entity handle

◆ Entity_SetSpawnPosition()

void Entity_SetSpawnPosition ( const double  dPosX,
const double  dPosY,
Entity pstEntity 
)

Set entity spawn position.

Sets absolute (re)spawn position for an entity

Parameters
dPosXPosition along the x-axis
dPosYPosition along the y-axis
pstEntityPointer to entity handle

◆ Entity_SetSpeed()

void Entity_SetSpeed ( const double  dAcceleration,
const double  dMaxVelocityX,
Entity pstEntity 
)

Set entity speed.

Sets a entity's acceleration and maximum velocity along the x-axis

Parameters
dAccelerationAcceleration
dMaxVelocityXMaximum velocity along the y-axis
pstEntityPointer to entity handle
Here is the caller graph for this function:

◆ Entity_Stop()

void Entity_Stop ( Entity pstEntity)

Stop entity.

Clears the IS_MOVING flag of an entity

Parameters
pstEntityPointer to entity handle
Here is the call graph for this function:

◆ Entity_UnlockCamera()

void Entity_UnlockCamera ( Camera pstCamera)

Unlock camera.

Clears the IS_LOCKED flag of a camera entity

Parameters
pstCameraPointer to camera handle
Here is the call graph for this function:

◆ Entity_Update()

void Entity_Update ( const double  dDeltaTime,
const double  dGravitation,
const Uint8  u8MeterInPixel,
Entity pstEntity 
)

Update entity.

Updates the current state of an entity

Remarks
This function is usually called once per frame
Parameters
dDeltaTimeDelta time since last call
dGravitationGravitational constant of entity
u8MeterInPixelDefinition of meter in pixel
pstEntityPointer to entity handle
Here is the call graph for this function: