From 1b05eefc7a5a4fb688d7b631529324ca08ed1a16 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Wed, 1 Mar 2023 23:11:31 +0000 Subject: Untangle state changes into actions WIP: still unclear if we really need the IORefs! --- src/Game/Entities/Pickup.hs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Game/Entities/Pickup.hs') diff --git a/src/Game/Entities/Pickup.hs b/src/Game/Entities/Pickup.hs index 4aa7326..7c1937c 100644 --- a/src/Game/Entities/Pickup.hs +++ b/src/Game/Entities/Pickup.hs @@ -5,8 +5,8 @@ import Game.Entities.Const import Game.Entities.Types import qualified Game.Sprites as S -mkBattery :: S.SpriteSheet -> Int -> Int -> Collision -> IO () -> IO Entity -mkBattery sprites x y playerCollision collectedBattery' = do +mkBattery :: S.SpriteSheet -> Int -> Int -> Collision -> IO Entity +mkBattery sprites x y playerCollision = do s <- S.get sprites "battery" pure Entity @@ -19,15 +19,15 @@ mkBattery sprites x y playerCollision collectedBattery' = do gravity = gravityOff, dir = DirRight, sprite = s, - update = updateBattery playerCollision collectedBattery', + update = updateBattery playerCollision, destroy = False, - spawns = [] + actions = [] } -updateBattery :: Collision -> IO () -> Entity -> IO Entity -updateBattery touchedPlayer collectedBattery' e = do +updateBattery :: Collision -> Entity -> IO Entity +updateBattery touchedPlayer e = do touched <- touchedPlayer e - if touched then e {destroy = True} <$ collectedBattery' else pure updateBatteryFrame + pure $ if touched then e {destroy = True, actions = [ActionAddBattery]} else updateBatteryFrame where updateBatteryFrame :: Entity updateBatteryFrame -- cgit v1.2.3