aboutsummaryrefslogtreecommitdiff
path: root/src/Game/Entities/Tracker.hs
blob: ef7325f8ec75d134853c7b70c6107d25bff1aa08 (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
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 -> IO Entity
mkTracker sprites x y d playerCollision facingPlayerLower isBlocked = do
  s <- S.get sprites "tracker"
  runner <- mkRunner sprites x y d playerCollision isBlocked
  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 (ent.x + 8) (ent.y - 1)) && isBlocked (ent.x + 8) ent.y
      then
        e
          { gravity = gravityUp,
            frame = jumpFrame,
            actions = [ActionAddEffect ent.x (ent.y + 8) "dust"]
          }
      else e