Fix bug where new sounds didn't overplay old sounds
This commit is contained in:
@@ -159,7 +159,9 @@ isFrictionless cr = case cr ^? crStance . carriage of
|
|||||||
_ -> False
|
_ -> False
|
||||||
|
|
||||||
stepItemUseCooldown :: Creature -> Creature
|
stepItemUseCooldown :: Creature -> Creature
|
||||||
stepItemUseCooldown cr = over (crInv . ix iSel . itUseTime) decreaseToZero cr
|
stepItemUseCooldown cr = cr & crInv . ix iSel %~
|
||||||
|
(itUseTime %~ decreaseToZero) . (wpCurWarmUp %~ decreaseToZero)
|
||||||
|
--( over (crInv . ix iSel . itUseTime) decreaseToZero cr
|
||||||
where
|
where
|
||||||
iSel = _crInvSel cr
|
iSel = _crInvSel cr
|
||||||
|
|
||||||
|
|||||||
+18
-14
@@ -211,23 +211,27 @@ data ItemPos
|
|||||||
| OnFloor { _itFlID :: Int }
|
| OnFloor { _itFlID :: Int }
|
||||||
data Item
|
data Item
|
||||||
= Weapon
|
= Weapon
|
||||||
{ _itName :: String
|
{ _itName :: String
|
||||||
, _wpMaxAmmo :: Int
|
, _wpMaxAmmo :: Int
|
||||||
, _wpLoadedAmmo :: Int
|
, _wpLoadedAmmo :: Int
|
||||||
, _wpAmmo :: Ammo
|
, _wpAmmo :: Ammo
|
||||||
, _wpReloadTime :: Int
|
, _wpReloadTime :: Int
|
||||||
, _wpReloadState :: Int
|
, _wpReloadState :: Int
|
||||||
, _wpReloadType :: ReloadType
|
, _wpReloadType :: ReloadType
|
||||||
, _itUseRate :: Int
|
, _wpMaxWarmUp :: Int
|
||||||
, _itUseTime :: Int
|
, _wpCurWarmUp :: Int
|
||||||
, _itUse :: Item -> Creature -> World -> World
|
, _wpMaxCoolDown :: Int
|
||||||
|
, _wpCurCoolDown :: Int
|
||||||
|
, _itUseRate :: Int
|
||||||
|
, _itUseTime :: Int
|
||||||
|
, _itUse :: Item -> Creature -> World -> World
|
||||||
, _itUseModifiers :: [(Item -> Creature -> World -> World) -> Item -> Creature -> World -> World]
|
, _itUseModifiers :: [(Item -> Creature -> World -> World) -> Item -> Creature -> World -> World]
|
||||||
, _itLeftClickUse :: Maybe (Creature -> Int -> World -> World)
|
, _itLeftClickUse :: Maybe (Creature -> Int -> World -> World)
|
||||||
, _wpSpread :: Float
|
, _wpSpread :: Float
|
||||||
, _wpRange :: Float
|
, _wpRange :: Float
|
||||||
, _itHammer :: HammerPosition
|
, _itHammer :: HammerPosition
|
||||||
, _itFloorPict :: Picture
|
, _itFloorPict :: Picture
|
||||||
, _itMaxStack :: Int
|
, _itMaxStack :: Int
|
||||||
, _itAmount :: Int
|
, _itAmount :: Int
|
||||||
, _itAimingSpeed :: Float
|
, _itAimingSpeed :: Float
|
||||||
, _itAimingRange :: Float
|
, _itAimingRange :: Float
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ defaultGun = Weapon
|
|||||||
, _wpReloadTime = 40
|
, _wpReloadTime = 40
|
||||||
, _wpReloadState = 0
|
, _wpReloadState = 0
|
||||||
, _wpReloadType = ActiveReload
|
, _wpReloadType = ActiveReload
|
||||||
|
, _wpMaxWarmUp = 0
|
||||||
|
, _wpCurWarmUp = 0
|
||||||
|
, _wpMaxCoolDown = 0
|
||||||
|
, _wpCurCoolDown = 0
|
||||||
, _itUseRate = 8
|
, _itUseRate = 8
|
||||||
, _itUseTime = 0
|
, _itUseTime = 0
|
||||||
, _itUse = \_ _ -> id
|
, _itUse = \_ _ -> id
|
||||||
|
|||||||
@@ -291,10 +291,11 @@ ltAutoGun = defaultAutoGun
|
|||||||
, _wpReloadState = 0
|
, _wpReloadState = 0
|
||||||
, _itUseRate = 3
|
, _itUseRate = 3
|
||||||
, _itUseTime = 0
|
, _itUseTime = 0
|
||||||
, _itUse = \_ -> withSidePush 50 $ withVelWthHiteff (V2 30 0) 2 basicBulletEffect
|
, _itUse = useAmmoParams
|
||||||
, _itUseModifiers =
|
, _itUseModifiers =
|
||||||
[ shootWithSoundI 0
|
[ shootWithSoundI 0
|
||||||
, withRandomDirI 0.3
|
, withRandomDirI 0.3
|
||||||
|
, withSidePushI 50
|
||||||
, withMuzFlareI
|
, withMuzFlareI
|
||||||
]
|
]
|
||||||
, _wpSpread = 0.5
|
, _wpSpread = 0.5
|
||||||
@@ -305,6 +306,7 @@ ltAutoGun = defaultAutoGun
|
|||||||
, _itZoom = defaultItZoom
|
, _itZoom = defaultItZoom
|
||||||
, _itEquipPict = pictureWeaponOnAim ltAutoGunPic
|
, _itEquipPict = pictureWeaponOnAim ltAutoGunPic
|
||||||
, _itAimStance = OneHand
|
, _itAimStance = OneHand
|
||||||
|
, _wpAmmo = ltBullet
|
||||||
}
|
}
|
||||||
ltAutoGunPic :: Picture
|
ltAutoGunPic :: Picture
|
||||||
ltAutoGunPic = color green $ pictures
|
ltAutoGunPic = color green $ pictures
|
||||||
@@ -319,9 +321,12 @@ miniGun = defaultAutoGun
|
|||||||
, _wpLoadedAmmo = 150
|
, _wpLoadedAmmo = 150
|
||||||
, _wpReloadTime = 200
|
, _wpReloadTime = 200
|
||||||
, _wpReloadState = 0
|
, _wpReloadState = 0
|
||||||
|
, _wpMaxWarmUp = 100
|
||||||
, _itUseRate = 2
|
, _itUseRate = 2
|
||||||
, _itUseTime = 0
|
, _itUseTime = 0
|
||||||
, _itUse = \_ -> withWarmUp 50 . torqueBefore 0.03 . withSidePush 50 . withRecoil 15
|
, _itUse = \_ -> withWarmUp 50
|
||||||
|
. shootWithSoundFor 28 2
|
||||||
|
. torqueBefore 0.03 . withSidePush 50 . withRecoil 15
|
||||||
. withRandomDir 0.1
|
. withRandomDir 0.1
|
||||||
. withRandomOffset 9
|
. withRandomOffset 9
|
||||||
. withMuzFlare
|
. withMuzFlare
|
||||||
|
|||||||
@@ -12,6 +12,13 @@ basicBullet = BulletAmmo
|
|||||||
, _amBulWth = 2
|
, _amBulWth = 2
|
||||||
, _amBulVel = V2 50 0
|
, _amBulVel = V2 50 0
|
||||||
}
|
}
|
||||||
|
ltBullet :: Ammo
|
||||||
|
ltBullet = BulletAmmo
|
||||||
|
{ _amString = "LTBULLET"
|
||||||
|
, _amBulEff = destroyOnImpact bulHitCr bulHitWall' bulHitFF'
|
||||||
|
, _amBulWth = 2
|
||||||
|
, _amBulVel = V2 40 0
|
||||||
|
}
|
||||||
hvBullet :: Ammo
|
hvBullet :: Ammo
|
||||||
hvBullet = BulletAmmo
|
hvBullet = BulletAmmo
|
||||||
{ _amString = "HVBULLET"
|
{ _amString = "HVBULLET"
|
||||||
|
|||||||
@@ -89,25 +89,23 @@ withWarmUp
|
|||||||
-> Creature
|
-> Creature
|
||||||
-> World
|
-> World
|
||||||
-> World
|
-> World
|
||||||
withWarmUp t f cr w
|
withWarmUp t f cr w
|
||||||
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
|
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
|
||||||
| _wpReloadState item /= 0 = w
|
| _wpReloadState item /= 0 = w
|
||||||
| fState == 0 = w
|
| curWarmUp < maxWarmUp = w
|
||||||
& pointerToItem %~ ( (itUse .~ (\_ -> withWarmUp 100 f)) . (itUseTime .~ 2) )
|
& pointerToItem . wpCurWarmUp +~ 2
|
||||||
| t > 2 = w
|
|
||||||
& pointerToItem %~ ( (itUse .~ (\_ -> withWarmUp (t-1) f)) . (itUseTime .~ 2) )
|
|
||||||
& soundFrom (CrWeaponSound cid) 26 2 0
|
& soundFrom (CrWeaponSound cid) 26 2 0
|
||||||
| t > 0 = w
|
| otherwise = w
|
||||||
& pointerToItem %~ ( (itUse .~ (\_ -> withWarmUp (t-1) f)) . (itUseTime .~ 2) )
|
& pointerToItem . wpCurWarmUp .~ maxWarmUp
|
||||||
| otherwise = w
|
|
||||||
& pointerToItem %~ ( (itUse .~ (\_ -> withWarmUp 1 f)) . (wpLoadedAmmo -~ 1) . (itUseTime .~ 2) )
|
|
||||||
& f cr
|
& f cr
|
||||||
& soundFrom (CrWeaponSound cid) 28 2 0
|
-- & soundFrom (CrWeaponSound cid) 28 2 0
|
||||||
where
|
where
|
||||||
cid = _crID cr
|
cid = _crID cr
|
||||||
itRef = _crInvSel cr
|
itRef = _crInvSel cr
|
||||||
item = _crInv cr IM.! itRef
|
item = _crInv cr IM.! itRef
|
||||||
pointerToItem = creatures . ix cid . crInv . ix itRef
|
pointerToItem = creatures . ix cid . crInv . ix itRef
|
||||||
|
curWarmUp = _wpCurWarmUp item
|
||||||
|
maxWarmUp = _wpMaxWarmUp item
|
||||||
fState = _itUseTime item
|
fState = _itUseTime item
|
||||||
reloadCondition = _wpLoadedAmmo item == 0
|
reloadCondition = _wpLoadedAmmo item == 0
|
||||||
{- | Adds a sound to a creature based world effect.
|
{- | Adds a sound to a creature based world effect.
|
||||||
@@ -133,11 +131,13 @@ withRecoil recoilAmount eff cr = eff cr . over (creatures . ix cid) pushback
|
|||||||
Applied before the underlying effect. -}
|
Applied before the underlying effect. -}
|
||||||
withSidePushI
|
withSidePushI
|
||||||
:: Float -- ^ Maximal possible side push amount
|
:: Float -- ^ Maximal possible side push amount
|
||||||
-> (Creature -> World -> World)
|
-> (Item -> Creature -> World -> World)
|
||||||
-- ^ Underlying world effect, takes creature id as input
|
-- ^ Underlying world effect
|
||||||
|
-> Item
|
||||||
-> Creature
|
-> Creature
|
||||||
-> World -> World
|
-> World -> World
|
||||||
withSidePushI maxSide eff cr w = eff cr . over (creatures . ix cid) push $ w
|
withSidePushI maxSide eff item cr w = eff item cr $
|
||||||
|
w & creatures . ix cid %~ push
|
||||||
where
|
where
|
||||||
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)))
|
||||||
@@ -170,6 +170,32 @@ withSidePushAfter maxSide eff cr w = over (creatures . ix cid) push . eff cr $ w
|
|||||||
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
|
||||||
{- | 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
|
shootWithSound
|
||||||
:: Int -- ^ Sound identifier
|
:: Int -- ^ Sound identifier
|
||||||
-> (Creature -> World -> World)
|
-> (Creature -> World -> World)
|
||||||
|
|||||||
+4
-4
@@ -39,7 +39,7 @@ New sounds with the same keys as
|
|||||||
already playing sounds are merged as follows:
|
already playing sounds are merged as follows:
|
||||||
|
|
||||||
* '_soundChannel' is set to the old value
|
* '_soundChannel' is set to the old value
|
||||||
* if the old '_soundStatus' was 'FadingOut', it set to the new value (can restart playback with 'ToStart')
|
* if the old '_soundStatus' was 'FadingOut', it is set to the new value (can restart playback with 'ToStart')
|
||||||
* other fields are set to the new value.
|
* other fields are set to the new value.
|
||||||
|
|
||||||
In the update:
|
In the update:
|
||||||
@@ -57,8 +57,10 @@ mergeSound :: Sound -> Sound -> Sound
|
|||||||
mergeSound newS oldS
|
mergeSound newS oldS
|
||||||
| _soundStatus oldS == FadingOut
|
| _soundStatus oldS == FadingOut
|
||||||
= newS & soundChannel .~ _soundChannel oldS
|
= newS & soundChannel .~ _soundChannel oldS
|
||||||
| otherwise = newS & soundChannel .~ _soundChannel oldS
|
| _soundChunkID newS == _soundChunkID oldS
|
||||||
|
= newS & soundChannel .~ _soundChannel oldS
|
||||||
& soundStatus .~ _soundStatus oldS
|
& soundStatus .~ _soundStatus oldS
|
||||||
|
| otherwise = newS & soundChannel .~ _soundChannel oldS
|
||||||
|
|
||||||
updateSounds :: Ord a => IM.IntMap Mix.Chunk -> M.Map a Sound -> IO (M.Map a Sound)
|
updateSounds :: Ord a => IM.IntMap Mix.Chunk -> M.Map a Sound -> IO (M.Map a Sound)
|
||||||
updateSounds sd ss = do
|
updateSounds sd ss = do
|
||||||
@@ -156,8 +158,6 @@ setChannelPos :: Int16 -> Mix.Channel -> MaybeT IO Mix.Channel
|
|||||||
setChannelPos a i = do
|
setChannelPos a i = do
|
||||||
_ <- liftIO $ Mix.effectPosition i a 0
|
_ <- liftIO $ Mix.effectPosition i a 0
|
||||||
return i
|
return i
|
||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------------
|
-----------------------------------------------------------------
|
||||||
{- | Set the volume for all sound channels.
|
{- | Set the volume for all sound channels.
|
||||||
Behind the scenes, scales a float [0,1] to an Int [0..128].
|
Behind the scenes, scales a float [0,1] to an Int [0..128].
|
||||||
|
|||||||
Reference in New Issue
Block a user