aboutsummaryrefslogtreecommitdiff
path: root/src/Game/Entities/Effect.hs
blob: 7a2b341fb4250728d0c42694f6b5806d6d3401fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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,
        actions = []
      }

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}