From fa3526fe2b17eb445fb6a4adf79bd68cd88112d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amedeo=20Moln=C3=A1r?= Date: Wed, 18 Dec 2024 11:40:10 +0100 Subject: [PATCH] add collision check with walls --- src-server/Server/Communication/Handler.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src-server/Server/Communication/Handler.hs b/src-server/Server/Communication/Handler.hs index 6215253..5631ac7 100644 --- a/src-server/Server/Communication/Handler.hs +++ b/src-server/Server/Communication/Handler.hs @@ -11,13 +11,15 @@ import Control.Monad.State import Data.List +import qualified Data.Matrix as M + import Data.Maybe import Data.Time import Data.UUID.V4 -import Linear (angle, perp) +import Linear import System.Random (randomRIO) @@ -142,6 +144,7 @@ handleMessage stateContainer readerContainer msg = do (pure ()) (\player -> do let wiz = playerWizard player + mat = rcMap readerContainer rotStep = pi / 18 newRot = wizardRot wiz + case act of TurnLeft -> -rotStep @@ -155,9 +158,10 @@ handleMessage stateContainer readerContainer msg = do StrifeLeft -> -(perp (angle (-newRot))) _ -> 0 ) + doesCollide (V2 prow pcol) = (M.safeGet (floor prow) (floor pcol) mat) == Just Wall newWiz = wiz { wizardRot = newRot - , wizardPos = newPos + , wizardPos = if doesCollide newPos then wizardPos wiz else newPos } newPlayer = player { playerWizard = newWiz