From f83bdf40e380711a2b8c17e0007b9f7edcc9d18e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Fri, 7 Sep 2018 18:19:25 +0200 Subject: [PATCH] Fix movement --- raycastlib.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/raycastlib.h b/raycastlib.h index d5972de..045df40 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -982,6 +982,7 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset, Unit bottomLimit = camera->height - camera->collisionHeightBelow; Unit topLimit = camera->height + camera->collisionHeightAbove; + // checks a single square for collision against the camera #define collCheck(dir,s1,s2)\ {\ Unit height = floorHeightFunc(s1,s2);\ @@ -995,22 +996,28 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset, }\ }\ - #define collCheckOrtho(dir,dir2,s1,s2)\ + // check a collision against non-diagonal square + #define collCheckOrtho(dir,dir2,s1,s2,x)\ if (dir##SquareNew != dir##Square)\ collCheck(dir,s1,s2)\ if (!dir##Collides)\ - {\ + { /* now also check for coll on the neighbouring square */ \ int16_t dir2##Square2 = divRoundDown(corner.dir2 - dir2##Dir *\ camera->collisionRadius,UNITS_PER_SQUARE);\ if (dir2##Square2 != dir2##Square)\ - collCheck(dir,dir2##Square2,dir##SquareNew)\ + {\ + if (x)\ + collCheck(dir,dir##SquareNew,dir2##Square2)\ + else\ + collCheck(dir,dir2##Square2,dir##SquareNew)\ + }\ } int8_t xCollides = false; - collCheckOrtho(x,y,xSquareNew,ySquare) + collCheckOrtho(x,y,xSquareNew,ySquare,1) int8_t yCollides = false; - collCheckOrtho(y,x,xSquare,ySquareNew) + collCheckOrtho(y,x,xSquare,ySquareNew,0) #define collHandle(dir)\ if (dir##Collides)\