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

Utility functions for tile-based environment. More...

#include <maps.h>
#include <math.h>
#include <random.h>

Functions

void Tile_FromPixelPoint (Vec2 pixelPoint, Vec2 *chunkIndex, Vec2 *tileIndex)
 [Utility] Converts a pixel position to tile and chunk indices
 
bool Tile_IsValid (Vec2 tileIndex)
 [Utility] Checks if a tile index is valid within a chunk
 
Vec2 Tile_GetPositionFromPixel (Vec2 pixelPoint)
 [Utility] Converts a pixel point to a tile position
 
SDL_Rect Tile_GetRectFromPixel (Vec2 pixelPoint)
 [Utility] Gets the rectangle for a tile from a pixel point
 
Vec2 Tile_GetRandomPixelInRect (SDL_Rect rect)
 [Utility] Gets a random pixel coordinate within a rectangle
 
Vec2 Tile_TileIndexToPixel (Vec2 tileIndex, Vec2 chunkIndex)
 [Utility] Converts tile and chunk indices to a world pixel position
 

Detailed Description

Utility functions for tile-based environment.

Provides coordinate conversion, validation, and helper functions for the tile-based environment system.

Author
Mango
Date
2025-03-03

Function Documentation

◆ Tile_FromPixelPoint()

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

[Utility] Converts a pixel position to tile and chunk indices

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)

[Utility] Converts a pixel point to a 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)

[Utility] Gets a random pixel coordinate within a 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)

[Utility] Gets the rectangle for a tile from a pixel point

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)

[Utility] Checks if a tile index is valid within a chunk

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_TileIndexToPixel()

Vec2 Tile_TileIndexToPixel ( Vec2  tileIndex,
Vec2  chunkIndex 
)

[Utility] Converts tile and chunk indices to a world pixel position

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