From 7a8af18d0e1003c26eb595b5faa71e51da6286a6 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Mon, 17 Apr 2023 23:41:35 +0100 Subject: Added new shooter enemy --- src/Game/Entities/Blast.hs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/Game/Entities/Blast.hs (limited to 'src/Game/Entities/Blast.hs') 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} -- cgit v1.2.3