From ea4100bd02143fea255cc0441cbeeb842796a58a Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Mon, 18 Nov 2024 17:42:20 -0800 Subject: Fix momentum. --- Demos/Pong/Pong.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'Demos/Pong') 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 maxBounceAngle = (65::Float) * (pi::Float)/(180::Float) playerSpeed = 1.0 :: Float enemySpeed = 7.0 :: Float -enemyMomentum = 0.1 :: Float +enemyMomentum = 1.0 :: Float initialEnemyPos = vec2 0.5 0.9 initialPlayerPos = vec2 0.5 0.1 initialBallPos = vec2 0.5 0.5 @@ -150,13 +150,13 @@ moveBall = step $ \_ dt _ _ (vel, ball) -> (translate (vel * dt) ball, moveBall) stepEnemy = movePad 0 .> clamp movePad :: Float -> Step [GameObject] e GameObject GameObject -movePad previousMomentum = step $ \_ dt gos _ pad -> - let ball = head gos - offset = (x . position $ ball) - (x . position $ pad) - chaseVector = enemySpeed * offset - momentum = previousMomentum + enemyMomentum * chaseVector - vx = chaseVector + momentum - in (translate (vec2 (vx * dt) 0) pad, movePad momentum) +movePad previousMomentumVector = step $ \_ dt gos _ pad -> + let ball = head gos + heading = (x . position $ ball) - (x . position $ pad) + chaseVector = enemySpeed * heading + momentumVector = previousMomentumVector + enemyMomentum * heading * dt + vx = chaseVector * dt + momentumVector + in (translate (vec2 vx 0) pad, movePad momentumVector) sign :: Float -> Float sign x = if x >= 0 then 1 else -1 -- cgit v1.2.3