aboutsummaryrefslogtreecommitdiff
path: root/src/Game
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-03-05 11:42:56 +0000
committerJuan J. Martinez <jjm@usebox.net>2023-03-09 12:21:05 +0000
commitbeecc1e2af08f81f5cb5d2ebb93aaef59b20fcd5 (patch)
treef0d1947e0369fdf59a1f626f953c778884873cc0 /src/Game
parentee50719de81145b5859d957da722cf183e0c8c60 (diff)
downloadspace-plat-hs-beecc1e2af08f81f5cb5d2ebb93aaef59b20fcd5.tar.gz
space-plat-hs-beecc1e2af08f81f5cb5d2ebb93aaef59b20fcd5.zip
Exit stage WIP
Diffstat (limited to 'src/Game')
-rw-r--r--src/Game/Entities.hs20
-rw-r--r--src/Game/Entities/Exit.hs31
-rw-r--r--src/Game/State.hs3
3 files changed, 52 insertions, 2 deletions
diff --git a/src/Game/Entities.hs b/src/Game/Entities.hs
index 2810fcf..2cfdd76 100644
--- a/src/Game/Entities.hs
+++ b/src/Game/Entities.hs
@@ -1,4 +1,14 @@
-module Game.Entities (Entities, Entity, mkEntities, updateAll, render, renderVisible, playerPosition) where
+module Game.Entities
+ ( Entities,
+ Entity,
+ mkEntities,
+ addExit,
+ updateAll,
+ render,
+ renderVisible,
+ playerPosition,
+ )
+where
import Control.Monad
import Data.Bits (Bits (..))
@@ -9,6 +19,7 @@ import qualified Game.Controller as C
import Game.Entities.Common
import Game.Entities.Const
import Game.Entities.Effect
+import Game.Entities.Exit
import Game.Entities.Pickup
import Game.Entities.Player
import Game.Entities.Robot
@@ -42,6 +53,13 @@ playerPosition (Entities _ _ entities) =
where
player = head entities
+addExit :: Entities -> IO Entities
+addExit es = do
+ exit <- mkExit es.sprites x y (collision es.player 24)
+ pure es {entities = es.entities ++ [exit]}
+ where
+ (x, y) = playerPosition es
+
updateAll :: Entities -> GS.State -> IO (Entities, GS.State)
updateAll es state = do
-- update the player first (including the reference)
diff --git a/src/Game/Entities/Exit.hs b/src/Game/Entities/Exit.hs
new file mode 100644
index 0000000..075e1f4
--- /dev/null
+++ b/src/Game/Entities/Exit.hs
@@ -0,0 +1,31 @@
+module Game.Entities.Exit (mkExit) where
+
+import Game.Entities.Common
+import Game.Entities.Const
+import Game.Entities.Types
+import qualified Game.Sprites as S
+
+mkExit :: S.SpriteSheet -> Int -> Int -> Collision -> IO Entity
+mkExit sprites x y playerCollision = do
+ s <- S.get sprites "exit"
+ pure
+ Entity
+ { typ = TypePickup,
+ x = x,
+ y = y,
+ delay = frameDelay,
+ frame = 0,
+ jumping = False,
+ gravity = gravityOff,
+ dir = DirRight,
+ sprite = s,
+ update = pure . 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}
diff --git a/src/Game/State.hs b/src/Game/State.hs
index f8b5721..8987a2e 100644
--- a/src/Game/State.hs
+++ b/src/Game/State.hs
@@ -6,5 +6,6 @@ data State = State
lives :: Int,
totalLives :: Int,
hitDelay :: Int,
- gameOverDelay :: Int
+ gameOverDelay :: Int,
+ exit :: Bool
}