diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-02-04 22:35:42 +0000 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-02-04 22:35:42 +0000 |
commit | fd63beed174dcbcdcc7fead7d734a53d65d060e1 (patch) | |
tree | e4304d524890bce6d66458d919786d89f7bf6c8e /src/Game | |
parent | cc9719db1ea93d892561214fe152ea7aca0f9cd5 (diff) | |
download | space-plat-hs-fd63beed174dcbcdcc7fead7d734a53d65d060e1.tar.gz space-plat-hs-fd63beed174dcbcdcc7fead7d734a53d65d060e1.zip |
Go down platforms with A + down
Diffstat (limited to 'src/Game')
-rw-r--r-- | src/Game/Entities.hs | 19 |
1 files changed, 15 insertions, 4 deletions
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 |