pituicat/src/Scenes/Test/EventHandler.hs

40 lines
908 B
Haskell
Raw Normal View History

2021-01-11 23:51:58 +00:00
{-# LANGUAGE OverloadedStrings #-}
2021-01-11 15:54:17 +00:00
module Scenes.Test.EventHandler where
2021-01-11 23:51:58 +00:00
import Affection as A
2021-01-11 15:54:17 +00:00
import qualified SDL
2021-01-11 23:51:58 +00:00
import Linear
import Control.Concurrent.STM
import Data.String (fromString)
2021-01-11 15:54:17 +00:00
-- internal imports
import Classes
import Types
2021-01-11 23:51:58 +00:00
import Scenes.Test.Types
2021-01-11 15:54:17 +00:00
singleHandler
:: Test
2021-01-11 23:51:58 +00:00
-> TranslatorMessage
2021-01-11 15:54:17 +00:00
-> Affection ()
2021-01-11 23:51:58 +00:00
singleHandler level event = do
let multiplier = if tmKeyMotion event == SDL.Pressed then 1 else 0
liftIO $ atomically $ modifyTVar (testPlayer level) (\(Just pituicat) ->
A.log Debug ("Grounded: " <> fromString (show $ pcGrounded pituicat)) $
case tmAction event of
Jump -> if multiplier > 0 && pcGrounded pituicat
then A.log Debug "jumping"
(Just pituicat
{ pcVel = pcVel pituicat + V2 0 250
, pcGrounded = False
}
)
else
Just pituicat
_ -> Just pituicat
)