56 lines
1.6 KiB
Haskell
56 lines
1.6 KiB
Haskell
module Dodge.Machine where
|
|
|
|
import Dodge.Base
|
|
import Dodge.Data.World
|
|
import Dodge.Machine.Damage
|
|
import Dodge.SoundLogic
|
|
import Dodge.Wall.Delete
|
|
import Geometry
|
|
import qualified IntMapHelp as IM
|
|
import LensHelp
|
|
import Sound.Data
|
|
|
|
basicMachineUpdate :: (Machine -> World -> World) -> Machine -> World -> World
|
|
basicMachineUpdate f mc = basicMachineApplyDamage mc . f mc
|
|
|
|
machineUpdateLiveDieEff ::
|
|
-- | effect when hp >= 1
|
|
(Machine -> World -> World) ->
|
|
-- | effect (once) when hp < 1
|
|
(Machine -> World -> World) ->
|
|
Machine ->
|
|
World ->
|
|
World
|
|
machineUpdateLiveDieEff livef dief mc
|
|
| _mcHP mc < 1 =
|
|
dief mc
|
|
. (cWorld . machines %~ IM.delete mcid)
|
|
. deleteWallIDs (_mcWallIDs mc)
|
|
| otherwise = livef mc . (cWorld . machines . ix mcid %~ ((mcDamage .~ []) . (mcHP -~ dams)))
|
|
where
|
|
dams = sum $ map _dmAmount $ _mcDamage mc
|
|
mcid = _mcID mc
|
|
|
|
machineUpdateDeathEff ::
|
|
(Machine -> World -> World) ->
|
|
Machine ->
|
|
World ->
|
|
World
|
|
machineUpdateDeathEff f mc
|
|
| _mcHP mc < 1 =
|
|
f mc
|
|
. (cWorld . machines %~ IM.delete mcid)
|
|
. deleteWallIDs (_mcWallIDs mc)
|
|
| otherwise = cWorld . machines . ix mcid %~ ((mcDamage .~ []) . (mcHP -~ dams))
|
|
where
|
|
dams = sum $ map _dmAmount $ _mcDamage mc
|
|
mcid = _mcID mc
|
|
|
|
machineAddSound :: SoundID -> (Machine -> World -> World) -> Machine -> World -> World
|
|
machineAddSound sid f mc w
|
|
| d < 200 = soundContinueVol (1 -0.005 * d) (MachineSound mid) (_mcPos mc) sid (Just 2) $ f mc w
|
|
| otherwise = f mc w
|
|
where
|
|
d = dist (_crPos $ you w) (_mcPos mc)
|
|
mid = _mcID mc
|