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/Robot.hs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Game/Entities/Robot.hs') diff --git a/src/Game/Entities/Robot.hs b/src/Game/Entities/Robot.hs index 39b63aa..dd3404a 100644 --- a/src/Game/Entities/Robot.hs +++ b/src/Game/Entities/Robot.hs @@ -6,8 +6,8 @@ import Game.Entities.Const import Game.Entities.Types import qualified Game.Sprites as S -mkRobot :: S.SpriteSheet -> Int -> Int -> Collision -> IsBlocked -> IO () -> IO Entity -mkRobot sprites x y playerCollision isBlocked hitPlayer' = do +mkRobot :: S.SpriteSheet -> Int -> Int -> Collision -> IsBlocked -> IO Entity +mkRobot sprites x y playerCollision isBlocked = do s <- S.get sprites "robot" pure Entity @@ -20,16 +20,16 @@ mkRobot sprites x y playerCollision isBlocked hitPlayer' = do gravity = gravityOff, dir = DirRight, sprite = s, - update = updateRobot playerCollision isBlocked hitPlayer', + update = updateRobot playerCollision isBlocked, destroy = False, - spawns = [] + actions = [] } -updateRobot :: Collision -> IsBlocked -> IO () -> Entity -> IO Entity -updateRobot touchedPlayer isBlocked hitPlayer' e = do +updateRobot :: Collision -> IsBlocked -> Entity -> IO Entity +updateRobot touchedPlayer isBlocked e = do touched <- touchedPlayer e let updated = updateFrame True e - if touched then fmap (const e) hitPlayer' else pure $ updateMovement updated + pure $ if touched then updated {actions = [ActionHitPlayer]} else updateMovement updated where updateMovement :: Entity -> Entity updateMovement ent -- cgit v1.2.3