From c14c652360b16db811966548a5edede8b03181a1 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sun, 13 May 2018 14:05:15 +0200 Subject: [PATCH] cyber entomology --- src/Test.hs | 63 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/src/Test.hs b/src/Test.hs index 19c2358..06bc2b7 100644 --- a/src/Test.hs +++ b/src/Test.hs @@ -199,20 +199,29 @@ updateMap dt = do let npos@(V2 nr nc) = pos' + fmap (* (4 * dt)) vel' dpos@(V2 dpr dpc) = npos - pos' len = sqrt (dpos `dot` dpos) - lll = Prelude.map (\i -> - let lrow = - [ (nr - (fromIntegral $ floor nr)) - , (nr - (fromIntegral $ floor nr)) + (dpr / len) - .. - ] - lcol = - [ (nc - (fromIntegral $ floor nc)) - , (nc - (fromIntegral $ floor nc)) + (dpc / len) - .. - ] - in (fromIntegral (floor (lrow !! i)), fromIntegral (floor (lcol !! i))) - ) - [ 0 .. floor len] + lll = (,) + <$> ( + if dpr < 0 + then [(floor dpr :: Int) .. 0] + else [0 .. (ceiling dpr :: Int)]) + <*> ( + if dpc < 0 + then [(floor dpc :: Int) .. 0] + else [0 .. (ceiling dpc :: Int)]) + -- lll = Prelude.map (\i -> + -- let lrow = + -- [ (nr - (fromIntegral $ floor nr)) + -- , (nr - (fromIntegral $ floor nr)) + (dpr / len) + -- .. + -- ] + -- lcol = + -- [ (nc - (fromIntegral $ floor nc)) + -- , (nc - (fromIntegral $ floor nc)) + (dpc / len) + -- .. + -- ] + -- in (fromIntegral (floor (lrow !! i)), fromIntegral (floor (lcol !! i))) + -- ) + -- [ 0 .. floor len] ent = defEntity' { pos = Set $ pos' + dpos * Prelude.foldl (\acc a -> let ret = checkBoundsCollision2 pos' npos dt acc a @@ -222,19 +231,16 @@ updateMap dt = do concatMap (\(dr, dc) -> let bs = fromMaybe [] (imgObstacle <$> (M.safeGet - (floor (nr + dr)) - (floor (nc + dc)) + (fromIntegral $ floor nr + dr) + (fromIntegral $ floor nc + dc) (imgMat (stateData ud)))) in Prelude.map (\(Boundaries (minr, minc) (maxr, maxc))-> Boundaries - (minr + dr, minc + dc) - (maxr + dr, maxc + dc) + (minr + fromIntegral dr, minc + fromIntegral dc) + (maxr + fromIntegral dr, maxc + fromIntegral dc) ) bs ) - (A.log - A.Verbose - ("paassing relative tiles: " ++ show lll ++ " " ++ show len) - lll) + lll ) } return ent @@ -367,10 +373,13 @@ checkBoundsCollision2 -> V2 Double checkBoundsCollision2 pre@(V2 pr pc) next@(V2 nr nc) dt acc (Boundaries (minr, minc) (maxr, maxc)) - | colltr < 0 && colltc < 0 = V2 0 0 - | colltr < 0 && colltc >= 0 = (V2 0 1) * acc - | colltc < 0 && colltr >= 0 = (V2 1 0) * acc - | otherwise = acc + -- | colltr < 0 && colltc < 0 = A.log A.Debug (show (colltr, colltc)) (V2 (colltr / dt) (colltc / dt)) + | (colltr < 0 && colltc < 0) || (inrow && incol) = A.log A.Debug ("both " ++ show (colltr, colltc)) (V2 0 0) + -- | colltr < 0 && colltc >= dt = (V2 (colltr / dt) 1) + | colltr < 0 && incol = (A.log A.Debug ("row fixed " ++ show (colltr, colltc))(V2 0 1)) * acc + -- | colltc < 0 && colltc >= dt = (V2 1 (colltr / dt)) + | colltc < 0 && inrow = (A.log A.Debug ("col fixed " ++ show (colltr, colltc))(V2 1 0)) * acc + | otherwise = acc where vel@(V2 vr vc) = fmap (/ dt) (next - pre) colltr @@ -381,3 +390,5 @@ checkBoundsCollision2 | vc > 0 = (((fromIntegral (floor nc :: Int)) + minc - 0.15) - nc) / vc | vc < 0 = (((fromIntegral (floor nc :: Int)) + maxc + 0.15) - nc) / vc | otherwise = 0 + inrow = pr > minr && pr < maxr + incol = pc > minc && pc < maxc