Refactor shell movement, modularised in a tweakable way

This commit is contained in:
2021-05-26 03:35:30 +02:00
parent 7ca7a2f941
commit f05381be47
9 changed files with 170 additions and 112 deletions
+1 -54
View File
@@ -13,8 +13,6 @@ import Dodge.Default
--import Dodge.Default.Shell
import Dodge.Item.Draw
import Dodge.Particle.Bullet.HitEffect
import Dodge.Particle.Bullet.Spawn
--import Dodge.Item.Weapon.Decoration
import Dodge.Item.Weapon.InventoryDisplay
import Dodge.Item.Weapon.TriggerType
import Dodge.Item.Weapon.ExtraEffect
@@ -83,12 +81,6 @@ pistol = Weapon
, _itTargeting = Nothing
, _itWorldTrigger = Nothing
}
defaultAutoGun :: Item
defaultAutoGun = autoGun
{ _itScrollUp = const id
, _itScrollDown = const id
, _itInvDisplay = basicWeaponDisplay
}
effectGun :: String -> (Creature -> World -> World) -> Item
effectGun name eff = defaultGun
{ _itName = name ++ "Gun"
@@ -161,7 +153,7 @@ rezGun = defaultGun
]
}
teslaGun :: Item
teslaGun = defaultAutoGun
teslaGun = defaultGun
{ _itName = "TESLA"
, _itIdentity = TeslaGun
, _wpMaxAmmo = 200
@@ -261,52 +253,7 @@ tractorGun = defaultAutoGun
, _itAimingRange = 0.5
, _itEquipPict = pictureWeaponOnAim $ color blue $ pictures [polygon $ rectNESW 1.5 6 (-1.5) 0 ]
}
useTargetPos
:: (Maybe Point2 -> Creature -> World -> World)
-> Creature
-> World
-> World
useTargetPos f cr w = case cr ^? crInv . ix (_crInvSel cr) . itTargeting . _Just of
Nothing -> w
Just (g,_) -> f (g w) cr w
bezierGun :: Item
bezierGun = defaultAutoGun
{ _itName = "B-GUN"
, _itUse = \_ -> useTargetPos $ \p ->
shootWithSound 0
. withMuzFlare
. withRecoil 40
. torqueBefore 0.05 -- I believe that this doesn't affect
$ shootBezier $ fromJust p -- <- the start point
, _itAttachment = Nothing
, _itScrollUp = removeItAttachment 0
, _itScrollDown = removeItAttachment 0
, _itHammer = HammerUp
, _itEffect = rbSetTarget
, _itZoom = defaultItZoom
, _itAimingRange = 0
}
shootBezier :: Point2 -> Creature -> World -> World
shootBezier targetp cr w = w & particles %~ (theBullet :)
where
theBullet = aCurveBulAt
(Just cid)
white
startp
(controlp +.+ randPos)
(targetp +.+ randPos')
(destroyOnImpact bulHitCr bulHitWall' bulHitFF')
5
controlp = mouseWorldPos w
cid = _crID cr
dir = _crDir cr
startp = _crPos cr +.+ rotateV dir (_crRad cr + 1,0)
(randPos,randPos') = flip evalState (_randGen w) $ do
a <- randInCirc 10
b <- randInCirc 20
return (a,b)
removeItAttachment :: Int -> Int -> World -> World
removeItAttachment i _ w = w & creatures . ix i . crInv . ix itRef . itAttachment .~ Nothing