add collision check with walls

This commit is contained in:
Amedeo Molnár 2024-12-18 11:40:10 +01:00
parent f52fa7be48
commit fa3526fe2b

View file

@ -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