From 9fcbd69c0e2ffc13d092db2656b5f28692980dd9 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Thu, 2 Jan 2025 14:39:54 -0800 Subject: Minor tweaks. --- Demos/Pong/Pong.hs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Demos/Pong/Pong.hs b/Demos/Pong/Pong.hs index f1b3c74..0df05ea 100644 --- a/Demos/Pong/Pong.hs +++ b/Demos/Pong/Pong.hs @@ -56,7 +56,6 @@ data GameObject = GameObject { gameObjectId :: !GameObjectId , gameObjectSize :: {-# UNPACK #-} !Vector2 , basis :: {-# UNPACK #-} !Transform2 - -- TODO: Think about storing steppers separately. , gostep :: Step [GameObject] [GameEvent] GameObject GameObject } @@ -110,9 +109,8 @@ stepWorld elapsed dt events gos@[ball, enemy, player] = collisions = collide [ball] [enemy, player] collisionEvents = (\(x,y) -> Collision (gameObjectId x) (gameObjectId y)) <$> collisions events' = events ++ collisionEvents - gos' = map (update elapsed dt events' gos) gos in - gos' + map (update elapsed dt events' gos) gos update :: Elapsed -> Dt -> [GameEvent] -> [GameObject] -> GameObject -> GameObject update elapsed dt events gos go = @@ -164,7 +162,7 @@ moveBall = step $ \_ dt _ _ (vel, ball) -> (translate (vel * dt) ball, moveBall) -- Enemy stepper -stepEnemy = movePad 0 .> clamp +stepEnemy = movePad 0 .> spure clamp movePad :: Float -> Step [GameObject] e GameObject GameObject movePad previousMomentumVector = step $ \_ dt gos _ pad -> @@ -175,13 +173,10 @@ movePad previousMomentumVector = step $ \_ dt gos _ pad -> vx = chaseVector * dt + momentumVector in (translate (vec2 vx 0) pad, movePad momentumVector) -sign :: Float -> Float -sign x = if x >= 0 then 1 else -1 - -- Player stepper -stepPlayer = sfold movePlayer .> clamp +stepPlayer = sfold movePlayer .> spure clamp movePlayer = mconcat [ swhen MoveLeft $ movePlayer' (vec2 (-playerSpeed) 0) @@ -191,8 +186,8 @@ movePlayer = mconcat movePlayer' :: Vector2 -> Step s e GameObject GameObject movePlayer' dir = step $ \_ dt _ _ go -> (translate (dir * dt) go, movePlayer' dir) -clamp :: Step s e GameObject GameObject -clamp = spure $ \go -> +clamp :: GameObject -> GameObject +clamp go = let p' = vec2 (clamp' x sx (1 - sx)) y (Vector2 x y) = position go clamp' x a b -- cgit v1.2.3