From a8c75f2bc537b65c6b6621819a1445c473ec6f83 Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 17 Jan 2026 20:15:48 +0100 Subject: [PATCH] Update models_first_person_maze.c --- examples/models/models_first_person_maze.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/models/models_first_person_maze.c b/examples/models/models_first_person_maze.c index 4c77d6121..13b56f4cd 100644 --- a/examples/models/models_first_person_maze.c +++ b/examples/models/models_first_person_maze.c @@ -84,19 +84,19 @@ int main(void) for (int y = playerCellY - 1; y <= playerCellY + 1; y++) { // Avoid map accessing out of bounds - if ((y < 0) || (y >= cubicmap.height)) continue; - - for (int x = playerCellX - 1; x <= playerCellX + 1; x++) + if ((y >= 0) && (y < cubicmap.height)) { - // Avoid map accessing out of bounds - if ((x < 0) || (x >= cubicmap.width)) continue; - - if ((mapPixels[y*cubicmap.width + x].r == 255) && // Collision: white pixel, only check R channel - (CheckCollisionCircleRec(playerPos, playerRadius, - (Rectangle){ mapPosition.x - 0.5f + x*1.0f, mapPosition.z - 0.5f + y*1.0f, 1.0f, 1.0f }))) + for (int x = playerCellX - 1; x <= playerCellX + 1; x++) { - // Collision detected, reset camera position - camera.position = oldCamPos; + // NOTE: Collision: Only checking R channel for white pixel + if (((x >= 0) && (x < cubicmap.width)) && + (mapPixels[y*cubicmap.width + x].r == 255) && + (CheckCollisionCircleRec(playerPos, playerRadius, + (Rectangle){ mapPosition.x - 0.5f + x*1.0f, mapPosition.z - 0.5f + y*1.0f, 1.0f, 1.0f }))) + { + // Collision detected, reset camera position + camera.position = oldCamPos; + } } } }