Cleanup unused code

This commit is contained in:
2021-08-27 17:10:14 +01:00
parent dd44a93476
commit 1168da0531
4 changed files with 54 additions and 408 deletions
+4 -2
View File
@@ -279,7 +279,8 @@ hvAutoGun = defaultAutoGun
, _itUseTime = 0 , _itUseTime = 0
, _itUse = useAmmoParams , _itUse = useAmmoParams
, _itUseModifiers = , _itUseModifiers =
[ rateIncABI 24 10 (torqueBeforeForcedI 0.1) (torqueAfterI 0.2) [ ammoCheckI
, rateIncABI 24 7 (torqueBeforeForcedI 0.1) (torqueAfterI 0.2)
, withSoundI longGunSound , withSoundI longGunSound
, withThinSmokeI , withThinSmokeI
, withMuzFlareI , withMuzFlareI
@@ -338,7 +339,8 @@ miniGun = defaultAutoGun
, _itUseTime = 0 , _itUseTime = 0
, _itUse = useAmmoParams , _itUse = useAmmoParams
, _itUseModifiers = , _itUseModifiers =
[ withWarmUpI 26 [ ammoCheckI
, withWarmUpI 26
, shootWithSoundForI 28 2 , shootWithSoundForI 28 2
, torqueBeforeForcedI 0.1 , torqueBeforeForcedI 0.1
, withSidePushI 50 , withSidePushI 50
-13
View File
@@ -14,8 +14,6 @@ import Dodge.Item.Draw
import Dodge.Item.Weapon.Bullet import Dodge.Item.Weapon.Bullet
import Dodge.Item.Weapon.TriggerType import Dodge.Item.Weapon.TriggerType
import Dodge.SoundLogic.Synonyms import Dodge.SoundLogic.Synonyms
import Dodge.WorldEvent.HitEffect
import Dodge.Particle.Bullet.HitEffect
import Picture import Picture
import Geometry import Geometry
@@ -54,17 +52,6 @@ autoGun = defaultAutoGun
, _itInvDisplay = basicWeaponDisplay , _itInvDisplay = basicWeaponDisplay
, _wpAmmo = basicBullet , _wpAmmo = basicBullet
} }
autoFireMode, singleFireMode, autoGunNonTwistEff :: Creature -> World -> World
autoFireMode = shootWithSound autoGunSound
. torqueBefore 0.05
$ autoGunNonTwistEff
singleFireMode = hammerCheck $ shootWithSound autoGunSound autoGunNonTwistEff
autoGunNonTwistEff = withRecoil 40
. withRandomDir (autogunSpread/2)
. withMuzFlare
. withVelWthHiteff (V2 50 0) 3
$ destroyOnImpact bulHitCr bulHitWall' bulHitFF'
autoGunPic :: Picture autoGunPic :: Picture
autoGunPic = color red $ polygon $ rectNESW 4 12 (-4) (-12) autoGunPic = color red $ polygon $ rectNESW 4 12 (-4) (-12)
+7 -6
View File
@@ -24,12 +24,13 @@ import Control.Monad.State
bezierGun :: Item bezierGun :: Item
bezierGun = defaultGun bezierGun = defaultGun
{ _itName = "B-GUN" { _itName = "B-GUN"
, _itUse = \_ -> useTargetPos $ \p -> , _itUse = \_ -> useTargetPos $ \p -> shootBezier $ fromJust p -- <- the start point
shootWithSound 0 , _itUseModifiers =
. withMuzFlare [shootWithSoundI 0
. withRecoil 40 , withMuzFlareI
. torqueBefore 0.05 -- I believe that this doesn't affect . withRecoilI 40
$ shootBezier $ fromJust p -- <- the start point . torqueBeforeForcedI 0.05
]
, _itFloorPict = onLayer FlItLayer bezierGunPic , _itFloorPict = onLayer FlItLayer bezierGunPic
, _itEquipPict = pictureWeaponOnAim bezierGunPic , _itEquipPict = pictureWeaponOnAim bezierGunPic
, _itAttachment = Nothing , _itAttachment = Nothing
+43 -387
View File
@@ -1,32 +1,32 @@
{- | {- |
Weapon effects when pulling the trigger. -} Weapon effects when pulling the trigger. -}
module Dodge.Item.Weapon.TriggerType module Dodge.Item.Weapon.TriggerType
-- ( hammerCheckI ( shootWithSoundI
-- , shootWithSoundI , shootWithSoundForI
-- , shootWithSoundForI , withMuzFlareI
-- , withMuzFlareI , withVelWthHiteff
-- , withVelWthHiteff , ammoUseCheckI
-- , ammoUseCheckI , rateIncABI
-- , rateIncABI , torqueBeforeForcedI
-- , torqueBeforeForcedI , torqueAfterI
-- , torqueAfterI , withSoundI
-- , withSoundI , withThickSmokeI
-- , withThickSmokeI , withThinSmokeI
-- , withThinSmokeI , withRandomOffsetI
-- , withRandomOffsetI , withRandomDirI
-- , withRandomDirI , withRecoilI
-- , withRecoilI , withSidePushAfterI
-- , withSidePushAfterI , withSidePushI
-- , withSidePushI , withWarmUpI
-- , withWarmUpI , spreadNumI
-- , spreadNumI , numI
-- , numI , randWalkAngle -- ^ should be made into a modifier, perhaps
-- , randWalkAngle -- ^ should be made into a modifier, perhaps , hammerCheckI
-- , hammerCheckI , hammerCheckL
-- , hammerCheckL , shootL
-- , shootL , useTimeCheckI
-- , useTimeCheckI , ammoCheckI
-- ) where )
where where
import Dodge.Data import Dodge.Data
import Dodge.SoundLogic import Dodge.SoundLogic
@@ -46,6 +46,15 @@ import Data.Maybe
import qualified Data.IntMap.Strict as IM import qualified Data.IntMap.Strict as IM
import Data.Foldable import Data.Foldable
type ChainEffect =
(Item -> Creature -> World -> World)
-> Item
-> Creature -- ^ Creature id
-> World
-> World
withThinSmokeI withThinSmokeI
:: (Item -> Creature -> World -> World) -- ^ Underlying effect :: (Item -> Creature -> World -> World) -- ^ Underlying effect
-> Item -> Item
@@ -58,17 +67,6 @@ withThinSmokeI eff item cr w = eff item cr $ foldl' (flip $ makeThinSmokeAt . (+
pos = _crPos cr +.+ (_crRad cr +0.5) *.* unitVectorAtAngle dir pos = _crPos cr +.+ (_crRad cr +0.5) *.* unitVectorAtAngle dir
ps = (replicateM 5 . randInCirc) 8 & evalState $ _randGen w ps = (replicateM 5 . randInCirc) 8 & evalState $ _randGen w
withThinSmoke
:: (Creature -> World -> World) -- ^ Underlying effect
-> Creature
-> World
-> World
withThinSmoke eff cr w = eff cr $ foldl' (flip $ makeThinSmokeAt . (+.+ pos)) w ps
where
dir = _crDir cr
pos = _crPos cr +.+ (_crRad cr +0.5) *.* unitVectorAtAngle dir
ps = (replicateM 5 . randInCirc) 8 & evalState $ _randGen w
withThickSmokeI withThickSmokeI
:: (Item -> Creature -> World -> World) -- ^ Underlying effect :: (Item -> Creature -> World -> World) -- ^ Underlying effect
-> Item -> Item
@@ -80,57 +78,16 @@ withThickSmokeI eff item cr w = eff item cr $ foldl' (flip $ makeThickSmokeAt .
dir = _crDir cr dir = _crDir cr
pos = _crPos cr +.+ (_crRad cr + 15) *.* unitVectorAtAngle dir pos = _crPos cr +.+ (_crRad cr + 15) *.* unitVectorAtAngle dir
ps = (replicateM 20 . randInCirc) 8 & evalState $ _randGen w ps = (replicateM 20 . randInCirc) 8 & evalState $ _randGen w
withThickSmoke
:: (Creature -> World -> World) -- ^ Underlying effect
-> Creature
-> World
-> World
withThickSmoke eff cr w = eff cr $ foldl' (flip $ makeThickSmokeAt . (+.+ pos)) w ps
where
dir = _crDir cr
pos = _crPos cr +.+ (_crRad cr + 15) *.* unitVectorAtAngle dir
ps = (replicateM 20 . randInCirc) 8 & evalState $ _randGen w
-- TODO create a trigger that does different things on first and continued -- TODO create a trigger that does different things on first and continued
-- fire. -- fire.
{- |
Fires at an increasing rate.
Has different effect after first fire. ammoCheckI :: ChainEffect
Applies ammo check and use cooldown check. -} ammoCheckI eff item cr w
rateIncAB | _wpLoadedAmmo item == 0
:: Int -- ^ Start rate = fromMaybe w (startReloadingWeapon cr w)
-> Int -- ^ End rate | otherwise = eff item cr w
-> ((Creature -> World -> World) -> Creature -> World -> World) -- ^ Extra effect on first fire
-> ((Creature -> World -> World) -> Creature -> World -> World) -- ^ Extra effect on continued fire
-> (Creature -> World -> World) -- ^ Extra effect (always applied)
-> Creature -- ^ Creature id
-> World
-> World
rateIncAB startRate fastRate exeffFirst exeffCont eff cr w
| repeatFire = w
& pointItem %~ ( (itUseRate .~ max fastRate (currentRate - 1))
. (wpLoadedAmmo -~ 1)
. (itUseTime .~ currentRate) )
& exeffCont eff cr
| firstFire = w
& pointItem %~ ( (itUseRate .~ startRate - 1)
. (wpLoadedAmmo -~ 1)
. (itUseTime .~ startRate) )
& exeffFirst eff cr
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
| otherwise = w
where
cid = _crID cr
itRef = _crInvSel cr
item = _crInv cr IM.! itRef
pointItem = creatures . ix cid . crInv . ix itRef
currentRate = _itUseRate item
repeatFire = _wpReloadState item == 0
&& _itUseTime item == 1
&& _wpLoadedAmmo item > 0
firstFire = _wpReloadState item == 0
&& _itUseTime item == 0
&& _wpLoadedAmmo item > 0
reloadCondition = _wpLoadedAmmo item == 0
{- | {- |
Fires at an increasing rate. Fires at an increasing rate.
Has different effect after first fire. Has different effect after first fire.
@@ -156,7 +113,6 @@ rateIncABI startRate fastRate exeffFirst exeffCont eff item cr w
. (wpLoadedAmmo -~ 1) . (wpLoadedAmmo -~ 1)
. (itUseTime .~ startRate) ) . (itUseTime .~ startRate) )
& exeffFirst eff item cr & exeffFirst eff item cr
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
| otherwise = w | otherwise = w
where where
cid = _crID cr cid = _crID cr
@@ -165,11 +121,8 @@ rateIncABI startRate fastRate exeffFirst exeffCont eff item cr w
currentRate = _itUseRate item currentRate = _itUseRate item
repeatFire = _wpReloadState item == 0 repeatFire = _wpReloadState item == 0
&& _itUseTime item == 1 && _itUseTime item == 1
&& _wpLoadedAmmo item > 0
firstFire = _wpReloadState item == 0 firstFire = _wpReloadState item == 0
&& _itUseTime item == 0 && _itUseTime item == 0
&& _wpLoadedAmmo item > 0
reloadCondition = _wpLoadedAmmo item == 0
{- | Apply effect after a warm up. -} {- | Apply effect after a warm up. -}
withWarmUpI withWarmUpI
:: Int -- ^ warm up sound id :: Int -- ^ warm up sound id
@@ -180,7 +133,6 @@ withWarmUpI
-> World -> World
-> World -> World
withWarmUpI soundID f item cr w withWarmUpI soundID f item cr w
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
| _wpReloadState item /= 0 = w | _wpReloadState item /= 0 = w
| curWarmUp < maxWarmUp = w | curWarmUp < maxWarmUp = w
& pointerToItem . wpCurWarmUp +~ 2 & pointerToItem . wpCurWarmUp +~ 2
@@ -194,40 +146,6 @@ withWarmUpI soundID f item cr w
pointerToItem = creatures . ix cid . crInv . ix itRef pointerToItem = creatures . ix cid . crInv . ix itRef
curWarmUp = _wpCurWarmUp item curWarmUp = _wpCurWarmUp item
maxWarmUp = _wpMaxWarmUp item maxWarmUp = _wpMaxWarmUp item
reloadCondition = _wpLoadedAmmo item == 0
{- | Apply effect after a warm up. -}
withWarmUp
:: Int -- ^ warm up sound id
-> (Creature -> World -> World)
-- ^ underlying effect
-> Creature
-> World
-> World
withWarmUp soundID f cr w
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
| _wpReloadState item /= 0 = w
| curWarmUp < maxWarmUp = w
& pointerToItem . wpCurWarmUp +~ 2
& soundFrom (CrWeaponSound cid) soundID 2 0
| otherwise = w
& pointerToItem . wpCurWarmUp .~ maxWarmUp
& f cr
where
cid = _crID cr
itRef = _crInvSel cr
item = _crInv cr IM.! itRef
pointerToItem = creatures . ix cid . crInv . ix itRef
curWarmUp = _wpCurWarmUp item
maxWarmUp = _wpMaxWarmUp item
reloadCondition = _wpLoadedAmmo item == 0
{- | Adds a sound to a creature based world effect.
The sound is emitted from the creature's position. -}
withSound
:: Int -- ^ Sound id
-> (Creature -> World -> World) -- ^ Underlying effect
-> Creature
-> World -> World
withSound soundid f cr = soundOncePos soundid (_crPos cr) . f cr
{- | Adds a sound to a creature based world effect. {- | Adds a sound to a creature based world effect.
The sound is emitted from the creature's position. -} The sound is emitted from the creature's position. -}
withSoundI withSoundI
@@ -248,16 +166,6 @@ withRecoilI recoilAmount eff item cr = eff item cr . over (creatures . ix cid) p
where where
cid = _crID cr cid = _crID cr
pushback = over crPos (+.+ rotateV (_crDir cr) (V2 ((-recoilAmount) / _crMass cr ) 0)) pushback = over crPos (+.+ rotateV (_crDir cr) (V2 ((-recoilAmount) / _crMass cr ) 0))
withRecoil
:: Float -- ^ Recoil amount
-> (Creature -> World -> World)
-- ^ Underlying world effect, takes creature id as input
-> Creature
-> World -> World
withRecoil recoilAmount eff cr = eff cr . over (creatures . ix cid) pushback
where
cid = _crID cr
pushback = over crPos (+.+ rotateV (_crDir cr) (V2 ((-recoilAmount) / _crMass cr ) 0))
{- | Pushes a creature sideways by a random amount. {- | Pushes a creature sideways by a random amount.
Applied before the underlying effect. -} Applied before the underlying effect. -}
withSidePushI withSidePushI
@@ -273,19 +181,6 @@ withSidePushI maxSide eff item cr w = eff item cr $
cid = _crID cr cid = _crID cr
push = over crPos (+.+ rotateV (_crDir cr) (V2 0 (pushAmount / _crMass cr))) push = over crPos (+.+ rotateV (_crDir cr) (V2 0 (pushAmount / _crMass cr)))
(pushAmount, _) = randomR (-maxSide,maxSide) $ _randGen w (pushAmount, _) = randomR (-maxSide,maxSide) $ _randGen w
{- | Pushes a creature sideways by a random amount.
Applied before the underlying effect. -}
withSidePush
:: Float -- ^ Maximal possible side push amount
-> (Creature -> World -> World)
-- ^ Underlying world effect, takes creature id as input
-> Creature
-> World -> World
withSidePush maxSide eff cr w = eff cr . over (creatures . ix cid) push $ w
where
cid = _crID cr
push = over crPos (+.+ rotateV (_crDir cr) (V2 0 (pushAmount / _crMass cr)))
(pushAmount, _) = randomR (-maxSide,maxSide) $ _randGen w
-- consider unifying the pushes using a direction vector -- consider unifying the pushes using a direction vector
{- | Pushes a creature sideways by a random amount. {- | Pushes a creature sideways by a random amount.
Applied after the underlying effect. -} Applied after the underlying effect. -}
@@ -300,19 +195,6 @@ withSidePushAfterI maxSide eff item cr w = over (creatures . ix cid) push . eff
cid = _crID cr cid = _crID cr
push = over crPos (+.+ rotateV (_crDir cr) (V2 0 (pushAmount / _crMass cr))) push = over crPos (+.+ rotateV (_crDir cr) (V2 0 (pushAmount / _crMass cr)))
(pushAmount, _) = randomR (-maxSide,maxSide) $ _randGen w (pushAmount, _) = randomR (-maxSide,maxSide) $ _randGen w
{- | Pushes a creature sideways by a random amount.
Applied after the underlying effect. -}
withSidePushAfter
:: Float -- ^ Maximal possible side push amount
-> (Creature -> World -> World)
-- ^ Underlying world effect, takes creature id as input
-> Creature -- ^ Creature id
-> World -> World
withSidePushAfter maxSide eff cr w = over (creatures . ix cid) push . eff cr $ w
where
cid = _crID cr
push = over crPos (+.+ rotateV (_crDir cr) (V2 0 (pushAmount / _crMass cr)))
(pushAmount, _) = randomR (-maxSide,maxSide) $ _randGen w
{- | Applies a world effect and sound effect after an ammo check. -} {- | Applies a world effect and sound effect after an ammo check. -}
shootWithSoundForI shootWithSoundForI
:: Int -- ^ Sound identifier :: Int -- ^ Sound identifier
@@ -343,56 +225,6 @@ shootWithSoundForI soundid playTime f item cr w
&& _wpLoadedAmmo item > 0 && _wpLoadedAmmo item > 0
reloadCondition = _wpLoadedAmmo item == 0 reloadCondition = _wpLoadedAmmo item == 0
{- | Applies a world effect and sound effect after an ammo check. -} {- | Applies a world effect and sound effect after an ammo check. -}
shootWithSoundFor
:: Int -- ^ Sound identifier
-> Int -- ^ Frames to play
-> (Creature -> World -> World)
-- ^ Shoot effect, takes creature id as input
-> Creature
-> World
-> World
shootWithSoundFor soundid playTime f cr w
| fireCondition = over (pointerToItem . wpLoadedAmmo) (\ammo -> ammo-1)
$ soundFromPos (CrWeaponSound cid) cpos soundid playTime 0
$ set (pointerToItem . itUseTime) (_itUseRate item)
$ f cr w
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
| otherwise = w
where
cid = _crID cr
cpos = _crPos cr
itRef = _crInvSel cr
item = _crInv cr IM.! itRef
pointerToItem = creatures . ix cid . crInv . ix itRef
fireCondition = _wpReloadState item == 0
&& _itUseTime item == 0
&& _wpLoadedAmmo item > 0
reloadCondition = _wpLoadedAmmo item == 0
{- | Applies a world effect and sound effect after an ammo check. -}
shootWithSound
:: Int -- ^ Sound identifier
-> (Creature -> World -> World)
-- ^ Shoot effect, takes creature id as input
-> Creature
-> World
-> World
shootWithSound soundid f cr w
| fireCondition = over (pointerToItem . wpLoadedAmmo) (\ammo -> ammo-1)
$ soundOncePos soundid (_crPos cr)
$ set (pointerToItem . itUseTime) (_itUseRate item)
$ f cr w
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
| otherwise = w
where
cid = _crID cr
itRef = _crInvSel cr
item = _crInv cr IM.! itRef
pointerToItem = creatures . ix cid . crInv . ix itRef
fireCondition = _wpReloadState item == 0
&& _itUseTime item == 0
&& _wpLoadedAmmo item > 0
reloadCondition = _wpLoadedAmmo item == 0
{- | Applies a world effect and sound effect after an ammo check. -}
shootWithSoundI shootWithSoundI
:: Int -- ^ Sound identifier :: Int -- ^ Sound identifier
-> (Item -> Creature -> World -> World) -> (Item -> Creature -> World -> World)
@@ -418,21 +250,6 @@ shootWithSoundI soundid f item cr w
reloadCondition = _wpLoadedAmmo item == 0 reloadCondition = _wpLoadedAmmo item == 0
{- | {- |
Applies a world effect after an item use cooldown check. -} Applies a world effect after an item use cooldown check. -}
useTimeCheck
:: (Creature -> World -> World) -- ^ Underlying effect
-> Creature
-> World
-> World
useTimeCheck f cr w = case theItem ^? itUseTime of
Just 0 -> f cr $ setUseTime w
_ -> w
where
cid = _crID cr
setUseTime = creatures . ix cid . crInv . ix (_crInvSel cr) . itUseTime +~ useRate
theItem = _crInv cr IM.! _crInvSel cr
useRate = fromMaybe 0 $ theItem ^? itUseRate
{- |
Applies a world effect after an item use cooldown check. -}
useTimeCheckI useTimeCheckI
:: (Item -> Creature -> World -> World) -- ^ Underlying effect :: (Item -> Creature -> World -> World) -- ^ Underlying effect
-> Item -> Item
@@ -446,19 +263,6 @@ useTimeCheckI f item cr w = case item ^? itUseTime of
cid = _crID cr cid = _crID cr
setUseTime = creatures . ix cid . crInv . ix (_crInvSel cr) . itUseTime +~ useRate setUseTime = creatures . ix cid . crInv . ix (_crInvSel cr) . itUseTime +~ useRate
useRate = fromMaybe 0 $ item ^? itUseRate useRate = fromMaybe 0 $ item ^? itUseRate
{- | Applies a world effect after a hammer position check. -}
hammerCheck
:: (Creature -> World -> World) -- ^ Underlying effect
-> Creature
-> World
-> World
hammerCheck f cr w = case (_crInv cr IM.! _crInvSel cr) ^? itHammer of
Just HammerUp -> f cr $ setHammerDown w
_ -> setHammerDown w
where
cid = _crID cr
setHammerDown = creatures . ix cid . crInv . ix (_crInvSel cr) . itHammer .~ HammerDown
{- | Applies a world effect after a hammer position check. -} {- | Applies a world effect after a hammer position check. -}
hammerCheckI hammerCheckI
:: (Item -> Creature -> World -> World) -- ^ Underlying effect :: (Item -> Creature -> World -> World) -- ^ Underlying effect
@@ -493,27 +297,6 @@ ammoUseCheckI f item cr w
&& _itUseTime item == 0 && _itUseTime item == 0
&& _wpLoadedAmmo item > 0 && _wpLoadedAmmo item > 0
reloadCondition = _wpLoadedAmmo item == 0 reloadCondition = _wpLoadedAmmo item == 0
{- | Applies a world effect after an ammo check. -}
shoot
:: (Creature -> World -> World)
-- ^ Underlying effect
-> Creature
-> World
-> World
shoot f cr w
| fireCondition = f cr w & pointerToItem %~
( (wpLoadedAmmo -~ 1) . (itUseTime .~ _itUseRate item) )
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
| otherwise = w
where
cid = _crID cr
itRef = _crInvSel cr
item = _crInv cr IM.! itRef
pointerToItem = creatures . ix cid . crInv . ix itRef
fireCondition = _wpReloadState item == 0
&& _itUseTime item == 0
&& _wpLoadedAmmo item > 0
reloadCondition = _wpLoadedAmmo item == 0
{- | Applies a world effect after a hammer position check. {- | Applies a world effect after a hammer position check.
Arbitrary inventory position. -} Arbitrary inventory position. -}
hammerCheckL hammerCheckL
@@ -550,17 +333,6 @@ shootL f cr invid w
&& _itUseTime item == 0 && _itUseTime item == 0
&& _wpLoadedAmmo item > 0 && _wpLoadedAmmo item > 0
reloadCondition = _wpLoadedAmmo item == 0 reloadCondition = _wpLoadedAmmo item == 0
withMuzFlare
:: (Creature -> World -> World) -- ^ Underlying effect
-> Creature
-> World
-> World
withMuzFlare f cr w = tempLightForAt 3 pos . muzzleFlashAt pos2 $ f cr w
where
pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr)
pos2 = _crPos cr +.+ (2 * _crRad cr) *.* unitVectorAtAngle (_crDir cr)
withMuzFlareI withMuzFlareI
:: (Item -> Creature -> World -> World) -- ^ Underlying effect :: (Item -> Creature -> World -> World) -- ^ Underlying effect
-> Item -> Item
@@ -572,17 +344,6 @@ withMuzFlareI f it cr w = tempLightForAt 3 pos . muzzleFlashAt pos2 $ f it cr w
pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr) pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr)
pos2 = _crPos cr +.+ (2 * _crRad cr) *.* unitVectorAtAngle (_crDir cr) pos2 = _crPos cr +.+ (2 * _crRad cr) *.* unitVectorAtAngle (_crDir cr)
{- | Applies the effect to a randomly rotated creature. -} {- | Applies the effect to a randomly rotated creature. -}
withRandomDir
:: Float -- ^ Max possible rotation
-> (Creature -> World -> World)
-- ^ Underlying effect
-> Creature
-> World
-> World
withRandomDir acc f cr w = f (cr & crDir +~ a) $ set randGen g w
where
(a, g) = randomR (-acc,acc) $ _randGen w
{- | Applies the effect to a randomly rotated creature. -}
withRandomDirI withRandomDirI
:: Float -- ^ Max possible rotation :: Float -- ^ Max possible rotation
-> (Item -> Creature -> World -> World) -> (Item -> Creature -> World -> World)
@@ -621,18 +382,6 @@ withRandomOffsetI offsetAmount f item cr w = f item (cr & crPos %~ (+.+ offV)) $
where where
(offsetVal , g) = randomR (-offsetAmount,offsetAmount) $ _randGen w (offsetVal , g) = randomR (-offsetAmount,offsetAmount) $ _randGen w
offV = rotateV (_crDir cr) (V2 0 offsetVal) offV = rotateV (_crDir cr) (V2 0 offsetVal)
{- | Apply the effect to a translated creature. -}
withRandomOffset
:: Float -- ^ Max possible translate
-> (Creature -> World -> World)
-- ^ Underlying effect
-> Creature
-> World
-> World
withRandomOffset offsetAmount f cr w = f (cr & crPos %~ (+.+ offV)) $ set randGen g w
where
(offsetVal , g) = randomR (-offsetAmount,offsetAmount) $ _randGen w
offV = rotateV (_crDir cr) (V2 0 offsetVal)
-- | Rotates a creature with minimum rotation at least 0.1. -- | Rotates a creature with minimum rotation at least 0.1.
-- Rotates the player creature before applying the effect, other creatures after. -- Rotates the player creature before applying the effect, other creatures after.
torqueBeforeForcedI torqueBeforeForcedI
@@ -654,43 +403,6 @@ torqueBeforeForcedI torque feff item cr w
(rot, g) = randomR (-torque,torque) $ _randGen w (rot, g) = randomR (-torque,torque) $ _randGen w
rot' | rot < 0 = rot - 0.1 rot' | rot < 0 = rot - 0.1
| otherwise = rot + 0.1 | otherwise = rot + 0.1
-- | Rotates a creature with minimum rotation at least 0.1.
-- Rotates the player creature before applying the effect, other creatures after.
torqueBeforeForced
:: Float -- ^ Max possible rotation (less the 0.1 forced rotation)
-> (Creature -> World -> World)
-- ^ Underlying effect
-> Creature
-> World
-> World
torqueBeforeForced torque feff cr w
| cid == 0 = feff (cr & crDir +~ rot') $ w
& randGen .~ g
& creatures . ix cid . crDir +~ rot'
& cameraRot +~ rot'
| otherwise = feff cr $ set randGen g $ over (creatures . ix cid . crDir) (+rot') w
where
cid = _crID cr
(rot, g) = randomR (-torque,torque) $ _randGen w
rot' | rot < 0 = rot - 0.1
| otherwise = rot + 0.1
-- | Rotates the player creature before applying an effect.
-- Note this currently (29/4/2021) rotates other creatures /after/ applying the effect.
torqueBefore
:: Float -- ^ Max possible rotation
-> (Creature -> World -> World) -- ^ Underlying effect
-> Creature -- ^ Creature id
-> World
-> World
torqueBefore torque feff cr w
| cid == 0 = feff (cr & crDir +~ rot) $ w
& randGen .~ g
& creatures . ix cid . crDir +~ rot
& cameraRot +~ rot
| otherwise = set randGen g $ over (creatures . ix cid . crDir) (+rot) $ feff cr w
where
cid = _crID cr
(rot, g) = randomR (-torque,torque) $ _randGen w
-- | Rotate a randomly creature after applying an effect. -- | Rotate a randomly creature after applying an effect.
torqueAfterI torqueAfterI
:: Float -- ^ Max possible rotation :: Float -- ^ Max possible rotation
@@ -707,21 +419,6 @@ torqueAfterI torque feff item cr w
(rot, g) = randomR (-torque,torque) $ _randGen w (rot, g) = randomR (-torque,torque) $ _randGen w
rotateScope = creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0)) rotateScope = creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
. itAttachment . _Just . scopePos %~ rotateV rot . itAttachment . _Just . scopePos %~ rotateV rot
-- | Rotate a randomly creature after applying an effect.
torqueAfter
:: Float -- ^ Max possible rotation
-> (Creature -> World -> World) -- ^ Underlying effect
-> Creature -- ^ Creature id
-> World
-> World
torqueAfter torque feff cr w
| cid == 0 = rotateScope $ set randGen g $ over cameraRot (+rot) $ feff cr w
| otherwise = set randGen g $ over (creatures . ix cid . crDir) (+rot) $ feff cr w
where
cid = _crID cr
(rot, g) = randomR (-torque,torque) $ _randGen w
rotateScope = creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
. itAttachment . _Just . scopePos %~ rotateV rot
spreadNumI spreadNumI
:: (Item -> Creature -> World -> World) :: (Item -> Creature -> World -> World)
-> Item -> Item
@@ -736,28 +433,6 @@ spreadNumI eff item cr w = foldr f w dirs
f dir = eff item (cr & crDir +~ dir) f dir = eff item (cr & crDir +~ dir)
spread = _wpSpread item spread = _wpSpread item
numBul = _wpNumBarrels item numBul = _wpNumBarrels item
{- | Create multiple bullets with a given spread, a given amount, given velocity,
given width and given 'HitEffect'. -}
spreadNumVelWthHiteff
:: Float -- ^ Spread
-> Int -- ^ Number of bullets
-> Point2 -- ^ Velocity, x is direction of creature
-> Float -- ^ Bullet width
-> HitEffect -- ^ Effect when hitting creature, wall etc
-> Creature -- ^ Creature id
-> World
-> World
spreadNumVelWthHiteff spread num vel wth eff cr w = over particles (newbuls ++) w
where
cid = _crID cr
newbuls = zipWith
(\pos d -> aGenBulAt (Just cid) pos (rotateV d vel) eff wth)
poss dirs
poss = map ((+.+) $ _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr))
$ (replicateM num . randInCirc) 5 & evalState $ _randGen w
dirs = map (_crDir cr +) $ zipWith (+)
[-spread,-spread+(2*spread/fromIntegral num)..]
(randomRs (0,spread/5) (_randGen w))
numI numI
:: (Item -> Creature -> World -> World) :: (Item -> Creature -> World -> World)
-> Item -> Item
@@ -772,25 +447,6 @@ numI eff item cr w = foldr f w poss
poss = map (rotateV (_crDir cr) . V2 0 . (*5) . (+ cp) . fromIntegral) [0 .. numBul - 1] poss = map (rotateV (_crDir cr) . V2 0 . (*5) . (+ cp) . fromIntegral) [0 .. numBul - 1]
f pos = eff item (cr & crPos %~ (+.+ pos)) f pos = eff item (cr & crPos %~ (+.+ pos))
numBul = _wpNumBarrels item numBul = _wpNumBarrels item
{- | Create a number of bullets side by side with a given velocity,
given width and given 'HitEffect'. -}
numVelWthHitEff
:: Int -- ^ Amount of bullets
-> Point2 -- ^ Velocity, x axis is direction of creature
-> Float -- ^ Bullet width
-> HitEffect -- ^ Effect when hitting creature, wall etc
-> Creature
-> World
-> World
numVelWthHitEff num vel wth eff cr = over particles (newbuls ++)
where
cid = _crID cr
newbuls = map (\p -> aGenBulAt (Just cid) p (rotateV d vel) eff wth) poss
d = _crDir cr
poss = map (+.+ pos) $ take num offsets
maxOffset = fromIntegral num * 2.5 - 2.5
offsets = map (rotateV d . V2 0) [-maxOffset,5-maxOffset..]
pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle d
{- | Uses '_wpSpread' as a parameter for the current offset angle. -} {- | Uses '_wpSpread' as a parameter for the current offset angle. -}
randWalkAngle randWalkAngle
:: Float -- ^ Max offset angle :: Float -- ^ Max offset angle