diff options
Diffstat (limited to 'Demos/Pong')
| -rw-r--r-- | Demos/Pong/Pong.hs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Demos/Pong/Pong.hs b/Demos/Pong/Pong.hs index 790a98e..f1b3c74 100644 --- a/Demos/Pong/Pong.hs +++ b/Demos/Pong/Pong.hs | |||
| @@ -56,6 +56,7 @@ data GameObject = GameObject | |||
| 56 | { gameObjectId :: !GameObjectId | 56 | { gameObjectId :: !GameObjectId |
| 57 | , gameObjectSize :: {-# UNPACK #-} !Vector2 | 57 | , gameObjectSize :: {-# UNPACK #-} !Vector2 |
| 58 | , basis :: {-# UNPACK #-} !Transform2 | 58 | , basis :: {-# UNPACK #-} !Transform2 |
| 59 | -- TODO: Think about storing steppers separately. | ||
| 59 | , gostep :: Step [GameObject] [GameEvent] GameObject GameObject | 60 | , gostep :: Step [GameObject] [GameEvent] GameObject GameObject |
| 60 | } | 61 | } |
| 61 | 62 | ||
| @@ -121,7 +122,7 @@ update elapsed dt events gos go = | |||
| 121 | 122 | ||
| 122 | -- Ball steppers | 123 | -- Ball steppers |
| 123 | 124 | ||
| 124 | stepBall vel = bounceBall vel .> moveBall | 125 | stepBall vel = bounceBall vel .> moveBall -- .> clamp |
| 125 | 126 | ||
| 126 | bounceBall :: Vector2 -> Step [GameObject] [GameEvent] GameObject (Vector2, GameObject) | 127 | bounceBall :: Vector2 -> Step [GameObject] [GameEvent] GameObject (Vector2, GameObject) |
| 127 | bounceBall vel = step $ \_ dt gos events ball -> | 128 | bounceBall vel = step $ \_ dt gos events ball -> |
| @@ -192,11 +193,11 @@ movePlayer' dir = step $ \_ dt _ _ go -> (translate (dir * dt) go, movePlayer' d | |||
| 192 | 193 | ||
| 193 | clamp :: Step s e GameObject GameObject | 194 | clamp :: Step s e GameObject GameObject |
| 194 | clamp = spure $ \go -> | 195 | clamp = spure $ \go -> |
| 195 | let p' = vec2 (clamp' x s (1 - s)) y | 196 | let p' = vec2 (clamp' x sx (1 - sx)) y |
| 196 | (Vector2 x y) = position go | 197 | (Vector2 x y) = position go |
| 197 | clamp' x a b | 198 | clamp' x a b |
| 198 | | x < a = a | 199 | | x < a = a |
| 199 | | x > b = b | 200 | | x > b = b |
| 200 | | otherwise = x | 201 | | otherwise = x |
| 201 | (Vector2 s _) = padSize | 202 | (Vector2 sx _) = gameObjectSize go |
| 202 | in setPosition p' go | 203 | in setPosition p' go |
