aboutsummaryrefslogtreecommitdiff
path: root/src/Game/Entities/Effect.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-02-20 21:52:22 +0000
committerJuan J. Martinez <jjm@usebox.net>2023-02-20 21:52:22 +0000
commited585355b1f78de15885e803138a98b75ca2b1e2 (patch)
treeda25f10539fa39ee284dc49ab9d5e53721bc008f /src/Game/Entities/Effect.hs
parent92785d2df84e18953048a6537b71c824a2a4b288 (diff)
downloadspace-plat-hs-ed585355b1f78de15885e803138a98b75ca2b1e2.tar.gz
space-plat-hs-ed585355b1f78de15885e803138a98b75ca2b1e2.zip
Split entities in modules.
Diffstat (limited to 'src/Game/Entities/Effect.hs')
-rw-r--r--src/Game/Entities/Effect.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/Game/Entities/Effect.hs b/src/Game/Entities/Effect.hs
new file mode 100644
index 0000000..0a20445
--- /dev/null
+++ b/src/Game/Entities/Effect.hs
@@ -0,0 +1,31 @@
+module Game.Entities.Effect (mkEffect) where
+
+import Game.Entities.Common
+import Game.Entities.Const
+import Game.Entities.Types
+import qualified Game.Sprites as S
+
+mkEffect :: S.SpriteSheet -> Int -> Int -> String -> IO Entity
+mkEffect sprites x y name = do
+ s <- S.get sprites name
+ pure
+ Entity
+ { typ = TypeEffect,
+ x = x,
+ y = y,
+ delay = frameDelay,
+ frame = 0,
+ jumping = False,
+ gravity = gravityOff,
+ dir = DirRight,
+ sprite = s,
+ update = pure . updateEffect,
+ destroy = False,
+ spawns = []
+ }
+
+updateEffect :: Entity -> Entity
+updateEffect 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}