Operation Null Mind 0.4.1
A 2D roguelike top down shooter game made with SDL2
 
Loading...
Searching...
No Matches
tiles.h File Reference

Defines and manages environment tiles for game world construction. More...

#include <vec2.h>
#include <SDL.h>
#include <camera.h>

Go to the source code of this file.

Classes

struct  EnvironmentTile
 Represents a single environment tile. More...
 
struct  EnvironmentTileResources
 Contains loaded textures for all tile types. More...
 
struct  EnvironmentTileConfig
 Configuration for tile resources. More...
 
struct  EnvironmentTileData
 Global tile data container. More...
 

Macros

#define TILE_SIZE_PIXELS   20
 Defines the size of a tile in pixels.
 
#define MAX(a, b)   ((a) > (b) ? (a) : (b))
 Safely calculates maximum of two values.
 
#define MIN(a, b)   ((a) < (b) ? (a) : (b))
 Safely calculates minimum of two values.
 

Enumerations

enum  TileType {
  TILE_VOID , TILE_FLOOR_1 , TILE_FLOOR_2 , TILE_FLOOR_3 ,
  TILE_FLOOR_VENT_1 , TILE_FLOOR_VENT_2 , TILE_FLOOR_VENT_3 , TILE_FLOOR_SCRATCHED_1 ,
  TILE_FLOOR_SCRATCHED_2 , TILE_FLOOR_SCRATCHED_3 , TILE_WALL_TOP , TILE_WALL_BOTTOM ,
  TILE_WALL_CORNER_BORDER_SMALL , TILE_WALL_CORNER_BORDER , TILE_WALL_SIDE_BORDER , TILE_TYPE_COUNT
}
 Defines various types of environment tiles. More...
 
enum  TileRotation { TILE_ROTATE_NONE , TILE_ROTATE_CLOCKWISE , TILE_ROTATE_COUNTERCLOCKWISE , TILE_ROTATE_180 }
 Defines rotation options for tiles. More...
 

Functions

void Tile_Start ()
 Initialize tile system.
 
EnvironmentTile Tile_Create (TileType type, TileRotation rotation)
 Create a new environment tile.
 
void Tile_Destroy (EnvironmentTile *tile)
 Destroy a tile and free resources.
 
void Tile_Render (EnvironmentTile tile, Vec2 tilePosition)
 Render a tile at the specified position.
 
void Tile_FromPixelPoint (Vec2 pixelPoint, Vec2 *chunkIndex, Vec2 *tileIndex)
 Convert a pixel coordinate to tile and chunk indices.
 
bool Tile_IsValid (Vec2 tileIndex)
 Check if a tile index is valid.
 
Vec2 Tile_GetPositionFromPixel (Vec2 pixelPoint)
 Convert a pixel coordinate to a tile position.
 
SDL_Rect Tile_GetRectFromPixel (Vec2 pixelPoint)
 Get the rectangle of a tile from a pixel coordinate.
 
Vec2 Tile_GetRandomPixelInRect (SDL_Rect rect)
 Get a random pixel coordinate within a rectangle.
 
Vec2 Tile_TileIndexToPixel (Vec2 tileIndex, Vec2 chunkIndex)
 Convert tile and chunk indices to a pixel coordinate.
 

Variables

EnvironmentTileData tiles
 Global tile data instance.
 

Detailed Description

Defines and manages environment tiles for game world construction.

Author
Mango
Date
2025-03-13

Macro Definition Documentation

◆ MAX

#define MAX (   a,
  b 
)    ((a) > (b) ? (a) : (b))

Safely calculates maximum of two values.

Parameters
aFirst value to compare
bSecond value to compare
Returns
The greater of a and b

◆ MIN

#define MIN (   a,
  b 
)    ((a) < (b) ? (a) : (b))

Safely calculates minimum of two values.

Parameters
aFirst value to compare
bSecond value to compare
Returns
The lesser of a and b

◆ TILE_SIZE_PIXELS

#define TILE_SIZE_PIXELS   20

Defines the size of a tile in pixels.

Enumeration Type Documentation

◆ TileRotation

Defines rotation options for tiles.

Enumerator
TILE_ROTATE_NONE 

No rotation.

TILE_ROTATE_CLOCKWISE 

90 degrees clockwise rotation

TILE_ROTATE_COUNTERCLOCKWISE 

90 degrees counterclockwise rotation

TILE_ROTATE_180 

180 degrees rotation

◆ TileType

enum TileType

Defines various types of environment tiles.

Enumerator
TILE_VOID 

Empty/void tile.

TILE_FLOOR_1 

Standard floor type 1.

TILE_FLOOR_2 

Standard floor type 2.

TILE_FLOOR_3 

Standard floor type 3.

TILE_FLOOR_VENT_1 

Floor with vent, variation 1.

TILE_FLOOR_VENT_2 

