aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-02-24 22:51:42 +0000
committerJuan J. Martinez <jjm@usebox.net>2023-02-24 22:51:42 +0000
commite066422b950a06873efb6a884b47155c867b7acf (patch)
tree833c0ac83cdb66ec50f3ef882598d3b93004cf12
parentcf01ddef562c64dbcffa2770f50825cd97f02e3f (diff)
downloadspace-plat-hs-e066422b950a06873efb6a884b47155c867b7acf.tar.gz
space-plat-hs-e066422b950a06873efb6a884b47155c867b7acf.zip
Cleaned passing the collision detection function to the entities
-rw-r--r--src/Game/Entities.hs6
-rw-r--r--src/Game/Entities/Pickup.hs7
-rw-r--r--src/Game/Entities/Robot.hs7
-rw-r--r--src/Game/Entities/Slime.hs7
4 files changed, 12 insertions, 15 deletions
diff --git a/src/Game/Entities.hs b/src/Game/Entities.hs
index 291f10e..d265ff5 100644
--- a/src/Game/Entities.hs
+++ b/src/Game/Entities.hs
@@ -30,9 +30,9 @@ mkEntities sprites m controls stateRef = do
pure $ Entities sprites playerRef stateRef (player : entities)
where
toEntity :: IORef Entity -> M.Object -> IO Entity
- toEntity playerRef (M.SlimeEntity x y) = mkSlime sprites x y playerRef (M.isBlocked m) (hitPlayer stateRef)
- toEntity playerRef (M.RobotEntity x y) = mkRobot sprites x y playerRef (M.isBlocked m) (hitPlayer stateRef)
- toEntity playerRef (M.BatteryEntity x y) = mkBattery sprites x y playerRef (collectedBattery stateRef)
+ toEntity playerRef (M.SlimeEntity x y) = mkSlime sprites x y (collision playerRef 16) (M.isBlocked m) (hitPlayer stateRef)
+ toEntity playerRef (M.RobotEntity x y) = mkRobot sprites x y (collision playerRef 24) (M.isBlocked m) (hitPlayer stateRef)
+ toEntity playerRef (M.BatteryEntity x y) = mkBattery sprites x y (collision playerRef 16) (collectedBattery stateRef)
toEntity _ (M.PlayerEntity _ _) = error "Player already processed"
processSpawn :: S.SpriteSheet -> Spawn -> IO Entity
diff --git a/src/Game/Entities/Pickup.hs b/src/Game/Entities/Pickup.hs
index 8d8beb8..4aa7326 100644
--- a/src/Game/Entities/Pickup.hs
+++ b/src/Game/Entities/Pickup.hs
@@ -1,13 +1,12 @@
module Game.Entities.Pickup (mkBattery) where
-import Data.IORef
import Game.Entities.Common
import Game.Entities.Const
import Game.Entities.Types
import qualified Game.Sprites as S
-mkBattery :: S.SpriteSheet -> Int -> Int -> IORef Entity -> IO () -> IO Entity
-mkBattery sprites x y playerRef collectedBattery' = do
+mkBattery :: S.SpriteSheet -> Int -> Int -> Collision -> IO () -> IO Entity
+mkBattery sprites x y playerCollision collectedBattery' = do
s <- S.get sprites "battery"
pure
Entity
@@ -20,7 +19,7 @@ mkBattery sprites x y playerRef collectedBattery' = do
gravity = gravityOff,
dir = DirRight,
sprite = s,
- update = updateBattery (collision playerRef 16) collectedBattery',
+ update = updateBattery playerCollision collectedBattery',
destroy = False,
spawns = []
}
diff --git a/src/Game/Entities/Robot.hs b/src/Game/Entities/Robot.hs
index 64c9d48..39b63aa 100644
--- a/src/Game/Entities/Robot.hs
+++ b/src/Game/Entities/Robot.hs
@@ -1,14 +1,13 @@
module Game.Entities.Robot (mkRobot) where
import Data.Bits (Bits (..))
-import Data.IORef
import Game.Entities.Common
import Game.Entities.Const
import Game.Entities.Types
import qualified Game.Sprites as S
-mkRobot :: S.SpriteSheet -> Int -> Int -> IORef Entity -> IsBlocked -> IO () -> IO Entity
-mkRobot sprites x y playerRef isBlocked hitPlayer' = do
+mkRobot :: S.SpriteSheet -> Int -> Int -> Collision -> IsBlocked -> IO () -> IO Entity
+mkRobot sprites x y playerCollision isBlocked hitPlayer' = do
s <- S.get sprites "robot"
pure
Entity
@@ -21,7 +20,7 @@ mkRobot sprites x y playerRef isBlocked hitPlayer' = do
gravity = gravityOff,
dir = DirRight,
sprite = s,
- update = updateRobot (collision playerRef 24) isBlocked hitPlayer',
+ update = updateRobot playerCollision isBlocked hitPlayer',
destroy = False,
spawns = []
}
diff --git a/src/Game/Entities/Slime.hs b/src/Game/Entities/Slime.hs
index d87f735..5ca6fe7 100644
--- a/src/Game/Entities/Slime.hs
+++ b/src/Game/Entities/Slime.hs
@@ -1,14 +1,13 @@
module Game.Entities.Slime (mkSlime) where
import Data.Bits (Bits (..))
-import Data.IORef
import Game.Entities.Common
import Game.Entities.Const
import Game.Entities.Types
import qualified Game.Sprites as S
-mkSlime :: S.SpriteSheet -> Int -> Int -> IORef Entity -> IsBlocked -> IO () -> IO Entity
-mkSlime sprites x y playerRef isBlocked hitPlayer' = do
+mkSlime :: S.SpriteSheet -> Int -> Int -> Collision -> IsBlocked -> IO () -> IO Entity
+mkSlime sprites x y playerCollision isBlocked hitPlayer' = do
s <- S.get sprites "slime"
pure
Entity
@@ -21,7 +20,7 @@ mkSlime sprites x y playerRef isBlocked hitPlayer' = do
gravity = gravityOff,
dir = DirRight,
sprite = s,
- update = updateSlime (collision playerRef 16) isBlocked hitPlayer',
+ update = updateSlime playerCollision isBlocked hitPlayer',
destroy = False,
spawns = []
}