change keyboard event handling

This commit is contained in:
nek0 2017-03-29 00:43:59 +02:00
parent fc452c53ff
commit 705f032035

View file

@ -35,7 +35,7 @@ data UserData = UserData
, actors :: M.Map String (Actor String)
, foreground :: G.GeglBuffer
, updateActors :: [Actor String]
, keyDown :: Maybe SDL.Keycode
, keysDown :: [SDL.Keycode]
, cameraX :: Double
}
@ -126,7 +126,7 @@ load = do
, actors = actorMap
, foreground = buffer
, updateActors = []
, keyDown = Nothing
, keysDown = []
, cameraX = 0
}
@ -157,8 +157,9 @@ update dt = do
ud <- getAffection
traceM $ show (1 / dt) ++ " FPS"
-- traceM $ show $ keysDown ud
maybe (return ()) (\code -> do
mapM_ (\code -> do
let vel = 400 -- velocity in Pixels per second
leg = vel * dt
(G.PropertyDouble xpos) <-
@ -195,7 +196,7 @@ update dt = do
, updateActors = (nmap M.! "rect") : updateActors ud
, cameraX = cameraX ud + offset
}
) (keyDown ud)
) (keysDown ud)
handle :: SDL.EventPayload -> Affection UserData ()
handle (SDL.KeyboardEvent dat) =
@ -204,11 +205,13 @@ handle (SDL.KeyboardEvent dat) =
if (SDL.keyboardEventKeyMotion dat == SDL.Pressed)
then
putAffection ud
{ keyDown = Just $ SDL.keysymKeycode $ SDL.keyboardEventKeysym dat
{ keysDown =
SDL.keysymKeycode (SDL.keyboardEventKeysym dat) : keysDown ud
}
else
putAffection ud
{ keyDown = Nothing
{ keysDown =
delete (SDL.keysymKeycode $ SDL.keyboardEventKeysym dat) (keysDown ud)
}
handle (SDL.WindowClosedEvent _) = do