NightFox’s Lib
Data Structures | Macros | Functions | Variables
Collision map support.

Collision maps only have map information, so the collisions have a granularity of 8x8 pixels. More...

Data Structures

struct  NF_TYPE_CMAP_INFO
 Struct that holds collision map information. More...
 

Macros

#define NF_SLOTS_CMAP   32
 Maximum number of available collision maps.
 

Functions

void NF_InitCmapBuffers (void)
 Initialize buffers to store collision map data. More...
 
void NF_ResetCmapBuffers (void)
 Reset collision map buffers, clearing all data in RAM. More...
 
void NF_LoadCollisionMap (const char *file, u32 id, u32 width, u32 height)
 Load a collision map into RAM in the specified slot. More...
 
void NF_UnloadCollisionMap (u32 id)
 Unload from RAM the collision map at the specified slot. More...
 
u32 NF_GetTile (u32 slot, s32 x, s32 y)
 Return the tile number at the specified position. More...
 
void NF_SetTile (u32 slot, s32 x, s32 y, u32 value)
 Set the value of the tile of a collision map at the specified position. More...
 
void NF_LoadCollisionBg (const char *file, u32 id, u32 width, u32 height)
 Load a collision background to RAM at the specified slot. More...
 
void NF_UnloadCollisionBg (u32 id)
 Unload from RAM the collision background at the specified slot. More...
 
u8 NF_GetPoint (u32 slot, s32 x, s32 y)
 Returns the color number at the specified coordinates. More...
 

Variables

NF_TYPE_CMAP_INFO NF_CMAP [NF_SLOTS_CMAP]
 Information of all collision maps.
 

Detailed Description

Collision maps only have map information, so the collisions have a granularity of 8x8 pixels.

This is useful for games where the map is simple and it doesn't have many details that affect collisions.

Collision backgrounds also have tile information, so they can have information at a pixel granularity.

Function Documentation

◆ NF_GetPoint()

u8 NF_GetPoint ( u32  slot,
s32  x,
s32  y 
)

Returns the color number at the specified coordinates.

If the coordinates are outside of the background, it returns 0.

Parameters
slotSlot number (0 - 31)
xX coordinate in pixels.
yY coordinate in pixels.
Returns
Tile index (0 - 255).

◆ NF_GetTile()

u32 NF_GetTile ( u32  slot,
s32  x,
s32  y 
)

Return the tile number at the specified position.

You must place your tileset in the first row of the collision map image.

Parameters
slotSlot number (0 - 31)
xX coordinate in pixels.
yY coordinate in pixels.
Returns
Tile index.

◆ NF_InitCmapBuffers()

void NF_InitCmapBuffers ( void  )

Initialize buffers to store collision map data.

You must call this function once in you code before loading any collision map.

◆ NF_LoadCollisionBg()

void NF_LoadCollisionBg ( const char *  file,
u32  id,
u32  width,
u32  height 
)

Load a collision background to RAM at the specified slot.

You must specify the width and height of the background in pixels. Remember to make your colision background 8 pixels taller than your real background and to use this first row of tiles to define your color tileset for the collision background.

Use the "Convert_CMaps.bat" script in the GRIT folder to convert you maps. You need to copy the ".cmp" and ".dat" files to your game data folder.

Parameters
fileFile name
idSlot number (0 - 31)
widthMap width (in pixels)
heightMap height (in pixels)

◆ NF_LoadCollisionMap()

void NF_LoadCollisionMap ( const char *  file,
u32  id,
u32  width,
u32  height 
)

Load a collision map into RAM in the specified slot.

You must specify the width and height of the map in pixels. Remember to make your collision map 8 pixels taller than your background and to use this first row of tiles to define your tileset for the collision map.

Use the "Convert_CMaps.bat" script in the GRIT folder to convert your maps. You need to copy the ".cmp" file to your game data folder.

Parameters
fileFile name
idSlot number (0 - 31)
widthMap width (in pixels)
heightMap height (in pixels)

◆ NF_ResetCmapBuffers()

void NF_ResetCmapBuffers ( void  )

Reset collision map buffers, clearing all data in RAM.

It's useful to use this function during game level changes, for example, to easily clear all data before loading the new level.

◆ NF_SetTile()

void NF_SetTile ( u32  slot,
s32  x,
s32  y,
u32  value 
)

Set the value of the tile of a collision map at the specified position.

Parameters
slotSlot number (0 - 31)
xX coordinate in pixels.
yY coordinate in pixels.
valueNew tile.

◆ NF_UnloadCollisionBg()

void NF_UnloadCollisionBg ( u32  id)

Unload from RAM the collision background at the specified slot.

Parameters
idSlot number (0 - 31)

◆ NF_UnloadCollisionMap()

void NF_UnloadCollisionMap ( u32  id)

Unload from RAM the collision map at the specified slot.

Parameters
idSlot number (0 - 31)