fixing ghost boundaries

This commit is contained in:
nek0 2018-03-07 16:01:37 +01:00
parent 4405539bd8
commit 146d65ce3b

View file

@ -153,6 +153,13 @@ updateMap dt = do
(checkBoundsCollision pos' npos)
(V2 1 1)
((imgObstacle (imgMat (stateData ud) M.! (floor nr, floor nc))) ++
Prelude.map (\(Boundaries (minr, minc) (maxr, maxc)) ->
let deltar = fromIntegral (floor nr - floor pr)
deltac = fromIntegral (floor nc - floor pc)
in Boundaries
(minr + deltar, minc + deltac)
(maxr + deltar, maxc + deltac)
)
(imgObstacle (imgMat (stateData ud) M.! (floor pr, floor pc))))
}
return ent
@ -180,8 +187,8 @@ drawTile ai ctx pr pc row col img =
drawImage
drawPlayer
else do
if any (\maxr -> pr <= (fromIntegral (floor pr :: Int)) + maxr) maxrs &&
any (\minc -> pc >= (fromIntegral (floor pc :: Int)) + minc) mincs
if all (\maxr -> pr <= (fromIntegral (floor pr :: Int)) + maxr) maxrs &&
all (\minc -> pc >= (fromIntegral (floor pc :: Int)) + minc) mincs
then do
drawPlayer
drawImage
@ -256,24 +263,24 @@ checkBoundsCollision
where
ntestr
| ndistr <= hheight + 0.07 = True
| ncdistsq <= 0.005 = True
-- | ncdistsq <= 0.005 = True
| otherwise = False
ntestc
| ndistc <= hwidth + 0.07 = True
| ncdistsq <= 0.005 = True
-- | ncdistsq <= 0.005 = True
| otherwise = False
testr
| distr <= hheight + 0.07 = True
| cdistsq <= 0.005 = True
-- | cdistsq <= 0.005 = True
| otherwise = False
testc
| distc <= hwidth + 0.07 = True
| cdistsq <= 0.005 = True
-- | cdistsq <= 0.005 = True
| otherwise = False
ndistr = abs ((fr - fromIntegral (floor fr :: Int)) - (minr + hheight))
ndistc = abs ((fc - fromIntegral (floor fc :: Int)) - (minc + hwidth))
distr = abs ((pr - fromIntegral (floor pr :: Int)) - (minr + hheight))
distc = abs ((pc - fromIntegral (floor pc :: Int)) - (minc + hwidth))
ndistr = abs (fr - (fromIntegral (floor fr :: Int) + (minr + hheight)))
ndistc = abs (fc - (fromIntegral (floor fc :: Int) + (minc + hwidth)))
distr = abs (pr - (fromIntegral (floor fr :: Int) + (minr + hheight)))
distc = abs (pc - (fromIntegral (floor fc :: Int) + (minc + hwidth)))
hheight = (maxr - minr) / 2
hwidth = (maxc - minc) / 2
ncdistsq = (ndistr - hheight) ^ (2 :: Int) + (ndistc - hwidth) ^ (2 :: Int)