corrected navigation
This commit is contained in:
parent
54b7cbd414
commit
63c76389f0
3 changed files with 15 additions and 14 deletions
|
@ -84,9 +84,9 @@ 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 - hFOV / 2 + x * hFOV / width)
|
let direction = angle (wizardRot wizard - pi / 2 - 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 wStepRow wStepCol) = wizardPos wizard - (fromIntegral . floor <$> wizardPos wizard)
|
||||||
ulCol = col - 1
|
ulCol = col - 1
|
||||||
ulRow = row - 1
|
ulRow = row - 1
|
||||||
brCol = col
|
brCol = col
|
||||||
|
|
|
@ -149,10 +149,10 @@ handleMessage stateContainer readerContainer msg = do
|
||||||
_ -> 0
|
_ -> 0
|
||||||
newPos = wizardPos wiz + ((0.25 *) <$>
|
newPos = wizardPos wiz + ((0.25 *) <$>
|
||||||
case act of
|
case act of
|
||||||
StepForward -> -(angle newRot)
|
StepForward -> -(angle (-newRot))
|
||||||
StepBackward -> angle newRot
|
StepBackward -> angle (-newRot)
|
||||||
StrifeRight -> perp (angle newRot)
|
StrifeRight -> perp (angle (-newRot))
|
||||||
StrifeLeft -> -(perp (angle newRot))
|
StrifeLeft -> -(perp (angle (-newRot)))
|
||||||
_ -> 0
|
_ -> 0
|
||||||
)
|
)
|
||||||
newWiz = wiz
|
newWiz = wiz
|
||||||
|
|
|
@ -180,8 +180,8 @@ sendUpdate curLevel stateContainer tileMap player = do
|
||||||
buildSlice (Player _ (Wizard {..}) _ _) =
|
buildSlice (Player _ (Wizard {..}) _ _) =
|
||||||
let V2 wr wc = wizardPos
|
let V2 wr wc = wizardPos
|
||||||
subCoords = (,) <$> [floor wr - 4 .. floor wr + 4] <*> [floor wc - 4 .. floor wc + 4]
|
subCoords = (,) <$> [floor wr - 4 .. floor wr + 4] <*> [floor wc - 4 .. floor wc + 4]
|
||||||
leftBound = wizardRot + (pi / 4)
|
leftBound = wizardRot - (pi / 4)
|
||||||
rightBound = wizardRot - (pi / 4)
|
rightBound = wizardRot + (pi / 4)
|
||||||
leftLine row = cos leftBound * row
|
leftLine row = cos leftBound * row
|
||||||
rightLine row = sin rightBound * row
|
rightLine row = sin rightBound * row
|
||||||
correctionLeft = if wizardRot < pi / 2 || wizardRot >= 2 * pi
|
correctionLeft = if wizardRot < pi / 2 || wizardRot >= 2 * pi
|
||||||
|
@ -192,12 +192,13 @@ sendUpdate curLevel stateContainer tileMap player = do
|
||||||
else floor
|
else floor
|
||||||
initViewMatrix = M.fromList 9 9 $ map
|
initViewMatrix = M.fromList 9 9 $ map
|
||||||
(\(qr, qc) ->
|
(\(qr, qc) ->
|
||||||
if qc - floor wc <= correctionLeft (leftLine (wr - fromIntegral qr))
|
-- if qc - floor wc >= correctionLeft (leftLine (wr - fromIntegral qr))
|
||||||
&& qc - floor wc >= correctionRight (rightLine (wr - fromIntegral qr))
|
-- && qc - floor wc <= correctionRight (rightLine (wr - fromIntegral qr))
|
||||||
then
|
-- then
|
||||||
M.safeGet qr qc tileMap
|
-- M.safeGet qr qc tileMap
|
||||||
else
|
-- else
|
||||||
Nothing
|
-- Nothing
|
||||||
|
M.safeGet qr qc tileMap
|
||||||
)
|
)
|
||||||
subCoords
|
subCoords
|
||||||
in
|
in
|
||||||
|
|
Loading…
Reference in a new issue