From 9c812f10d3a18ff5811440e1ceef2939d7864148 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sat, 2 Jun 2018 22:04:05 +0200 Subject: [PATCH] stop walking animation when colliding --- src/Test.hs | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/Test.hs b/src/Test.hs index 9ef4229..66dd6ca 100644 --- a/src/Test.hs +++ b/src/Test.hs @@ -371,7 +371,7 @@ updateMap dt = do aId = asId stat nstat = case aiName aId of "walking" - | sqrt (vel' `dot` vel') > 0 -> + | sqrt (colldpos `dot` colldpos) > 0 -> stat { asId = aId { aiDirection = direction vel' rot' @@ -386,7 +386,7 @@ updateMap dt = do , asCurrentFrame = 0 } "standing" - | sqrt (vel' `dot` vel') > 0 -> + | sqrt (colldpos `dot` colldpos) > 0 -> stat { asId = aId { aiDirection = direction vel' rot' @@ -411,26 +411,27 @@ updateMap dt = do if dpc < 0 then [(floor dpc :: Int) .. 0] else [0 .. (ceiling dpc :: Int)]) - ent = unchanged - { pos = Set $ pos' + dpos * Prelude.foldl - (\acc a -> let ret = checkBoundsCollision2 pos' npos dt acc a - in A.log A.Verbose (show ret) ret) - (V2 1 1) - ( - concatMap - (\(dr, dc) -> - let bs = fromMaybe [] (imgObstacle <$> (M.safeGet - (fromIntegral $ floor pr + dr) - (fromIntegral $ floor pc + dc) - (imgMat (stateData ud)))) - in Prelude.map (\(Boundaries (minr, minc) (maxr, maxc))-> - Boundaries - (minr + fromIntegral dr, minc + fromIntegral dc) - (maxr + fromIntegral dr, maxc + fromIntegral dc) - ) bs - ) - (A.log A.Verbose (show lll ++ " " ++ show len) lll) + colldpos = dpos * Prelude.foldl + (\acc a -> let ret = checkBoundsCollision2 pos' npos dt acc a + in A.log A.Verbose (show ret) ret) + (V2 1 1) + ( + concatMap + (\(dr, dc) -> + let bs = fromMaybe [] (imgObstacle <$> (M.safeGet + (fromIntegral $ floor pr + dr) + (fromIntegral $ floor pc + dc) + (imgMat (stateData ud)))) + in Prelude.map (\(Boundaries (minr, minc) (maxr, maxc))-> + Boundaries + (minr + fromIntegral dr, minc + fromIntegral dc) + (maxr + fromIntegral dr, maxc + fromIntegral dc) + ) bs + ) + lll -- (A.log A.Verbose (show lll ++ " " ++ show len) lll) ) + ent = unchanged + { pos = Set $ pos' + colldpos , rot = Set (direction vel' rot') , anim = Set nstat }