This commit is contained in:
2022-06-26 01:54:00 +01:00
parent ac9181e1a1
commit 7532c4cafb
2 changed files with 18 additions and 11 deletions
+12 -9
View File
@@ -5,6 +5,7 @@ module Dodge.Base.Collide
, collidePointWallsWall , collidePointWallsWall
, collidePointWallsFilterStream , collidePointWallsFilterStream
, reflectPointWallsDamp , reflectPointWallsDamp
, reflectCircWallsDamp
, hasButtonLOS , hasButtonLOS
, reflectPointWalls , reflectPointWalls
, ssfold , ssfold
@@ -72,15 +73,16 @@ hasButtonLOS p1 p2 = not
. collidePointTestFilter (not . _wlTouchThrough) p1 p2 . collidePointTestFilter (not . _wlTouchThrough) p1 p2
. wallsAlongLine p1 p2 . wallsAlongLine p1 p2
--hitPointLines reflectCircWallsDamp :: Float -> Point2 -> Point2 -> Float -> Stream (Of Wall) Identity ()
-- :: Point2 -> Maybe (Point2,Point2)
-- -> Point2 reflectCircWallsDamp x sp ep r w = do
-- -> [(Point2,Point2)] wl <- mwl
-- -> Maybe (Point2,(Point2,Point2)) return (p +.+ normalizeV (vNormal (uncurry (-.-) (_wlLine wl)))
--hitPointLines p1 p2 , reflVelWallDamp x wl (ep -.- sp)
-- = safeMinimumOn (dist p1 . fst) )
-- . mapMaybe where
-- (\(x,y) -> (, (x,y)) <$> intersectSegSeg p1 p2 x y) (p, mwl) = collideCircWallsStream sp ep r w
reflectPointWallsDamp :: (Wall -> Bool) -> Float -> Point2 -> Point2 -> World -> Maybe (Point2,Point2) reflectPointWallsDamp :: (Wall -> Bool) -> Float -> Point2 -> Point2 -> World -> Maybe (Point2,Point2)
reflectPointWallsDamp t x sp ep w = do reflectPointWallsDamp t x sp ep w = do
wl <- mwl wl <- mwl
@@ -321,6 +323,7 @@ overlapCircWalls p r = S.mapMaybe dointersect
dointersect wl = f (_wlLine wl) <&> (,wl) dointersect wl = f (_wlLine wl) <&> (,wl)
f (a,b) = intersectSegSeg p (p -.- r *.* vNormal (normalizeV (a -.- b))) a b f (a,b) = intersectSegSeg p (p -.- r *.* vNormal (normalizeV (a -.- b))) a b
-- note that this does not push the circle away from the wall at all
collideCircWallsStream :: Point2 -> Point2 -> Float -> Stream (Of Wall) Identity () collideCircWallsStream :: Point2 -> Point2 -> Float -> Stream (Of Wall) Identity ()
-> (Point2, Maybe Wall) -> (Point2, Maybe Wall)
collideCircWallsStream sp ep rad = runIdentity collideCircWallsStream sp ep rad = runIdentity
+6 -2
View File
@@ -52,7 +52,10 @@ moveGrenade pj w
| _pjTimer pj <= 0 = w | _pjTimer pj <= 0 = w
& props %~ IM.delete pID & props %~ IM.delete pID
& _pjPayload pj (_prPos (_props w IM.! pID)) & _pjPayload pj (_prPos (_props w IM.! pID))
| otherwise = case collideCircWallsList oldPos newPos 4 $ wallsNearPoint' newPos w of -- this should maybe
-- be wallsAlongLine
-- or something vvv
| otherwise = case reflectCircWallsDamp 1 oldPos newPos 4 $ wallsNearPoint newPos w of
Nothing -> w & props . ix pID %~ normalUpdate Nothing -> w & props . ix pID %~ normalUpdate
Just (p,v) -> w Just (p,v) -> w
& soundStart (Tap 0) p tapQuietS Nothing & soundStart (Tap 0) p tapQuietS Nothing
@@ -159,6 +162,7 @@ throwArmReset x = ItInvEffect {_ieInv = f ,_ieCounter = x }
-- _ -> w' -- _ -> w'
-- pos = fromMaybe (V2 0 0) $ w ^? props . ix pjid . pjPos -- pos = fromMaybe (V2 0 0) $ w ^? props . ix pjid . pjPos
-- TODO hive out movement and share with moveGrenade
moveRemoteBomb :: Int -> Int -> Int -> World -> World moveRemoteBomb :: Int -> Int -> Int -> World -> World
moveRemoteBomb itid time pID w moveRemoteBomb itid time pID w
| time < -4 = updatePicture | time < -4 = updatePicture
@@ -182,7 +186,7 @@ moveRemoteBomb itid time pID w
-- this is hacky, should use a version of collidePointWalls' that collides -- this is hacky, should use a version of collidePointWalls' that collides
-- circles and walls -- circles and walls
invShift x = x -.- 5 *.* normalizeV (_pjVel pj) invShift x = x -.- 5 *.* normalizeV (_pjVel pj)
hitWl = collideCircWallsList oldPos newPos 4 $ wallsNearPoint' newPos w hitWl = reflectCircWallsDamp 1 oldPos newPos 4 $ wallsNearPoint newPos w
finalPos = maybe newPos (invShift . fst) hitWl finalPos = maybe newPos (invShift . fst) hitWl
setV v = set (props . ix pID . pjVel) v setV v = set (props . ix pID . pjVel) v
updateV = maybe id (setV . snd) hitWl updateV = maybe id (setV . snd) hitWl