25 lines
920 B
Haskell
25 lines
920 B
Haskell
module Dodge.Creature.Impulse.Flee where
|
|
|
|
import Control.Lens
|
|
import Linear
|
|
import Dodge.Data.World
|
|
import FoldableHelp
|
|
import Geometry
|
|
|
|
retreatPointForFrom :: Float -> World -> Creature -> Point2 -> Maybe Point2
|
|
retreatPointForFrom d _ cr p =
|
|
safeMinimumOn (dist cpos) $
|
|
divideCircle 10 p d
|
|
where
|
|
cpos = cr ^. crPos . _xy
|
|
|
|
-- = head $ sortBy (compare `on` (\p -> dist p ypos < 300)) $ retreatP'' : retreatPs
|
|
-- where
|
|
-- retreatPs = sortBy (compare `on` dist cpos) $ map f $ nRaysRad 8 400
|
|
-- where f p = fromMaybe (ypos +.+ p) $ fmap fst
|
|
-- $ reflectPointWalls ypos (ypos +.+ p) (wallsAlongLine ypos (ypos +.+ p) w)
|
|
-- retreatP' = cpos +.+ 300 *.* (cpos -.- ypos)
|
|
-- retreatP'' = fromMaybe retreatP' $ fmap fst
|
|
-- $ reflectPointWalls ypos retreatP'
|
|
-- $ wallsAlongLine ypos retreatP' w
|