diff options
Diffstat (limited to 'Demos')
-rw-r--r-- | Demos/Pong/Pong.hs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Demos/Pong/Pong.hs b/Demos/Pong/Pong.hs index dd8855b..b9661ee 100644 --- a/Demos/Pong/Pong.hs +++ b/Demos/Pong/Pong.hs | |||
@@ -31,7 +31,7 @@ initialBallVelocity = vec2 1 1 | |||
31 | maxBounceAngle = (65::Float) * (pi::Float)/(180::Float) | 31 | maxBounceAngle = (65::Float) * (pi::Float)/(180::Float) |
32 | playerSpeed = 1.0 :: Float | 32 | playerSpeed = 1.0 :: Float |
33 | enemySpeed = 7.0 :: Float | 33 | enemySpeed = 7.0 :: Float |
34 | enemyMomentum = 0.1 :: Float | 34 | enemyMomentum = 1.0 :: Float |
35 | initialEnemyPos = vec2 0.5 0.9 | 35 | initialEnemyPos = vec2 0.5 0.9 |
36 | initialPlayerPos = vec2 0.5 0.1 | 36 | initialPlayerPos = vec2 0.5 0.1 |
37 | initialBallPos = vec2 0.5 0.5 | 37 | initialBallPos = vec2 0.5 0.5 |
@@ -150,13 +150,13 @@ moveBall = step $ \_ dt _ _ (vel, ball) -> (translate (vel * dt) ball, moveBall) | |||
150 | stepEnemy = movePad 0 .> clamp | 150 | stepEnemy = movePad 0 .> clamp |
151 | 151 | ||
152 | movePad :: Float -> Step [GameObject] e GameObject GameObject | 152 | movePad :: Float -> Step [GameObject] e GameObject GameObject |
153 | movePad previousMomentum = step $ \_ dt gos _ pad -> | 153 | movePad previousMomentumVector = step $ \_ dt gos _ pad -> |
154 | let ball = head gos | 154 | let ball = head gos |
155 | offset = (x . position $ ball) - (x . position $ pad) | 155 | heading = (x . position $ ball) - (x . position $ pad) |
156 | chaseVector = enemySpeed * offset | 156 | chaseVector = enemySpeed * heading |
157 | momentum = previousMomentum + enemyMomentum * chaseVector | 157 | momentumVector = previousMomentumVector + enemyMomentum * heading * dt |
158 | vx = chaseVector + momentum | 158 | vx = chaseVector * dt + momentumVector |
159 | in (translate (vec2 (vx * dt) 0) pad, movePad momentum) | 159 | in (translate (vec2 vx 0) pad, movePad momentumVector) |
160 | 160 | ||
161 | sign :: Float -> Float | 161 | sign :: Float -> Float |
162 | sign x = if x >= 0 then 1 else -1 | 162 | sign x = if x >= 0 then 1 else -1 |