From 146d65ce3b33f10e3829bbed99fa7d6239ab4e03 Mon Sep 17 00:00:00 2001 From: nek0 Date: Wed, 7 Mar 2018 16:01:37 +0100 Subject: [PATCH] fixing ghost boundaries --- src/Test.hs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Test.hs b/src/Test.hs index 80b5c16..38de3cd 100644 --- a/src/Test.hs +++ b/src/Test.hs @@ -153,7 +153,14 @@ updateMap dt = do (checkBoundsCollision pos' npos) (V2 1 1) ((imgObstacle (imgMat (stateData ud) M.! (floor nr, floor nc))) ++ - (imgObstacle (imgMat (stateData ud) M.! (floor pr, floor pc)))) + 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 putAffection ud @@ -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)