aboutsummaryrefslogtreecommitdiff
path: root/src/Game/Entities/Player.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-03-21 21:28:25 +0000
committerJuan J. Martinez <jjm@usebox.net>2023-03-21 21:28:25 +0000
commit11d2ed7f15a86dd465bc3456e3478e9ff03bf5d2 (patch)
treef5e6df771eb4396df13fe3cdc2d98721917a2d68 /src/Game/Entities/Player.hs
parent1c8a22d24b14d258a9103f7b83d627359eae0da8 (diff)
downloadspace-plat-hs-11d2ed7f15a86dd465bc3456e3478e9ff03bf5d2.tar.gz
space-plat-hs-11d2ed7f15a86dd465bc3456e3478e9ff03bf5d2.zip
Introduce a set property
Stopped abusing the direction property!
Diffstat (limited to 'src/Game/Entities/Player.hs')
-rw-r--r--src/Game/Entities/Player.hs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/Game/Entities/Player.hs b/src/Game/Entities/Player.hs
index a69799b..18625b6 100644
--- a/src/Game/Entities/Player.hs
+++ b/src/Game/Entities/Player.hs
@@ -1,4 +1,4 @@
-module Game.Entities.Player (mkPlayer) where
+module Game.Entities.Player (mkPlayer, dyingSet) where
import Data.IORef
import qualified Game.Controller as C
@@ -7,6 +7,9 @@ import Game.Entities.Const
import Game.Entities.Types
import qualified Game.Sprites as S
+dyingSet :: Int
+dyingSet = 2
+
mkPlayer :: S.SpriteSheet -> Int -> Int -> IORef C.Controls -> IsBlocked -> IO Entity
mkPlayer sprites x y controls isBlocked = do
s <- S.get sprites "player"
@@ -17,6 +20,7 @@ mkPlayer sprites x y controls isBlocked = do
y = y,
delay = 0,
frame = 0,
+ set = toSpriteSet DirRight,
jumping = False,
gravity = gravityOff,
dir = DirRight,
@@ -31,8 +35,8 @@ updateHorizontal isBlocked left right e
-- prevent pressing both directions (keyboard)
| left && right = e
-- change direction first
- | left && e.dir /= DirLeft = e {dir = DirLeft, delay = 0}
- | right && e.dir /= DirRight = e {dir = DirRight, delay = 0}
+ | left && e.dir /= DirLeft = e {dir = DirLeft, set = toSpriteSet DirLeft, delay = 0}
+ | right && e.dir /= DirRight = e {dir = DirRight, set = toSpriteSet DirRight, delay = 0}
| left && isGoingDown = if isBlocked (e.x - 1) (e.y + 23) then e else e {x = e.x - 1}
| left && not isGoingDown = if isBlocked (e.x - 1) (e.y + 23) && isBlocked (e.x - 1) (e.y + 17) then e else e {x = e.x - 1}
| right && isGoingDown = if isBlocked (e.x + 17) (e.y + 23) then e else e {x = e.x + 1}
@@ -59,7 +63,7 @@ updateVertical isBlocked jump down e
updatePlayer :: IORef C.Controls -> IsBlocked -> Entity -> IO Entity
updatePlayer controls isBlocked e
- | e.dir /= Dying = do
+ | e.set /= dyingSet = do
ctl <- readIORef controls
pure $
updateGravity isBlocked $