From fd63beed174dcbcdcc7fead7d734a53d65d060e1 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 4 Feb 2023 22:35:42 +0000 Subject: Go down platforms with A + down --- src/Game/Entities.hs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/Game/Entities.hs') diff --git a/src/Game/Entities.hs b/src/Game/Entities.hs index 0d37632..1203f55 100644 --- a/src/Game/Entities.hs +++ b/src/Game/Entities.hs @@ -81,12 +81,23 @@ updateHorizontal left right e gravity = eGravity e isGoingDown = gravity == gravityOff || gravity >= gravityDown -updateVertical :: Bool -> Entity -> Entity -updateVertical jump e - | jump && gravity == gravityOff = e {eGravity = gravityUp, eFrame = jumpFrame} +updateVertical :: Bool -> Bool -> Entity -> Entity +updateVertical jump down e + | gravity /= gravityOff = e + | jump && not down = e {eGravity = gravityUp, eFrame = jumpFrame} + -- go down a 8 pixel tall platform; not ideal to have these values hardcoded here + -- but to be fair, the player height/width is hardcoded as well + | jump + && down + && not (isBlocked (x + 2) (y + 24 + 8)) + && not (isBlocked (x + 12) (y + 24 + 8)) = + applyGravity 8 e {eGravity = gravityDown, eFrame = jumpFrame, eY = eY e + 1} | otherwise = e where + x = eX e + y = eY e gravity = eGravity e + isBlocked = eBlocked e applyGravity :: Int -> Entity -> Entity applyGravity v e @@ -123,7 +134,7 @@ updatePlayer controls e = do ctl <- readIORef controls pure $ updateGravity $ - updateVertical (C.cA ctl) $ + updateVertical (C.cA ctl) (C.cDown ctl) $ updateHorizontal (C.cLeft ctl) (C.cRight ctl) $ -- left or right, but not both (keyboard) updateFrame ((C.cLeft ctl || C.cRight ctl) && (C.cLeft ctl /= C.cRight ctl)) e -- cgit v1.2.3