Refactor crPos to be a V3
This commit is contained in:
@@ -6,6 +6,7 @@ module Dodge.WallCreatureCollisions (
|
||||
crOnWall,
|
||||
) where
|
||||
|
||||
import Linear
|
||||
import Dodge.Creature.Radius
|
||||
import Control.Lens
|
||||
import Data.Maybe
|
||||
@@ -35,15 +36,15 @@ colCrWall w c
|
||||
-- c'' = c' & crPos %~ pushOutFromWalls rad ls
|
||||
--c' = c & crPos %~ pushOutFromWalls' rad (reverse ls)
|
||||
c' =
|
||||
c & crPos
|
||||
c & crPos . _xy
|
||||
%~ pushOutFromCorners r ls'
|
||||
. pushOutFromWalls r ls'
|
||||
. fst
|
||||
. flip (collidePoint p1) wls -- check push throughs
|
||||
-- . flip (collidePointWalls' p1) wls -- check push throughs
|
||||
r = crRad (c ^. crType) + wallBuffer
|
||||
p1 = _crOldPos c
|
||||
p2 = _crPos c
|
||||
p1 = c ^. crOldPos . _xy
|
||||
p2 = c ^. crPos . _xy
|
||||
ls = _wlLine <$> wls
|
||||
ls' = filter (uncurry $ isLHS p1) ls
|
||||
wls = filter (not . _wlWalkable) $ wlsNearRect (p2 +.+ V2 r r) (p2 -.- V2 r r) w
|
||||
@@ -53,7 +54,8 @@ wallBuffer :: Float
|
||||
wallBuffer = 0
|
||||
|
||||
pushCreatureOutFromWalls :: [(Point2, Point2)] -> Creature -> Creature
|
||||
pushCreatureOutFromWalls ls cr = cr & crPos %~ pushOutFromWalls (crRad (cr ^. crType)) ls
|
||||
pushCreatureOutFromWalls ls cr = cr & crPos . _xy
|
||||
%~ pushOutFromWalls (crRad (cr ^. crType)) ls
|
||||
|
||||
-- the following tests whether or not a point is on a wall, and if so pushes it
|
||||
-- out from the wall
|
||||
@@ -74,13 +76,13 @@ pushOutFromWalls rad wls p1 = case (getFirst . foldMap (First . pushOutFromWall
|
||||
pushOrCrush :: [(Point2, Point2)] -> Creature -> Creature
|
||||
pushOrCrush wls cr = case mapMaybe (pushOutFromWall (crRad (cr ^. crType)) cpos) wls of
|
||||
[] -> cr
|
||||
(p : _) -> cr & crPos .~ p
|
||||
(p : _) -> cr & crPos . _xy .~ p
|
||||
where
|
||||
-- (_:p:_) -> cr
|
||||
-- & crPos .~ p
|
||||
-- & crState . crDamage %~ ( Blunt 50 cpos cpos cpos : )
|
||||
|
||||
cpos = _crPos cr
|
||||
cpos = cr ^. crPos . _xy
|
||||
|
||||
-- note the inclusion of endpoints in circOnSeg
|
||||
crOnWall :: Creature -> World -> Bool
|
||||
@@ -89,7 +91,7 @@ crOnWall cr =
|
||||
. filter (not . _wlWalkable)
|
||||
. wlsNearPoint p
|
||||
where
|
||||
p = _crPos cr
|
||||
p = cr ^. crPos . _xy
|
||||
r = crRad (cr ^. crType)
|
||||
|
||||
-- assumes that the wall is orientated
|
||||
@@ -99,9 +101,9 @@ pushOutFromWall rad cp2 (wp1, wp2)
|
||||
| isOnWall = Just newP
|
||||
| otherwise = Nothing
|
||||
where
|
||||
norm = errorNormalizeV 61 $ vNormal (wp1 -.- wp2)
|
||||
wp1' = wp1 +.+ rad *.* norm
|
||||
wp2' = wp2 +.+ rad *.* norm
|
||||
n = errorNormalizeV 61 $ vNormal (wp1 -.- wp2)
|
||||
wp1' = wp1 +.+ rad *.* n
|
||||
wp2' = wp2 +.+ rad *.* n
|
||||
newP = errorClosestPointOnLine 5 wp1' wp2' cp2
|
||||
isOnWall = circOnSegNoEndpoints wp1 wp2 cp2 rad
|
||||
|
||||
|
||||
Reference in New Issue
Block a user