# Pong Complete two-player game in ~150 lines. ```{raw} html ▶ Run in browser ``` **Tags:** `game` `input-actions` `signals` `collision` A classic Pong demonstrating input actions, signals, collision detection, and game-state management. Player 1 uses W/S, player 2 uses Up/Down arrows. ## What you will learn - **Input actions**: Bind keys to named actions with `InputMap.add_action()`. - **Input.get_strength()**: Read analogue input strength for smooth movement. - **Signals**: Decouple game events (the ball emits `scored` when it passes a paddle). - **Collision**: Manual AABB overlap for paddle-ball bouncing. - **Game state**: Track and display scores. ## How it works Three node types compose the game: - `Paddle` reads two input actions (up/down) and clamps position to the screen. - `Ball` moves at a velocity, bounces off top/bottom edges, and emits a `scored` signal when it exits left or right. - `PongGame` (root) declares `input_actions = {...}` at class scope, creates paddles and ball in `on_ready()`, connects the `scored` signal to update the score, and handles paddle-ball collision in `on_process()` by reflecting the ball's velocity based on where it hits the paddle. The `input_actions` class attribute is the canonical registration path: the scene tree consumes it at mount and re-applies on every `change_scene` swap. It also works correctly under the web exporter, which instantiates the root class directly without invoking `main()`. ## Source ```{literalinclude} ../../examples/demos/pong.py :language: python :linenos: ```