From 678a4631a36b55face6541c473d5dfb854225547 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Thu, 15 Aug 2024 22:49:21 -0700 Subject: Better event handling. --- Demos/Pong/Pong.hs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'Demos/Pong/Pong.hs') diff --git a/Demos/Pong/Pong.hs b/Demos/Pong/Pong.hs index 943682f..2bd9df1 100644 --- a/Demos/Pong/Pong.hs +++ b/Demos/Pong/Pong.hs @@ -40,9 +40,7 @@ initialBallPos = vec2 0.5 0.5 data GameEvent = MoveLeft | MoveRight - | StopLeft - | StopRight - deriving (Eq, Ord) + deriving (Eq, Ord, Show) -- Game objects @@ -163,11 +161,10 @@ movePad = step $ \elapsed _ _ _ pad -> stepPlayer = sfold moveGO .> clamp -moveGO = - mconcat - [ switch StopLeft sid MoveLeft (moveGO' $ vec2 (-playerSpeed) 0), - switch StopRight sid MoveRight (moveGO' $ vec2 playerSpeed 0) - ] +moveGO = mconcat + [ swhen MoveLeft $ moveGO' (vec2 (-playerSpeed) 0) + , swhen MoveRight $ moveGO' (vec2 playerSpeed 0) + ] moveGO' :: Vector2 -> Step s e GameObject GameObject moveGO' dir = step $ \_ dt _ _ go -> (translate (dir * dt) go, moveGO' dir) -- cgit v1.2.3