is_wall - 1Fr3aK2/Cub3d GitHub Wiki

📝 is_wall

Checks whether a given position in the map corresponds to a wall.

⚙️ Parameters

Parameter Type Description
map t_map* Pointer to the map structure containing the map grid.
y float The vertical coordinate (row index) to check in the map.
x float The horizontal coordinate (column index) to check in the map.

🔁 Returns

Return value Description
bool Returns true if the specified position corresponds to a wall, otherwise false.

📖 Description

The is_wall function determines whether the given (x, y) position in the map represents a wall.
It first verifies that the map pointer is valid and that the provided coordinates are within the bounds of the map.
If the position is outside the map or invalid, the function returns false.

  • The coordinates x and y are cast to integers to access the corresponding cell in the map grid.
  • If the cell contains the character or constant WALL, the function returns true.
  • Otherwise, or if the cell is empty, invalid, or out of bounds, it returns false.

This function is typically used for collision detection or determining whether the player or an object is hitting a wall during movement or raycasting.

💡 Example Usage

float x = 5.2f;
float y = 3.7f;

if (is_wall(&map, y, x)) {
    printf("There's a wall at (%.1f, %.1f)\n", x, y);
} else {
    printf("No wall at (%.1f, %.1f)\n", x, y);
}