make client move around on the map
This commit is contained in:
parent
e9b0093103
commit
54b7cbd414
3 changed files with 38 additions and 4 deletions
|
@ -84,7 +84,7 @@ castRay
|
|||
-> (Float, Float) -- screen dimensions
|
||||
-> Float -- Ray length
|
||||
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
|
||||
wStep@(V2 wStepCol wStepRow) = wizardPos wizard - (fromIntegral . floor <$> wizardPos wizard)
|
||||
ulCol = col - 1
|
||||
|
|
|
@ -17,6 +17,8 @@ import Data.Time
|
|||
|
||||
import Data.UUID.V4
|
||||
|
||||
import Linear (angle, perp)
|
||||
|
||||
import System.Random (randomRIO)
|
||||
|
||||
-- internal imports
|
||||
|
@ -132,8 +134,40 @@ handleMessage stateContainer readerContainer msg = do
|
|||
mPlayer
|
||||
)
|
||||
mclient
|
||||
-- ClientAction act -> do
|
||||
-- let mclient = find (\c -> csUUID c == Just clientId) socks
|
||||
ClientAction act -> do
|
||||
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)
|
||||
|
||||
-- | handle received messages
|
||||
|
|
|
@ -30,7 +30,7 @@ newWizard
|
|||
newWizard pos rot =
|
||||
Wizard
|
||||
{ wizardWands = []
|
||||
, wizardRot = rot
|
||||
, wizardRot = 0
|
||||
, wizardPos = pos
|
||||
, wizardMana = 100
|
||||
, wizardHealth = 100
|
||||
|
|
Loading…
Reference in a new issue