Map.c File Reference
#include <SDL.h>
#include <SDL_image.h>
#include "Constants.h"
#include "Map.h"
Include dependency graph for Map.c:

Functions

Sint8 Map_Draw (const Uint16 u16Index, const SDL_bool bRenderAnimTiles, const SDL_bool bRenderBgColour, const char *pacLayerName, const double dCameraPosX, const double dCameraPosY, Map *pstMap, SDL_Renderer *pstRenderer)
 Draw Map. More...
 
void Map_Free (Map *pstMap)
 Free map. More...
 
void Map_GetObjects (const Map *pstMap, Object astObject[])
 Get objects. More...
 
Uint16 Map_GetObjectCount (Map *pstMap)
 Get object count. More...
 
char * Map_GetObjectName (Object *pstObject)
 Get object name. More...
 
char * Map_GetObjectType (Object *pstObject)
 Get object type. More...
 
Sint8 Map_Init (const char *pacFileName, const char *pacTilesetImage, const Uint8 u8MeterInPixel, Map **pstMap)
 Initialise map. More...
 
SDL_bool Map_IsCoordOfType (const char *pacType, const Map *pstMap, double dPosX, double dPosY)
 Check if map coordinate is of specific type. More...
 
SDL_bool Map_IsObjectOfType (const char *pacType, Object *pstObject)
 Determine if object is of specific type. More...
 
SDL_bool Map_IsOnTileOfType (const char *pacType, const double dPosX, const double dPosY, const Uint8 u8EntityHeight, const Map *pstMap)
 Determine if entity/object is on-top of tile of specific type. More...
 
void Map_SetGravitation (const double dGravitation, const SDL_bool bUseTmxConstant, Map *pstMap)
 Set map gravitation. More...
 
void Map_SetTileAnimationSpeed (const double dAnimSpeed, Map *pstMap)
 Set speed of animated tiles. More...
 
void Map_ShowObjects (const Map *pstMap)
 Show map objects. More...
 

Function Documentation

◆ Map_Draw()

Sint8 Map_Draw ( const Uint16  u16Index,
const SDL_bool  bRenderAnimTiles,
const SDL_bool  bRenderBgColour,
const char *  pacLayerName,
const double  dCameraPosX,
const double  dCameraPosY,
Map pstMap,
SDL_Renderer *  pstRenderer 
)

Draw Map.

Draws the map on screen

Parameters
u16IndexThe texture index; the total amount of layers per map is defined by MAP_TEXTURES.
bRenderAnimTilesIf set to 1, all animated tiles will be rendered in this call.
bRenderBgColourDetermine if the map's background colour should be rendered
pacLayerNameSub-string of the layer(s) to render
dCameraPosXCamera position along the x-axis
dCameraPosYCamera position along the y-axis
pstMapPointer to map handle
pstRendererPointer to SDL2 rendering context
Returns
Error code
Return values
0OK
-1Error

◆ Map_Free()

void Map_Free ( Map pstMap)

Free map.

Frees up allocated memory and unloads map

Parameters
pstMapPointer to map handle

◆ Map_GetObjectCount()

Uint16 Map_GetObjectCount ( Map pstMap)

Get object count.

Return total object count of map

Parameters
pstMapPointer to map handle
Returns
Number of objects in the map
Here is the caller graph for this function:

◆ Map_GetObjectName()

char* Map_GetObjectName ( Object pstObject)

Get object name.

Get name of an object

Parameters
pstObjectPointer to object handle
Returns
The object name as a string

◆ Map_GetObjects()

void Map_GetObjects ( const Map pstMap,
Object  astObject[] 
)

Get objects.

Retreive objects from map

Parameters
pstMapPointer to map handle
astObjectArray to store the objects
Here is the caller graph for this function:

◆ Map_GetObjectType()

char* Map_GetObjectType ( Object pstObject)

Get object type.

Get type of an object

Parameters
pstObjectPointer to object handle
Returns
The object type as a string
Here is the caller graph for this function:

◆ Map_Init()

Sint8 Map_Init ( const char *  pacFileName,
const char *  pacTilesetImage,
const Uint8  u8MeterInPixel,
Map **  pstMap 
)

Initialise map.

Initialises/load map

Parameters
pacFileNamePath and filename of the TMX map to load
pacTilesetImagePath and filename of the tileset image
u8MeterInPixelDefinition of meter in pixel
pstMapPointer to map handle
Returns
Error code
Return values
0OK
-1Error
Here is the call graph for this function:

◆ Map_IsCoordOfType()

SDL_bool Map_IsCoordOfType ( const char *  pacType,
const Map pstMap,
double  dPosX,
double  dPosY 
)

Check if map coordinate is of specific type.

Checks if a coodinate is of a specific type

Parameters
pacTypeName of the type to check for
pstMapPointer to map handle
dPosXCoordinate along the x-axis
dPosYCoordinate along the y-axis
Returns
Boolean state
Return values
SDL_TRUEMap coordinate is of specific type
SDL_FALSEMap coordinate is not of specific type
Here is the caller graph for this function:

◆ Map_IsObjectOfType()

SDL_bool Map_IsObjectOfType ( const char *  pacType,
Object pstObject 
)

Determine if object is of specific type.

Determines if an object is of a specific type

Parameters
pacTypeThe type name to check for
pstObjectPointer to object handle
Returns
Boolean state
Return values
SDL_TRUEObject is of specific type
SDL_FALSEObject is not of specific type
Here is the call graph for this function:

◆ Map_IsOnTileOfType()

SDL_bool Map_IsOnTileOfType ( const char *  pacType,
const double  dPosX,
const double  dPosY,
const Uint8  u8EntityHeight,
const Map pstMap 
)

Determine if entity/object is on-top of tile of specific type.

Determines if an entity/object is on-top of a tile of a specific type

Parameters
pacTypeThe type name to check for
dPosXPosition along the x-axis
dPosYPosition along the y-axis
u8EntityHeightHeight ob the entity/object in pixel
pstMapPointer to map handle
Returns
Boolean state
Return values
SDL_TRUEentity is on-top of tile of specific type
SDL_FALSEentity is not on-top of tile of specific type
Here is the call graph for this function:

◆ Map_SetGravitation()

void Map_SetGravitation ( const double  dGravitation,
const SDL_bool  bUseTmxConstant,
Map pstMap 
)

Set map gravitation.

Sets the gravitational constant of the map

Parameters
dGravitation
bUseTmxConstant
pstMap
Here is the caller graph for this function:

◆ Map_SetTileAnimationSpeed()

void Map_SetTileAnimationSpeed ( const double  dAnimSpeed,
Map pstMap 
)

Set speed of animated tiles.

Sets the speed of animated tiles

Parameters
dAnimSpeedAnimation speed
pstMapPointer to map handle

◆ Map_ShowObjects()

void Map_ShowObjects ( const Map pstMap)

Show map objects.

Prints a list of all map objects

Parameters
pstMapPointer to map handle
Remarks
This function is mainly for debugging purposes