diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-04-17 23:41:35 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-04-17 23:41:35 +0100 |
commit | 7a8af18d0e1003c26eb595b5faa71e51da6286a6 (patch) | |
tree | d94ea6897570e12d9c044c40e82e9c05921ba64d /src/Game/Entities/Blast.hs | |
parent | d333eca8c0761e39781af0711a54044cd5ea3c10 (diff) | |
download | space-plat-hs-7a8af18d0e1003c26eb595b5faa71e51da6286a6.tar.gz space-plat-hs-7a8af18d0e1003c26eb595b5faa71e51da6286a6.zip |
Added new shooter enemy
Diffstat (limited to 'src/Game/Entities/Blast.hs')
-rw-r--r-- | src/Game/Entities/Blast.hs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Game/Entities/Blast.hs b/src/Game/Entities/Blast.hs new file mode 100644 index 0000000..6e9fec2 --- /dev/null +++ b/src/Game/Entities/Blast.hs @@ -0,0 +1,40 @@ +module Game.Entities.Blast (mkBlast) where + +import Data.Bits (Bits (..)) +import Game.Entities.Const +import Game.Entities.Types +import qualified Game.Sprites as S + +mkBlast :: S.SpriteSheet -> Int -> Int -> Dir -> Collision -> IsBlocked -> IO Entity +mkBlast sprites x y dir playerCollision isBlocked = do + s <- S.get sprites "blast" + pure + Entity + { typ = TypeEnemy, + x = x, + y = y, + delay = frameDelay, + frame = 0, + set = 0, + jumping = False, + gravity = gravityOff, + dir = dir, + sprite = s, + update = updateBlast playerCollision isBlocked, + destroy = False, + actions = [], + dat = NoData + } + +updateBlast :: Collision -> IsBlocked -> Entity -> IO Entity +updateBlast touchedPlayer isBlocked e = do + touched <- touchedPlayer e + pure $ if touched then e {destroy = True, actions = [ActionHitPlayer, ActionAddEffect (e.x + 4) e.y "impact"]} else update + where + update + | e.dir == DirLeft && isBlocked (e.x - 1) (e.y + 4) = e {destroy = True, actions = [ActionAddEffect e.x e.y "impact"]} + | e.dir == DirLeft = updatedFrame {x = e.x - 1} + | e.dir == DirRight && isBlocked (e.x + 16) (e.y + 4) = e {destroy = True, actions = [ActionAddEffect (e.x + 8) e.y "impact"]} + | e.dir == DirRight = updatedFrame {x = e.x + 1} + | otherwise = updatedFrame + updatedFrame = if e.delay > 0 then e {delay = e.delay - 1} else e {delay = frameDelay, frame = e.frame `xor` 1} |