Move laser sound to where it is created

This commit is contained in:
2025-06-01 21:07:56 +01:00
parent c291c7e3da
commit b442001246
6 changed files with 156 additions and 133 deletions
-3
View File
@@ -93,9 +93,6 @@ data HeldParams
, _weaponRepeat :: [Int]
}
| BeamShooterParams
{ _bulGunSound :: Maybe (SoundID, Int) -- if the int is 0, play sound on new channel
-- TODO remove duplicate
}
| BulletShooterParams
{ _muzVel :: GenFloat
, _rifling :: GenFloat
+48 -22
View File
@@ -8,7 +8,6 @@ module Dodge.HeldUse (
mcUseHeld,
) where
import Dodge.Inventory.Path
import Color
import Control.Applicative
import Control.Monad
@@ -22,6 +21,7 @@ import Dodge.Data.MuzzleEffect
import Dodge.Data.World
import Dodge.Gas
import Dodge.Inventory.Lock
import Dodge.Inventory.Path
import Dodge.Item.HeldOffset
import Dodge.Item.Weapon.Bullet
import Dodge.Item.Weapon.Shatter
@@ -63,7 +63,7 @@ heldEffect ::
Creature ->
World ->
World
heldEffect pt = hammerCheck pt heldEffectNoHammerCheck
heldEffect = hammerCheck heldEffectNoHammerCheck
heldEffectNoHammerCheck ::
LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
@@ -77,16 +77,17 @@ type ChainEffect =
World
hammerCheck ::
PressType ->
(LabelDoubleTree ComposeLinkType Item -> t1 -> t2 -> t2) ->
PressType ->
LabelDoubleTree ComposeLinkType Item ->
t1 ->
t2 ->
t2
hammerCheck pt f it cr
hammerCheck f pt it cr
| Just HammerTrigger <- it ^? ldtValue . itUse . heldTriggerType
, isNothing $ lookup MakeAutoLink (it ^. ldtRight)
, pt /= InitialPress = id
, pt /= InitialPress =
id
| otherwise = f it cr
-- | Applies a world effect after an item use cooldown check.
@@ -187,16 +188,15 @@ applyInvLock itm cr = case itm ^? itUse . heldParams . weaponInvLock of
applySoundCME :: Item -> Creature -> World -> World
applySoundCME itm cr = fromMaybe id $ do
(soundid, x) <- itm ^? itUse . heldParams . bulGunSound . _Just
if x > 0
then return $ soundContinue (CrWeaponSound (_crID cr) 0) (_crPos cr) soundid (Just x)
else return $ soundMultiFrom [CrWeaponSound cid j | j <- [0 .. 5]] (_crPos cr) soundid Nothing
return $ if x > 0
then soundContinue (CrWeaponSound cid 0) (_crPos cr) soundid (Just x)
else soundMultiFrom [CrWeaponSound cid j | j <- [0 .. 5]] (_crPos cr) soundid Nothing
where
cid = _crID cr
applyRecoil :: Item -> Creature -> World -> World
applyRecoil itm cr = over (cWorld . lWorld . creatures . ix cid) pushback
applyRecoil itm cr = cWorld . lWorld . creatures . ix (_crID cr) %~ pushback
where
cid = _crID cr
recoilAmount = fromMaybe 0 $ itm ^? itUse . heldParams . recoil
pushback = over crPos (+.+ rotateV (_crDir cr) (V2 ((- recoilAmount) / _crMass cr) 0))
@@ -332,7 +332,7 @@ useLoadedAmmo _ _ (cme, w) (_, Nothing) = (cme, w)
useLoadedAmmo itmtree cr (cme, w) (mzid, Just (mz, x, magtree)) = (,) (cme & cmeSound .~ True) $
removeAmmoFromMag x mid cr . makeMuzzleFlare mz itmtree cr $ case _mzEffect mz of
MuzzleShootBullet -> shootBullet itmtree cr (mz, x, magtree) w
MuzzleLaser -> shootLaser itmtree cr mz w
MuzzleLaser -> creatureShootLaser itmtree cr mz w
MuzzleTesla -> shootTeslaArc itm cr mz w
MuzzleTractor -> shootTractorBeam cr w
MuzzleRLauncher -> createProjectileR itmtree magtree mz cr w
@@ -407,6 +407,7 @@ walkNozzle mzid mz itm cr w = fromMaybe w $ do
shootTractorBeam :: Creature -> World -> World
shootTractorBeam cr w = w & cWorld . lWorld . tractorBeams .:~ tractorBeamAt spos outpos dir power
& soundContinue (CrWeaponSound (_crID cr) 0) cpos tone440sawtoothquietS (Just 2)
where
cpos = _crPos cr
spos = cpos +.+ (_crRad cr + 10) *.* unitVectorAtAngle dir
@@ -426,18 +427,24 @@ tractorBeamAt pos outpos dir power =
where
d = unitVectorAtAngle dir * power
shootLaser :: LabelDoubleTree ComposeLinkType Item -> Creature -> Muzzle -> World -> World
shootLaser itmtree cr mz w =
w
creatureShootLaser ::
LabelDoubleTree ComposeLinkType Item ->
Creature ->
Muzzle ->
World ->
World
creatureShootLaser itmtree cr mz w = w
& randGen .~ g
& cWorld . lWorld . lasers
.:~ Laser
{ _lpType = getLaserDamage itmtree
, _lpPhaseV = getLaserPhaseV itmtree
, _lpPos = pos
, _lpDir = dir
, _lpColor = getLaserColor itmtree
}
& shootLaser (CrWeaponSound (_crID cr) 0) (getLaserDamage itmtree)
(getLaserPhaseV itmtree) pos dir (getLaserColor itmtree)
-- & cWorld . lWorld . lasers
-- .:~ Laser
-- { _lpType = getLaserDamage itmtree
-- , _lpPhaseV = getLaserPhaseV itmtree
-- , _lpPos = pos
-- , _lpDir = dir
-- , _lpColor = getLaserColor itmtree
-- }
where
itm = itmtree ^. ldtValue
(moff, mrot) = heldItemOrient2D itm cr (_mzPos mz) (_mzRot mz)
@@ -446,6 +453,24 @@ shootLaser itmtree cr mz w =
(a, g) = randomR (- inacc, inacc) $ _randGen w
inacc = _mzInaccuracy mz
shootLaser ::
SoundOrigin ->
LaserType ->
Float ->
Point2 ->
Float ->
Color ->
World ->
World
shootLaser so lt pv p dir col w = w & cWorld . lWorld . lasers .:~ Laser
{ _lpType = lt
, _lpPhaseV = pv
, _lpPos = p
, _lpDir = dir
, _lpColor = col
}
& soundContinue so p tone440sawtoothquietS (Just 2)
lasRayAt :: Color -> Int -> Float -> Point2 -> Float -> Laser
lasRayAt col dam phasev pos dir =
Laser
@@ -645,6 +670,7 @@ mcShootAuto itm mc w
shootTeslaArc :: Item -> Creature -> Muzzle -> World -> World
shootTeslaArc itm cr mz w =
w' & cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef . itParams .~ ip
& soundContinue (CrWeaponSound (_crID cr) 0) pos elecCrackleS (Just 2)
where
-- use items item location instead
itRef = cr ^?! crManipulation . manObject . imRootSelectedItem -- unsafe!! TODO change
+4 -3
View File
@@ -20,7 +20,7 @@ sparkGun =
teslaGun :: Item
teslaGun =
defaultHeldItem
& itUse . heldParams .~ BeamShooterParams (Just (elecCrackleS, 2))
& itUse . heldParams .~ BeamShooterParams-- (Just (elecCrackleS, 2))
& itParams .~ teslaParams
& itUse . heldDelay .~ NoDelay
& itUse . heldAim . aimWeight .~ 6
@@ -45,7 +45,8 @@ teslaParams =
laser :: Item
laser =
defaultHeldItem
& itUse . heldParams .~ BeamShooterParams (Just (tone440sawtoothquietS, 2))
-- & itUse . heldParams .~ BeamShooterParams (Just (tone440sawtoothquietS, 2))
& itUse . heldParams .~ BeamShooterParams-- Nothing
& itAmmoSlots .~ singleAmmo ElectricalAmmo
& itUse . heldDelay .~ NoDelay
& itUse . heldTriggerType .~ AutoTrigger
@@ -68,7 +69,7 @@ laser =
tractorGun :: Item
tractorGun =
defaultHeldItem
& itUse . heldParams .~ BeamShooterParams (Just (tone440sawtoothquietS, 2))
& itUse . heldParams .~ BeamShooterParams-- (Just (tone440sawtoothquietS, 2))
& itAmmoSlots .~ singleAmmo ElectricalAmmo
& itUse . heldTriggerType .~ AutoTrigger
& itUse . heldAim . aimMuzzles . ix 0 . mzPos .~ V2 30 0
+2 -4
View File
@@ -141,13 +141,11 @@ rotateCamera cfig w
, Just rotation <-
angleBetween (w ^. input . mousePos)
<$> (w ^. input . heldPos . at SDL.ButtonRight) =
w & wCam . camRot -~ rotation
w & wCam . camRot -~ rotation
| _gameplay_rotate_to_wall cfig
, isNothing $ pkeys ^? ix SDL.ButtonRight =
, isNothing $ w ^? input . mouseButtons . ix SDL.ButtonRight =
rotateToOverlappingWall w
| otherwise = w
where
pkeys = w ^. input . mouseButtons
rotateToOverlappingWall :: World -> World
rotateToOverlappingWall w =