Fix blink bug

This commit is contained in:
2022-10-19 23:17:26 +01:00
parent 4ad19aa19d
commit 21dc670c9f
13 changed files with 353 additions and 312 deletions
+103
View File
@@ -0,0 +1,103 @@
{-# LANGUAGE TupleSections #-}
module Dodge.Creature.Action.Blink (
blinkActionMousePos,
blinkActionFail,
unsafeBlinkAction,
) where
import Dodge.Zoning.Wall
import Data.Maybe
import Dodge.Base
import Dodge.Data.World
import Dodge.SoundLogic
import Dodge.WorldEvent.Shockwave
import Geometry
import LensHelp
import Picture
-- | Teleport a creature to the mouse position
blinkActionMousePos :: Creature -> World -> World
blinkActionMousePos cr w =
w
& soundMultiFrom [TeleSound 0, TeleSound 1] p3 teleS Nothing
& blinkDistortions cpos p3
& cWorld . creatures . ix cid . crPos .~ p3
& blinkShockwave cid p3
& inverseShockwaveAt cpos 40 2 2
where
cid = _crID cr
p1 = mouseWorldPos w
cpos = _crPos cr
--p2 = bouncePoint (const True) 1 cpos p1 w
p2 = pushIntoMaybe $ collideCircWalls cpos p1 r (wlsNearSeg cpos p1 w)
r = _crRad cr
p3 = maybe p1 ((+.+ squashNormalizeV (cpos -.- p1)) . fst) p2
--p3 = maybe p1 (const 0) p2
--p3 = maybe p1 fst p2
pushIntoMaybe :: (a, Maybe b) -> Maybe (a,b)
pushIntoMaybe (x,my) = (x,) <$> my
blinkDistortions :: Point2 -> Point2 -> World -> World
blinkDistortions sp ep = cWorld . distortions .++~ distortionBulge
where
distR = 120
distortionBulge =
[ RadialDistortion ep (ep +.+ V2 distR 0) (ep +.+ V2 0 distR) 0.1
, RadialDistortion sp (sp +.+ V2 distR 0) (sp +.+ V2 0 distR) 1.9
]
{- | Teleport a creature to the mouse position.
Can go through walls, if ending up in wall does big damage.
-}
unsafeBlinkAction ::
Creature ->
World ->
World
unsafeBlinkAction cr w
| success =
soundMultiFrom [TeleSound 0, TeleSound 1] mwp teleS Nothing
. blinkDistortions cpos mwp
. set (cWorld . creatures . ix cid . crPos) mwp
. blinkShockwave cid mwp
$ inverseShockwaveAt cpos 40 2 2 w
| otherwise =
w
& blinkActionFail cr
& cWorld . creatures . ix cid . crState . csDamage
.:~ Damage ENTERREMENT 10000 mwp mwp mwp NoDamageEffect
where
success = fromMaybe True $ do
wl <- snd $ collidePointWallsFilter (const True) mwp cpos w
return (isLHS mwp `uncurry` _wlLine wl)
cid = _crID cr
mwp = mouseWorldPos w
cpos = _crPos cr
blinkShockwave ::
-- | Blinking creature ID.
Int ->
Point2 ->
World ->
World
blinkShockwave i p = makeShockwaveAt [i] p 60 1 2 cyan
-- | Like a blink action, but no ingoing distortion
blinkActionFail ::
Creature ->
World ->
World
blinkActionFail cr w =
w
& soundMultiFrom [TeleSound 0, TeleSound 1] p3 teleS Nothing
& cWorld . distortions .:~ distortionBulge
& cWorld . creatures . ix cid . crPos .~ p3
& inverseShockwaveAt cpos 40 2 2
where
distR = 120
distortionBulge = RadialDistortion cpos (cpos +.+ V2 distR 0) (cpos +.+ V2 0 distR) 1.9
cid = _crID cr
p1 = mouseWorldPos w
cpos = _crPos cr
p2 = bouncePoint (const True) 1 cpos p1 w
r = 1.5 * _crRad cr
p3 = maybe p1 (mvPointTowardAtSpeed r cpos . fst) p2