Cleanup
This commit is contained in:
+30
-19
@@ -37,7 +37,6 @@ module Dodge.Base.Collide (
|
||||
collide3,
|
||||
) where
|
||||
|
||||
import Linear
|
||||
import Control.Lens
|
||||
import Control.Monad
|
||||
import qualified Data.IntSet as IS
|
||||
@@ -50,24 +49,28 @@ import Dodge.Data.World
|
||||
import Dodge.Zoning
|
||||
import FoldableHelp
|
||||
import Geometry
|
||||
import Linear
|
||||
|
||||
collidePoint :: Point2 -> Point2 -> [Wall] -> (Point2, Maybe Wall)
|
||||
{-# INLINE collidePoint #-}
|
||||
collidePoint sp ep = foldl' f (ep, Nothing)
|
||||
where
|
||||
f (p, mwl) wl
|
||||
= maybe (p, mwl) (,Just wl) . uncurry (intersectSegSeg sp p) . _wlLine $ wl
|
||||
f (p, mwl) wl =
|
||||
maybe (p, mwl) (,Just wl) . uncurry (intersectSegSeg sp p) . _wlLine $ wl
|
||||
|
||||
overlapSegCrs :: Point2 -> Point2 -> [Creature] -> [(Point2, Creature)]
|
||||
{-# INLINE overlapSegCrs #-}
|
||||
overlapSegCrs sp ep =
|
||||
mapMaybe
|
||||
(\cr -> (,cr) <$> fst (intersectCircSeg (cr ^. crPos . _xy) (crRad $ cr ^. crType) sp ep))
|
||||
overlapSegCrs sp ep = mapMaybe f
|
||||
where
|
||||
f cr =
|
||||
(,cr)
|
||||
<$> fst (intersectCircSeg (cr ^. crPos . _xy) (crRad $ cr ^. crType) sp ep)
|
||||
|
||||
doBounce :: Float -> Point2 -> Point2 -> (Point2, Maybe Wall) -> Maybe (Point2, Point2)
|
||||
{-# INLINE doBounce #-}
|
||||
doBounce x sp ep (p, mwl) =
|
||||
mwl <&> \wl ->
|
||||
doBounce x sp ep (p, mwl) = fmap f mwl
|
||||
where
|
||||
f wl =
|
||||
( p +.+ normalizeV (vNormal (uncurry (-.-) (_wlLine wl)))
|
||||
, reflVelWallDamp x wl (ep -.- sp)
|
||||
)
|
||||
@@ -82,7 +85,13 @@ doBounce x sp ep (p, mwl) =
|
||||
--{-# INLINE bounceBall #-}
|
||||
--bounceBall x sp ep r = doBounce x sp ep . collideCircWalls sp ep r
|
||||
|
||||
bouncePoint :: (Wall -> Bool) -> Float -> Point2 -> Point2 -> World -> Maybe (Point2, Point2)
|
||||
bouncePoint ::
|
||||
(Wall -> Bool) ->
|
||||
Float ->
|
||||
Point2 ->
|
||||
Point2 ->
|
||||
World ->
|
||||
Maybe (Point2, Point2)
|
||||
{-# INLINE bouncePoint #-}
|
||||
bouncePoint t x sp ep = doBounce x sp ep . collidePointWallsFilter t sp ep
|
||||
|
||||
@@ -152,19 +161,21 @@ collide3Wall sp wl (ep, mo) = maybe (ep, mo) (,Just (n, OWall wl)) $ intersectSe
|
||||
|
||||
collide3Creature :: Point3 -> Creature -> (Point3, MPO) -> (Point3, MPO)
|
||||
collide3Creature sp cr (ep, m) = fromMaybe (ep, m) $ do
|
||||
h <- crHeight cr
|
||||
(p,n) <- fst $ intersectCylSeg
|
||||
(cr ^. crPos)
|
||||
(crRad $ cr ^. crType)
|
||||
h
|
||||
sp
|
||||
ep
|
||||
return (p, Just (n,OCreature cr))
|
||||
h <- crHeight cr
|
||||
(p, n) <-
|
||||
fst $
|
||||
intersectCylSeg
|
||||
(cr ^. crPos)
|
||||
(crRad $ cr ^. crType)
|
||||
h
|
||||
sp
|
||||
ep
|
||||
return (p, Just (n, OCreature cr))
|
||||
|
||||
crHeight :: Creature -> Maybe Float
|
||||
crHeight cr = case cr ^. crHP of
|
||||
HP {} -> Just 25
|
||||
CrIsCorpse {} -> Just 5
|
||||
HP{} -> Just 25
|
||||
CrIsCorpse{} -> Just 5
|
||||
CrIsGibs -> Nothing
|
||||
CrIsPitted -> Nothing
|
||||
|
||||
|
||||
Reference in New Issue
Block a user