Floor with vent, variation 2.

TILE_FLOOR_VENT_3 

Floor with vent, variation 3.

TILE_FLOOR_SCRATCHED_1 

Scratched floor, variation 1.

TILE_FLOOR_SCRATCHED_2 

Scratched floor, variation 2.

TILE_FLOOR_SCRATCHED_3 

Scratched floor, variation 3.

TILE_WALL_TOP 

Wall top section.

TILE_WALL_BOTTOM 

Wall bottom section.

TILE_WALL_CORNER_BORDER_SMALL 

Small corner wall border.

TILE_WALL_CORNER_BORDER 

Corner wall border.

TILE_WALL_SIDE_BORDER 

Side wall border.

TILE_TYPE_COUNT 

Total count of tile types.

Function Documentation

◆ Tile_Create()

EnvironmentTile Tile_Create ( TileType  type,
TileRotation  rotation 
)

Create a new environment tile.

Parameters
typeThe type of tile to create
rotationThe rotation to apply to the tile
Returns
A new EnvironmentTile instance

Create a new environment tile.

Factory function that constructs a tile with the appropriate texture and rotation.

Parameters
typeThe type of tile to create
rotationThe rotation to apply to the tile
Returns
EnvironmentTile The constructed tile

◆ Tile_Destroy()

void Tile_Destroy ( EnvironmentTile *  tile)

Destroy a tile and free resources.

Parameters
tilePointer to the tile to destroy

◆ Tile_FromPixelPoint()

void Tile_FromPixelPoint ( Vec2  pixelPoint,
Vec2 *  chunkIndex,
Vec2 *  tileIndex 
)

Convert a pixel coordinate to tile and chunk indices.

Parameters
pixelPointThe pixel coordinate to convert
chunkIndexOutput parameter for the chunk index
tileIndexOutput parameter for the tile index

Convert a pixel coordinate to tile and chunk indices.

Takes a world-space pixel coordinate and determines which tile and chunk it belongs to.

Parameters
pixelPointThe world position in pixels
chunkIndexOutput parameter for the chunk index
tileIndexOutput parameter for the tile index within the chunk

◆ Tile_GetPositionFromPixel()

Vec2 Tile_GetPositionFromPixel ( Vec2  pixelPoint)

Convert a pixel coordinate to a tile position.

Parameters
pixelPointThe pixel coordinate to convert
Returns
The tile position

Convert a pixel coordinate to a tile position.

Parameters
pixelPointThe pixel coordinates to convert
Returns
Vec2 The position of the tile that contains the pixel

◆ Tile_GetRandomPixelInRect()

Vec2 Tile_GetRandomPixelInRect ( SDL_Rect  rect)

Get a random pixel coordinate within a rectangle.

Parameters
rectThe rectangle to get a random pixel from
Returns
A random pixel coordinate within the rectangle

Get a random pixel coordinate within a rectangle.

Parameters
rectThe rectangle to get a random point within
Returns
Vec2 A random pixel position inside the rectangle

◆ Tile_GetRectFromPixel()

SDL_Rect Tile_GetRectFromPixel ( Vec2  pixelPoint)

Get the rectangle of a tile from a pixel coordinate.

Parameters
pixelPointThe pixel coordinate
Returns
An SDL_Rect representing the tile's bounds

Get the rectangle of a tile from a pixel coordinate.

Parameters
pixelPointThe pixel coordinates within the tile
Returns
SDL_Rect The rectangle representing the tile

◆ Tile_IsValid()

bool Tile_IsValid ( Vec2  tileIndex)

Check if a tile index is valid.

Parameters
tileIndexThe tile index to check
Returns
true if the tile index is valid, false otherwise

Check if a tile index is valid.

Parameters
tileIndexThe tile index to check
Returns
bool True if the tile index is valid, false otherwise

◆ Tile_Render()

void Tile_Render ( EnvironmentTile  tile,
Vec2  tilePosition 
)

Render a tile at the specified position.

Parameters
tileThe tile to render
tilePositionPosition where the tile should be rendered

◆ Tile_Start()

void Tile_Start ( )

Initialize tile system.

Initialize tile system.

Loads all tile textures from disk and creates texture resources for each tile type.

◆ Tile_TileIndexToPixel()

Vec2 Tile_TileIndexToPixel ( Vec2  tileIndex,
Vec2  chunkIndex 
)

Convert tile and chunk indices to a pixel coordinate.

Parameters
tileIndexThe tile index
chunkIndexThe chunk index
Returns
The corresponding pixel coordinate

Convert tile and chunk indices to a pixel coordinate.

Parameters
tileIndexThe tile index within the chunk
chunkIndexThe chunk index
Returns
Vec2 The world pixel position

Variable Documentation

◆ tiles

EnvironmentTileData tiles
extern

Global tile data instance.