aboutsummaryrefslogtreecommitdiff
path: root/src/Game/Entities/Tracker.hs
blob: 9baac8006a6d5a133b11c79496f16ca6886e0163 (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
32
33
34
module Game.Entities.Tracker (mkTracker) where

import Game.Entities.Const
import Game.Entities.Runner
import Game.Entities.Types
import qualified Game.Sprites as S

mkTracker :: S.SpriteSheet -> Int -> Int -> Dir -> Collision -> Collision -> IsBlocked -> IsBlocked -> IO Entity
mkTracker sprites x y d playerCollision facingPlayerLower isBlocked isBlockedDeadly = do
  s <- S.get sprites "tracker"
  runner <- mkRunner sprites x y d playerCollision isBlocked isBlockedDeadly
  pure runner {sprite = s, update = updateTracker runner.update facingPlayerLower isBlocked}

updateTracker :: (Entity -> IO Entity) -> Collision -> IsBlocked -> Entity -> IO Entity
updateTracker updateRunner facingPlayerLower isBlocked ent = do
  e <- updateRunner ent
  facing <- facingPlayerLower e
  pure $
    if facing
      && e.gravity == gravityOff
      && not (isBlocked (isBlockedX e) (e.y - 1))
      && not (isBlocked (e.x + 8) (e.y - 1))
      && isBlocked (isBlockedX e) e.y
      && isBlocked (e.x + 8) e.y
      then
        e
          { gravity = gravityUp,
            frame = jumpFrame,
            actions = [ActionAddEffect ent.x (ent.y + 8) "dust"]
          }
      else e
  where
    isBlockedX :: Entity -> Int
    isBlockedX e = if e.dir == DirLeft then e.x + 16 else e.x - 1