From eaa683ecf3a36240b90c4aba69dfcc96ea3e5b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Wed, 29 Jul 2020 21:19:53 +0200 Subject: [PATCH] Update --- assets/levelC.gif | Bin 0 -> 4424 bytes raycastlib.h | 69 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 51 insertions(+), 18 deletions(-) create mode 100644 assets/levelC.gif diff --git a/assets/levelC.gif b/assets/levelC.gif new file mode 100644 index 0000000000000000000000000000000000000000..07680f8294f7f53316dfb02eab9227378866cfe8 GIT binary patch literal 4424 zcmV-O5x4F~Nk%w1VT%BZ0O$Vz0096803iVbA|L<&4*)?J03ja%5C{h#0t-JG2p=N= zVIT*06zc~Ap#F#A`bvy000pdAs7@P9~1~76BaoDpdS?w z7!*GMAplVTUjQHu1|R?gAP8arFAp3T2p|t184d&?8VweII|9QFAQllI5r6;yG7~-- zAO#yB02m+)K@ulH6c7L%piKbb3MD~t0EB@6OCls8Tmbn2EJ2|F04N||KOq4CCBusV zprHU*Cn!I`00Iss;bI;hKqoRcDL+3cC{Q3?06_*pED|L#Kw=(213)G>D1*QNX{i9g z2tXj>000$002@FMA2?wVKsFgJ`9U-$`Tzi5F#rlgUf}?CFhC6`KrSjkDaQceBtbbi zKmdX!CTJ*sI6xM9sfL$e0WPb#JR&G@NDS!as zM@B7xMrmtkIe;ZaaK9*jdT(f>ze?iaMxcOfO#qF-z-0hYfMStnpmBcy0H7IIfKpC? zd7o)!Xn-f8XNmY!PH%uvp>#0_pK;hz`ecEjPJ`btpaA$*xB#KzD4<|Np(=%d!ZDzi z-*^C?iD&@97gCq`uYbb8fPjvWjlhAPz==Tsz<+U{XlS5+kDvf$p_qlCFMpW96u0>K zhX9bEXhXpOpOxS{z;7_Xx>CVE0^kqcm5|Ys;@_0Q;h#jpq<@pI-xc7LfxwrFz<#=@ z_n^Q$vA_U>z_(N20I{^NvA}>#;C%U~r4RfnWZ**Rsrmb-*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K01zMo zHt+*ZumxwpiJv%*+7Oh>qgOj`FC5G7?=H0RZnvH1Rl({P=*8 zqFeFw82Q*R``C{Lseu1zA(AnWxl)h^X^`oKj||z64_T22S!PWkkrUZd7O8-q0Fm{` zRT{aGSYnZy<&pe&dL#*t9f=Mn`H}NT{wo40knuzj5(ybJF_Sfkk2-miGf9&)i4_hh zk1*+y{m52Kag#QwlL48LP05o1`IAjKl{Lv1CTWyd`H5$M4n}a1&bO3c36(zyl~u`; zOlg);xsy~Wlvn8qy>OB-8It}nk}FveE%}h{SeG?+mj@{=_NbQ}$(Kh-G5`sfo1u|I zDVU$=mn^}QWx11MNfFXWjn;^b+Q^OG2#(%ClZmOAoroD{8JR$-k&{`C*O-ml*p1(K z21~hn7vY(4c~U;9mSx$Kk~xj0X_={+nXKs>oC%xqn3slm6^IF(>?oYRsgyXWGM#Ch z5{R6aX=vkniai9o#p9;F53<`<~ z`k-tXq4emW6k4Gc`kWJ*p?7kiSCEC{>7mWJp(C21C2FB3N}(wlp)2~JEy|!T+Ga=b znj6ZYvMHL7DV;dEoC4W90e-~sM|5jTpX|2dmBd5=?ymQ*Q` zK>8UgG^DUmq*QaHW09nM$E5Ayq)$45x#5%2S(`j6l^4NmTDk#T3I|@=24K1fV!EVF zYNKcBfHR6MH5#J_3Yz|Axu*A6s8#tLX|SkV6`+0EfS?JMv`MAj*&&OX293Ixj|!tx~b;aq0C8XWMirfNT_7lqmlWPp-QH{K&tz>p&^Qs7xAjDkNT&cp{ju?ujoLit;wuv z3aW{E5$aa1Rtc~HtE~3wtF=j~Ad#@~%CG`Uu#;M_Yw7_MJFFIqss!n;;Q6r_>Y*P> zveK8bD!Z~Qn=`Wa5nU`HDK#OpCegAsD-#v55;^-HI~%h=AxbwJv @@ -1857,7 +1857,7 @@ void RCL_moveCameraWithCollision(RCL_Camera *camera, RCL_Vector2D planeOffset, else\ dir##Collides = floorHeightFunc(s1,s2) > RCL_CAMERA_COLL_STEP_HEIGHT; - // check a collision against non-diagonal square + // check collision against non-diagonal square #define collCheckOrtho(dir,dir2,s1,s2,x)\ if (dir##SquareNew != dir##Square)\ {\ @@ -1882,39 +1882,72 @@ void RCL_moveCameraWithCollision(RCL_Camera *camera, RCL_Vector2D planeOffset, int8_t yCollides = 0; collCheckOrtho(y,x,xSquare,ySquareNew,0) - #define collHandle(dir)\ - if (dir##Collides)\ - cornerNew.dir = (dir##Square) * RCL_UNITS_PER_SQUARE +\ - RCL_UNITS_PER_SQUARE / 2 + dir##Dir * (RCL_UNITS_PER_SQUARE / 2) -\ - dir##Dir;\ - - if (!xCollides && !yCollides) /* if non-diagonal collision happend, corner - collision can't happen */ + if (xCollides || yCollides) { - if (xSquare != xSquareNew && ySquare != ySquareNew) // corner? + if (movesInPlane) + { + #define collHandle(dir)\ + if (dir##Collides)\ + cornerNew.dir = (dir##Square) * RCL_UNITS_PER_SQUARE +\ + RCL_UNITS_PER_SQUARE / 2 + dir##Dir * (RCL_UNITS_PER_SQUARE / 2) -\ + dir##Dir;\ + + collHandle(x) + collHandle(y) + + #undef collHandle + } + else + { + /* Player collides without moving in the plane; this can happen e.g. on + elevators due to vertical only movement. This code can get executed + when force == 1. */ + + RCL_Vector2D squarePos; + RCL_Vector2D newPos; + + squarePos.x = xSquare * RCL_UNITS_PER_SQUARE; + squarePos.y = ySquare * RCL_UNITS_PER_SQUARE; + + newPos.x = + RCL_max(squarePos.x + RCL_CAMERA_COLL_RADIUS + 1, + RCL_min(squarePos.x + RCL_UNITS_PER_SQUARE - RCL_CAMERA_COLL_RADIUS - 1, + camera->position.x)); + + newPos.y = + RCL_max(squarePos.y + RCL_CAMERA_COLL_RADIUS + 1, + RCL_min(squarePos.y + RCL_UNITS_PER_SQUARE - RCL_CAMERA_COLL_RADIUS - 1, + camera->position.y)); + + cornerNew.x = corner.x + (newPos.x - camera->position.x); + cornerNew.y = corner.y + (newPos.y - camera->position.y); + } + } + else + { + /* If no non-diagonal collision is detected, a diagonal/corner collision + can still happen, check it here. */ + + if (xSquare != xSquareNew && ySquare != ySquareNew) { int8_t xyCollides = 0; collCheck(xy,xSquareNew,ySquareNew) if (xyCollides) { - // normally should slide, but let's KISS + // normally should slide, but let's KISS and simply stop any movement cornerNew = corner; } } } - collHandle(x) - collHandle(y) - #undef collCheck - #undef collHandle camera->position.x = cornerNew.x - xDir * RCL_CAMERA_COLL_RADIUS; - camera->position.y = cornerNew.y - yDir * RCL_CAMERA_COLL_RADIUS; + camera->position.y = cornerNew.y - yDir * RCL_CAMERA_COLL_RADIUS; } - if (computeHeight && (movesInPlane || heightOffset != 0 || force)) + if (computeHeight && (movesInPlane || (heightOffset != 0) || force)) { camera->height += heightOffset;