From d4d6e5bd83297d3ea3be68c8b9de0d55f04bed33 Mon Sep 17 00:00:00 2001 From: nek0 Date: Tue, 1 May 2018 23:52:40 +0200 Subject: [PATCH] fixing stuff up and make collision raycast --- src/Test.hs | 17 ++++++++++++++--- src/Util.hs | 11 ++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Test.hs b/src/Test.hs index c1f44f9..35235c2 100644 --- a/src/Test.hs +++ b/src/Test.hs @@ -52,7 +52,8 @@ loadMap = do ((,) <$> [1 .. nrows mat] <*> [1 .. ncols mat]) -- liftIO $ A.logIO A.Debug (show exits) (inter, rps) <- liftIO $ placeInteriorIO mat imgmat exits gr - let nnex = length (Prelude.filter (\p -> pointType p == RoomExit) rps) + liftIO $ logIO A.Debug ("number of reachpoints: " ++ show (length rps)) + let nnex = length (Prelude.filter (\p -> pointType p /= RoomExit) rps) liftIO $ A.logIO A.Debug $ "number of placed NPCs: " ++ show nnex npcposs <- placeNPCs inter mat rps gr nnex (nws, _) <- yieldSystemT (worldState ud) $ do @@ -196,7 +197,7 @@ updateMap dt = do pos'@(V2 pr pc) <- E.get pos vel' <- E.get vel let npos@(V2 nr nc) = pos' + fmap (* (4 * dt)) vel' - dpos = npos - pos' + dpos@(V2 dpr dpc) = npos - pos' ent = defEntity' { pos = Set $ pos' + dpos * Prelude.foldl (\acc a -> let ret = checkBoundsCollision2 pos' npos dt acc a @@ -215,7 +216,17 @@ updateMap dt = do (maxr + dr, maxc + dc) ) bs ) - ([(0, 0)]) + [ (fromIntegral lrow, fromIntegral lcol) | + lrow <- + [ (min (0 :: Int) (floor (nr - (fromIntegral $ floor nr)))) + .. (max (0 :: Int) (floor (nr - (fromIntegral $ floor nr)))) + ], + lcol <- + [ (min (0 :: Int) (floor (nc - (fromIntegral $ floor nc)))) + .. (max (0 :: Int) (floor (nc - (fromIntegral $ floor nc)))) + ], + fromIntegral lrow / dpr == fromIntegral lcol / dpc + ] ) } return ent diff --git a/src/Util.hs b/src/Util.hs index 631dc91..a26e94b 100644 --- a/src/Util.hs +++ b/src/Util.hs @@ -5,6 +5,7 @@ import Affection as A import Data.Matrix as M import qualified Data.HashSet as HS import Data.Graph.AStar +import Data.Maybe (fromMaybe) import qualified SDL import qualified Graphics.Rendering.OpenGL as GL hiding (get) @@ -136,7 +137,9 @@ naviGraph imgmat (V2 r c) = let list1 = foldl (\acc (or, oc) -> - if null (imgObstacle <$> M.safeGet (r + or) (c + oc) imgmat) + if null + (fromMaybe [] $ + imgObstacle <$> M.safeGet (r + or) (c + oc) imgmat) then V2 (r + or) (c + oc): acc else acc ) @@ -145,10 +148,12 @@ naviGraph imgmat (V2 r c) = list2 = foldl (\acc (or, oc) -> - if null (imgObstacle <$> M.safeGet (r + or) (c + oc) imgmat) + if null (fromMaybe [] $ + imgObstacle <$> M.safeGet (r + or) (c + oc) imgmat) && any null (map - (\(oor, ooc) -> imgObstacle <$> M.safeGet (r + oor) (c + ooc) imgmat) + (\(oor, ooc) -> fromMaybe [] $ + imgObstacle <$> M.safeGet (r + oor) (c + ooc) imgmat) [(0, oc), (or, 0)]) then V2 (r + or) (c + oc): acc else acc