Partially implement separate blocks

This commit is contained in:
2021-10-26 22:53:49 +01:00
parent d136fd910c
commit 12d43f9cf0
15 changed files with 145 additions and 115 deletions
+7 -10
View File
@@ -1,16 +1,13 @@
module Dodge.WorldEvent.DamageBlock
( damageBlocksBy
)
where
import Dodge.Data
import Data.Maybe
import Control.Lens
{- | Given a wall, if it is a damageable block
- then damage it and connecting walls by a certain amount. -}
damageBlocksBy :: Int -> Wall -> World -> World
{-# INLINE damageBlocksBy #-}
damageBlocksBy x wall w
| isJust (wall ^? blHP) = foldr (\j -> walls . ix j . blHP -~ x) w (_blIDs wall)
| otherwise = w
damageBlocksBy :: Int -> Wall -> World -> World
damageBlocksBy x wl = case wl ^? wlBlockID of
Just blid -> blocks . ix blid . blHPs %~ reduceHeadBy x
Nothing -> id
where
reduceHeadBy y (z:zs) = z - y : zs
reduceHeadBy _ [] = []