change keyboard event handling
This commit is contained in:
parent
fc452c53ff
commit
705f032035
1 changed files with 9 additions and 6 deletions
|
@ -35,7 +35,7 @@ data UserData = UserData
|
||||||
, actors :: M.Map String (Actor String)
|
, actors :: M.Map String (Actor String)
|
||||||
, foreground :: G.GeglBuffer
|
, foreground :: G.GeglBuffer
|
||||||
, updateActors :: [Actor String]
|
, updateActors :: [Actor String]
|
||||||
, keyDown :: Maybe SDL.Keycode
|
, keysDown :: [SDL.Keycode]
|
||||||
, cameraX :: Double
|
, cameraX :: Double
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ load = do
|
||||||
, actors = actorMap
|
, actors = actorMap
|
||||||
, foreground = buffer
|
, foreground = buffer
|
||||||
, updateActors = []
|
, updateActors = []
|
||||||
, keyDown = Nothing
|
, keysDown = []
|
||||||
, cameraX = 0
|
, cameraX = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,8 +157,9 @@ update dt = do
|
||||||
ud <- getAffection
|
ud <- getAffection
|
||||||
|
|
||||||
traceM $ show (1 / dt) ++ " FPS"
|
traceM $ show (1 / dt) ++ " FPS"
|
||||||
|
-- traceM $ show $ keysDown ud
|
||||||
|
|
||||||
maybe (return ()) (\code -> do
|
mapM_ (\code -> do
|
||||||
let vel = 400 -- velocity in Pixels per second
|
let vel = 400 -- velocity in Pixels per second
|
||||||
leg = vel * dt
|
leg = vel * dt
|
||||||
(G.PropertyDouble xpos) <-
|
(G.PropertyDouble xpos) <-
|
||||||
|
@ -195,7 +196,7 @@ update dt = do
|
||||||
, updateActors = (nmap M.! "rect") : updateActors ud
|
, updateActors = (nmap M.! "rect") : updateActors ud
|
||||||
, cameraX = cameraX ud + offset
|
, cameraX = cameraX ud + offset
|
||||||
}
|
}
|
||||||
) (keyDown ud)
|
) (keysDown ud)
|
||||||
|
|
||||||
handle :: SDL.EventPayload -> Affection UserData ()
|
handle :: SDL.EventPayload -> Affection UserData ()
|
||||||
handle (SDL.KeyboardEvent dat) =
|
handle (SDL.KeyboardEvent dat) =
|
||||||
|
@ -204,11 +205,13 @@ handle (SDL.KeyboardEvent dat) =
|
||||||
if (SDL.keyboardEventKeyMotion dat == SDL.Pressed)
|
if (SDL.keyboardEventKeyMotion dat == SDL.Pressed)
|
||||||
then
|
then
|
||||||
putAffection ud
|
putAffection ud
|
||||||
{ keyDown = Just $ SDL.keysymKeycode $ SDL.keyboardEventKeysym dat
|
{ keysDown =
|
||||||
|
SDL.keysymKeycode (SDL.keyboardEventKeysym dat) : keysDown ud
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
putAffection ud
|
putAffection ud
|
||||||
{ keyDown = Nothing
|
{ keysDown =
|
||||||
|
delete (SDL.keysymKeycode $ SDL.keyboardEventKeysym dat) (keysDown ud)
|
||||||
}
|
}
|
||||||
|
|
||||||
handle (SDL.WindowClosedEvent _) = do
|
handle (SDL.WindowClosedEvent _) = do
|
||||||
|
|
Loading…
Reference in a new issue