fixing stuff up and make collision raycast

This commit is contained in:
nek0 2018-05-01 23:52:40 +02:00
parent db5e368a61
commit d4d6e5bd83
2 changed files with 22 additions and 6 deletions

View file

@ -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

View file

@ -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