From 1c8a22d24b14d258a9103f7b83d627359eae0da8 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Tue, 21 Mar 2023 21:02:45 +0000 Subject: Player transition into the stage --- src/Game/Entities/Entry.hs | 31 +++++++++++++++++++++++++++++++ src/Game/Entities/Types.hs | 8 +++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/Game/Entities/Entry.hs (limited to 'src/Game/Entities') diff --git a/src/Game/Entities/Entry.hs b/src/Game/Entities/Entry.hs new file mode 100644 index 0000000..5c17146 --- /dev/null +++ b/src/Game/Entities/Entry.hs @@ -0,0 +1,31 @@ +module Game.Entities.Entry (mkEntry) where + +import Game.Entities.Common +import Game.Entities.Const +import Game.Entities.Types +import qualified Game.Sprites as S + +mkEntry :: S.SpriteSheet -> Int -> Int -> IO Entity +mkEntry sprites x y = do + s <- S.get sprites "exit" + pure + Entity + { typ = TypePickup, + x = x, + y = y, + delay = frameDelay, + frame = 0, + jumping = False, + gravity = gravityOff, + dir = Dying, + sprite = s, + update = pure . updateEntry, + destroy = False, + actions = [] + } + +updateEntry :: Entity -> Entity +updateEntry e + | e.delay > 0 = e {delay = e.delay - 1} + | e.frame + 1 < frameLimit e = e {delay = frameDelay, frame = e.frame + 1} + | otherwise = e {destroy = True, actions = [ActionEntryDone]} diff --git a/src/Game/Entities/Types.hs b/src/Game/Entities/Types.hs index 4ece6c5..e8b29b0 100644 --- a/src/Game/Entities/Types.hs +++ b/src/Game/Entities/Types.hs @@ -29,7 +29,13 @@ data Entities = Entities -- | The effect name must match the sprite name in the spritesheet. type EffectName = String -data Action = ActionAddEffect Int Int EffectName | ActionAddBattery Int Int | ActionHitPlayer | ActionExitStarted | ActionExitDone +data Action + = ActionAddEffect Int Int EffectName + | ActionAddBattery Int Int + | ActionHitPlayer + | ActionExitStarted + | ActionEntryDone + | ActionExitDone data Entity = Entity { typ :: Type, -- cgit v1.2.3