diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-03-10 23:53:40 +0000 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-03-10 23:53:40 +0000 |
commit | 45a103da2133b645fac9617cc97c11901d3e258f (patch) | |
tree | 0cad00427725ecd1067f64a99a25e78d39e72409 /src/Game/Entities | |
parent | 7a714cc457323bff6b4a73ec9e7b58c7a63381ec (diff) | |
download | space-plat-hs-45a103da2133b645fac9617cc97c11901d3e258f.tar.gz space-plat-hs-45a103da2133b645fac9617cc97c11901d3e258f.zip |
Change stage
Diffstat (limited to 'src/Game/Entities')
-rw-r--r-- | src/Game/Entities/Exit.hs | 20 | ||||
-rw-r--r-- | src/Game/Entities/Types.hs | 2 |
2 files changed, 15 insertions, 7 deletions
diff --git a/src/Game/Entities/Exit.hs b/src/Game/Entities/Exit.hs index 075e1f4..12f160d 100644 --- a/src/Game/Entities/Exit.hs +++ b/src/Game/Entities/Exit.hs @@ -19,13 +19,21 @@ mkExit sprites x y playerCollision = do gravity = gravityOff, dir = DirRight, sprite = s, - update = pure . updateExit playerCollision, + update = updateExit playerCollision, destroy = False, actions = [] } -updateExit :: Collision -> Entity -> Entity -updateExit _ e - | e.delay > 0 = e {delay = e.delay - 1} - | e.frame + 1 < frameLimit e = e {delay = frameDelay, frame = e.frame + 1} - | otherwise = e {delay = frameDelay, frame = 7} +updateExit :: Collision -> Entity -> IO Entity +updateExit touchedPlayer e = do + touched <- if e.frame < fullyOpen then pure False else touchedPlayer e + pure $ if touched then e {destroy = True, actions = [ActionExitLevel]} else update + where + fullyOpen :: Int + fullyOpen = 7 + + update :: Entity + update + | e.delay > 0 = e {delay = e.delay - 1} + | e.frame + 1 < frameLimit e = e {delay = frameDelay, frame = e.frame + 1} + | otherwise = e {delay = frameDelay, frame = fullyOpen} diff --git a/src/Game/Entities/Types.hs b/src/Game/Entities/Types.hs index 64b4637..392a86f 100644 --- a/src/Game/Entities/Types.hs +++ b/src/Game/Entities/Types.hs @@ -29,7 +29,7 @@ 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 +data Action = ActionAddEffect Int Int EffectName | ActionAddBattery Int Int | ActionHitPlayer | ActionExitLevel data Entity = Entity { typ :: Type, |