fixing stuff up and make collision raycast
This commit is contained in:
parent
db5e368a61
commit
d4d6e5bd83
2 changed files with 22 additions and 6 deletions
17
src/Test.hs
17
src/Test.hs
|
@ -52,7 +52,8 @@ loadMap = do
|
||||||
((,) <$> [1 .. nrows mat] <*> [1 .. ncols mat])
|
((,) <$> [1 .. nrows mat] <*> [1 .. ncols mat])
|
||||||
-- liftIO $ A.logIO A.Debug (show exits)
|
-- liftIO $ A.logIO A.Debug (show exits)
|
||||||
(inter, rps) <- liftIO $ placeInteriorIO mat imgmat exits gr
|
(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
|
liftIO $ A.logIO A.Debug $ "number of placed NPCs: " ++ show nnex
|
||||||
npcposs <- placeNPCs inter mat rps gr nnex
|
npcposs <- placeNPCs inter mat rps gr nnex
|
||||||
(nws, _) <- yieldSystemT (worldState ud) $ do
|
(nws, _) <- yieldSystemT (worldState ud) $ do
|
||||||
|
@ -196,7 +197,7 @@ updateMap dt = do
|
||||||
pos'@(V2 pr pc) <- E.get pos
|
pos'@(V2 pr pc) <- E.get pos
|
||||||
vel' <- E.get vel
|
vel' <- E.get vel
|
||||||
let npos@(V2 nr nc) = pos' + fmap (* (4 * dt)) vel'
|
let npos@(V2 nr nc) = pos' + fmap (* (4 * dt)) vel'
|
||||||
dpos = npos - pos'
|
dpos@(V2 dpr dpc) = npos - pos'
|
||||||
ent = defEntity'
|
ent = defEntity'
|
||||||
{ pos = Set $ pos' + dpos * Prelude.foldl
|
{ pos = Set $ pos' + dpos * Prelude.foldl
|
||||||
(\acc a -> let ret = checkBoundsCollision2 pos' npos dt acc a
|
(\acc a -> let ret = checkBoundsCollision2 pos' npos dt acc a
|
||||||
|
@ -215,7 +216,17 @@ updateMap dt = do
|
||||||
(maxr + dr, maxc + dc)
|
(maxr + dr, maxc + dc)
|
||||||
) bs
|
) 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
|
return ent
|
||||||
|
|
11
src/Util.hs
11
src/Util.hs
|
@ -5,6 +5,7 @@ import Affection as A
|
||||||
import Data.Matrix as M
|
import Data.Matrix as M
|
||||||
import qualified Data.HashSet as HS
|
import qualified Data.HashSet as HS
|
||||||
import Data.Graph.AStar
|
import Data.Graph.AStar
|
||||||
|
import Data.Maybe (fromMaybe)
|
||||||
|
|
||||||
import qualified SDL
|
import qualified SDL
|
||||||
import qualified Graphics.Rendering.OpenGL as GL hiding (get)
|
import qualified Graphics.Rendering.OpenGL as GL hiding (get)
|
||||||
|
@ -136,7 +137,9 @@ naviGraph imgmat (V2 r c) =
|
||||||
let list1 =
|
let list1 =
|
||||||
foldl
|
foldl
|
||||||
(\acc (or, oc) ->
|
(\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
|
then V2 (r + or) (c + oc): acc
|
||||||
else acc
|
else acc
|
||||||
)
|
)
|
||||||
|
@ -145,10 +148,12 @@ naviGraph imgmat (V2 r c) =
|
||||||
list2 =
|
list2 =
|
||||||
foldl
|
foldl
|
||||||
(\acc (or, oc) ->
|
(\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
|
&& any null
|
||||||
(map
|
(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)])
|
[(0, oc), (or, 0)])
|
||||||
then V2 (r + or) (c + oc): acc
|
then V2 (r + or) (c + oc): acc
|
||||||
else acc
|
else acc
|
||||||
|
|
Loading…
Reference in a new issue