make client move around on the map

This commit is contained in:
Amedeo Molnár 2024-12-17 12:00:51 +01:00
parent e9b0093103
commit 54b7cbd414
3 changed files with 38 additions and 4 deletions

View file

@ -84,7 +84,7 @@ castRay
-> (Float, Float) -- screen dimensions -> (Float, Float) -- screen dimensions
-> Float -- Ray length -> Float -- Ray length
castRay wizard (row, col) (x, y) (width, height) = castRay wizard (row, col) (x, y) (width, height) =
let direction = angle (wizardRot wizard - pi / 2 - hFOV / 2 + x * hFOV / width) let direction = angle (wizardRot wizard - hFOV / 2 + x * hFOV / width)
invdir@(V2 invDirCol invDirRow) = (1 /) <$> direction invdir@(V2 invDirCol invDirRow) = (1 /) <$> direction
wStep@(V2 wStepCol wStepRow) = wizardPos wizard - (fromIntegral . floor <$> wizardPos wizard) wStep@(V2 wStepCol wStepRow) = wizardPos wizard - (fromIntegral . floor <$> wizardPos wizard)
ulCol = col - 1 ulCol = col - 1

View file

@ -17,6 +17,8 @@ import Data.Time
import Data.UUID.V4 import Data.UUID.V4
import Linear (angle, perp)
import System.Random (randomRIO) import System.Random (randomRIO)
-- internal imports -- internal imports
@ -132,8 +134,40 @@ handleMessage stateContainer readerContainer msg = do
mPlayer mPlayer
) )
mclient mclient
-- ClientAction act -> do ClientAction act -> do
-- let mclient = find (\c -> csUUID c == Just clientId) socks players <- STM.atomically $ STM.readTMVar (scPlayers stateContainer)
mPlayer <- STM.atomically $ do
pure $ find (\p -> playerId p == clientId) players
maybe
(pure ())
(\player -> do
let wiz = playerWizard player
rotStep = pi / 18
newRot = wizardRot wiz + case act of
TurnLeft -> -rotStep
TurnRight -> rotStep
_ -> 0
newPos = wizardPos wiz + ((0.25 *) <$>
case act of
StepForward -> -(angle newRot)
StepBackward -> angle newRot
StrifeRight -> perp (angle newRot)
StrifeLeft -> -(perp (angle newRot))
_ -> 0
)
newWiz = wiz
{ wizardRot = newRot
, wizardPos = newPos
}
newPlayer = player
{ playerWizard = newWiz
}
otherPlayers = filter (\p -> playerId p /= clientId) players
newPlayers = newPlayer : otherPlayers
void $ STM.atomically $ STM.swapTMVar (scPlayers stateContainer) newPlayers
sendUpdate curLevel stateContainer (rcMap readerContainer) player
)
mPlayer
x -> logPrintIO (rcLogLevel readerContainer) Verbose ("Unhandled message: " <> show x) x -> logPrintIO (rcLogLevel readerContainer) Verbose ("Unhandled message: " <> show x)
-- | handle received messages -- | handle received messages

View file

@ -30,7 +30,7 @@ newWizard
newWizard pos rot = newWizard pos rot =
Wizard Wizard
{ wizardWands = [] { wizardWands = []
, wizardRot = rot , wizardRot = 0
, wizardPos = pos , wizardPos = pos
, wizardMana = 100 , wizardMana = 100
, wizardHealth = 100 , wizardHealth = 100