Building Pong on Canvas: Angle-Reflection Bounce Physics and an AI Paddle That's Meant to Lose Sometimes
Build Pong on HTML5 canvas: angle-reflection bounce physics from paddle contact point, plus a rate-limited AI paddle that's beatable by design.
Building Pong on Canvas: Angle-Reflection Bounce Physics and an AI Paddle That's Meant to Lose Sometimes
Pong is the game everyone thinks they can write in an afternoon, and mostly they can — a ball, two rectangles, vx *= -1 when they touch. What comes out the other end is technically Pong and completely lifeless: the ball ricochets at whatever angle it arrived at, so there's no way to aim, and the computer paddle either tracks the ball perfectly and never loses, or it's been crippled with a random miss chance that feels like the game is throwing the match. Both failures come from the same shortcut — treating the paddle as a flat wall and the opponent as a lookup of ball.y . The two things that make Pong feel like Pong are small and specific. The bounce angle has to depend on where along the paddle the ball landed, so hitting near an edge is a real tactical choice. And the computer has to move toward the ball at a limited speed rather than teleporting to it, so it loses to shots that are genuinely too fast for it rather than to a dice roll. Here it is running — click Start, then mo…