fix ghosting

This commit is contained in:
nek0 2018-03-06 16:37:21 +01:00
parent 70e6df88ca
commit ccfc7aaac6

View file

@ -149,10 +149,13 @@ updateMap dt = do
pos'@(V2 or oc) <- E.get pos
vel' <- E.get vel
let npos@(V2 nr nc) = pos' + fmap (* (4 * dt)) vel'
let ent = defEntity'
{ pos = Set $ Prelude.foldl (checkBoundsCollision pos')
npos
(imgObstacle (imgMat (stateData ud) M.! (floor nr, floor nc)))
dpos = npos - pos'
ent = defEntity'
{ pos = Set $ pos' + dpos * Prelude.foldl
(checkBoundsCollision pos' npos)
(V2 1 1)
((imgObstacle (imgMat (stateData ud) M.! (floor nr, floor nc))) ++
(imgObstacle (imgMat (stateData ud) M.! (floor or, floor oc))))
}
return ent
putAffection ud
@ -241,38 +244,40 @@ drawTile ai ctx pr pc row col img =
checkBoundsCollision
:: V2 Double
-> V2 Double
-> V2 Double
-> Boundaries Double
-> V2 Double
checkBoundsCollision
pos'@(V2 or oc) acc@(V2 fr fc) (Boundaries (minr, minc) (maxr, maxc))
pos@(V2 or oc) npos@(V2 fr fc) acc@(V2 mr mc)
(Boundaries (minr, minc) (maxr, maxc))
| (fr - fromIntegral (floor fr) >= minr &&
fr - fromIntegral (floor fr) <= maxr) &&
(fc - fromIntegral (floor fc) >= minc &&
fc - fromIntegral (floor fc) <= maxc) &&
(or - fromIntegral (floor or) < minr ||
or - fromIntegral (floor or) > maxr) =
(V2 or fc)
(V2 (0 * mr) (1 * mc))
| (fr - fromIntegral (floor fr) >= minr &&
fr - fromIntegral (floor fr) <= maxr) &&
(fc - fromIntegral (floor fc) >= minc &&
fc - fromIntegral (floor fc) <= maxc) &&
(oc - fromIntegral (floor oc) < minc ||
oc - fromIntegral (floor oc) > maxc) =
(V2 fr oc)
(V2 (1 * mr) (0 * mc))
| (fr - fromIntegral (floor fr) < minr ||
fr - fromIntegral (floor fr) > maxr) &&
(fc - fromIntegral (floor fc) < minc ||
fc - fromIntegral (floor fc) > maxc) =
acc
(V2 (1 * mr) (1 * mc))
| (fr - fromIntegral (floor fr) < minr ||
fr - fromIntegral (floor fr) > maxr) &&
(fc - fromIntegral (floor fc) >= minc &&
fc - fromIntegral (floor fc) <= maxc) =
acc
(V2 (1 * mr) (1 * mc))
| (fr - fromIntegral (floor fr) >= minr &&
fr - fromIntegral (floor fr) <= maxr) &&
(fc - fromIntegral (floor fc) < minc ||
fc - fromIntegral (floor fc) > maxc) =
acc
(V2 (1 * mr) (1 * mc))
| otherwise =
pos'
(V2 (0 * mr) (0 * mc))