add collision check with walls
This commit is contained in:
parent
f52fa7be48
commit
fa3526fe2b
1 changed files with 6 additions and 2 deletions
|
@ -11,13 +11,15 @@ import Control.Monad.State
|
||||||
|
|
||||||
import Data.List
|
import Data.List
|
||||||
|
|
||||||
|
import qualified Data.Matrix as M
|
||||||
|
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
|
||||||
import Data.Time
|
import Data.Time
|
||||||
|
|
||||||
import Data.UUID.V4
|
import Data.UUID.V4
|
||||||
|
|
||||||
import Linear (angle, perp)
|
import Linear
|
||||||
|
|
||||||
import System.Random (randomRIO)
|
import System.Random (randomRIO)
|
||||||
|
|
||||||
|
@ -142,6 +144,7 @@ handleMessage stateContainer readerContainer msg = do
|
||||||
(pure ())
|
(pure ())
|
||||||
(\player -> do
|
(\player -> do
|
||||||
let wiz = playerWizard player
|
let wiz = playerWizard player
|
||||||
|
mat = rcMap readerContainer
|
||||||
rotStep = pi / 18
|
rotStep = pi / 18
|
||||||
newRot = wizardRot wiz + case act of
|
newRot = wizardRot wiz + case act of
|
||||||
TurnLeft -> -rotStep
|
TurnLeft -> -rotStep
|
||||||
|
@ -155,9 +158,10 @@ handleMessage stateContainer readerContainer msg = do
|
||||||
StrifeLeft -> -(perp (angle (-newRot)))
|
StrifeLeft -> -(perp (angle (-newRot)))
|
||||||
_ -> 0
|
_ -> 0
|
||||||
)
|
)
|
||||||
|
doesCollide (V2 prow pcol) = (M.safeGet (floor prow) (floor pcol) mat) == Just Wall
|
||||||
newWiz = wiz
|
newWiz = wiz
|
||||||
{ wizardRot = newRot
|
{ wizardRot = newRot
|
||||||
, wizardPos = newPos
|
, wizardPos = if doesCollide newPos then wizardPos wiz else newPos
|
||||||
}
|
}
|
||||||
newPlayer = player
|
newPlayer = player
|
||||||
{ playerWizard = newWiz
|
{ playerWizard = newWiz
|
||||||
|
|
Loading…
Reference in a new issue