Skip to content

Tutorial Pong

Gabe1290 edited this page Sep 10, 2026 · 3 revisions

Tutorial: Create a Classic Pong Game

Select your language / Choisissez votre langue / Wählen Sie Ihre Sprache:

English | Français | Deutsch | Italiano | Español | Português | Slovenščina | Українська | Русский


Introduction

In this tutorial, you'll create a classic Pong game - one of the first video games ever made! Pong is a two-player game where each player controls a paddle and tries to hit the ball past their opponent's paddle to score points.

What you'll learn:

  • Creating sprites for paddles, ball, and walls
  • Handling keyboard input for two players
  • Making objects bounce off each other
  • Tracking and displaying scores for both players
  • Using global variables

Difficulty: Beginner Preset: Beginner Preset


Step 1: Plan Your Game

Before we start, let's understand what we need:

Element Purpose
Ball Bounces between players
Left Paddle Player 1 controls with W/S keys
Right Paddle Player 2 controls with Up/Down arrows
Walls Top and bottom boundaries
Goals Invisible areas behind each paddle to detect scoring
Score Display Shows both players' scores

Step 2: Create the Sprites

2.1 Ball Sprite

  1. In the Resource Tree, right-click on Sprites and select Create Sprite
  2. Name it spr_ball
  3. Click Edit Sprite to open the sprite editor
  4. Draw a small white circle (about 16x16 pixels)
  5. Click OK to save

2.2 Paddle Sprites

We'll create two paddles - one for each player:

Left Paddle (Player 1):

  1. Create a new sprite named spr_paddle_left
  2. Draw a tall, thin rectangle curved like a parenthesis ")" - blue color recommended
  3. Size: approximately 16x64 pixels

Right Paddle (Player 2):

  1. Create a new sprite named spr_paddle_right
  2. Draw a tall, thin rectangle curved like a parenthesis "(" - red color recommended
  3. Size: approximately 16x64 pixels

2.3 Wall Sprite

  1. Create a new sprite named spr_wall
  2. Draw a solid rectangle (gray or white)
  3. Size: 32x32 pixels (we'll stretch it in the room)

2.4 Goal Sprite (Invisible)

  1. Create a new sprite named spr_goal
  2. Make it 32x32 pixels
  3. Leave it transparent or make it a solid color (it will be invisible in the game)

The Sprite Editor with spr_ball open, origin centered; spr_ball, spr_paddle_left, spr_paddle_right, spr_wall and spr_goal in the resource tree


Step 3: Create the Wall Object

The wall object creates boundaries at the top and bottom of the play area.

  1. Right-click on Objects and select Create Object
  2. Name it obj_wall
  3. Set the sprite to spr_wall
  4. Check the "Solid" checkbox - this is important for bouncing!
  5. No events needed - the wall just sits there

obj_wall's Object Events panel: empty -- Solid checked is all it needs


Step 4: Create the Paddle Objects

4.1 Left Paddle (Player 1)

  1. Create a new object named obj_paddle_left
  2. Set the sprite to spr_paddle_left
  3. Check the "Solid" checkbox

Add Keyboard Events for Movement:

Event: Keyboard Press W

  1. Add Event → Keyboard → Press W
  2. Add Action: MoveSet Vertical Speed
  3. Set vertical speed to -8 (moves up)

Event: Key Release W

  1. Add Event → Keyboard → Release W
  2. Add Action: MoveSet Vertical Speed
  3. Set vertical speed to 0 (stops moving)

Event: Keyboard Press S

  1. Add Event → Keyboard → Press S
  2. Add Action: MoveSet Vertical Speed
  3. Set vertical speed to 8 (moves down)

Event: Key Release S

  1. Add Event → Keyboard → Release S
  2. Add Action: MoveSet Vertical Speed
  3. Set vertical speed to 0 (stops moving)

Event: Collision with obj_wall

  1. Add Event → Collision → obj_wall
  2. Add Action: MoveBounce (no configuration needed — it always bounces off solid objects)

4.2 Right Paddle (Player 2)

  1. Create a new object named obj_paddle_right
  2. Set the sprite to spr_paddle_right
  3. Check the "Solid" checkbox

Add Keyboard Events for Movement:

Event: Keyboard Press Up Arrow

  1. Add Event → Keyboard → Press Up
  2. Add Action: MoveSet Vertical Speed
  3. Set vertical speed to -8

Event: Key Release Up Arrow

  1. Add Event → Keyboard → Release Up
  2. Add Action: MoveSet Vertical Speed
  3. Set vertical speed to 0

Event: Keyboard Press Down Arrow

  1. Add Event → Keyboard → Press Down
  2. Add Action: MoveSet Vertical Speed
  3. Set vertical speed to 8

Event: Key Release Down Arrow

  1. Add Event → Keyboard → Release Down
  2. Add Action: MoveSet Vertical Speed
  3. Set vertical speed to 0

Event: Collision with obj_wall

  1. Add Event → Collision → obj_wall
  2. Add Action: MoveBounce (no configuration needed — it always bounces off solid objects)

obj_paddle_left's Object Events panel: Keyboard (held) and Keyboard Release with W/S, plus Collision with obj_wall (Bounce). obj_paddle_right is the same with the Up/Down arrows


Step 5: Create the Ball Object

  1. Create a new object named obj_ball
  2. Set the sprite to spr_ball

Event: Create

  1. Add Event → Create
  2. Add Action: MoveStart Moving (Direction)
  3. Check one diagonal box in the 3x3 direction picker (not straight up or down)
  4. Set speed to 6

Event: Collision with obj_paddle_left

  1. Add Event → Collision → obj_paddle_left
  2. Add Action: MoveBounce (no configuration needed — it always bounces off solid objects)

Event: Collision with obj_paddle_right

  1. Add Event → Collision → obj_paddle_right
  2. Add Action: MoveBounce (no configuration needed — it always bounces off solid objects)

Event: Collision with obj_wall

  1. Add Event → Collision → obj_wall
  2. Add Action: MoveBounce (no configuration needed — it always bounces off solid objects)

obj_ball's Object Events panel: Create (Start Moving), and Collision with obj_paddle_left, obj_paddle_right and obj_wall (each a Bounce)


Step 6: Create the Goal Objects

Goals are invisible areas behind each paddle. When the ball enters a goal, the opposing player scores.

6.1 Left Goal

  1. Create a new object named obj_goal_left
  2. Set the sprite to spr_goal
  3. Uncheck "Visible" - the goal should be invisible
  4. Check "Solid"

6.2 Right Goal

  1. Create a new object named obj_goal_right
  2. Set the sprite to spr_goal
  3. Uncheck "Visible"
  4. Check "Solid"

6.3 Add Goal Collision Events to the Ball

Go back to obj_ball and add these events:

global.p1score/global.p2score are custom named variables, one per player — the built-in Set Score action doesn't fit here, since it always writes to the single built-in score, with no way to point it at a variable name. Set Variable is the real action for a custom named variable and supports a global scope:

Event: Collision with obj_goal_left

  1. Add Event → Collision → obj_goal_left
  2. Add Action: MoveJump to Start Position (resets the ball)
  3. Add Action: ControlSet Variable
    • Variable: p2score
    • Value: 1
    • Scope: global
    • Check "Relative" (adds 1 to current score)

Event: Collision with obj_goal_right

  1. Add Event → Collision → obj_goal_right
  2. Add Action: MoveJump to Start Position
  3. Add Action: ControlSet Variable
    • Variable: p1score
    • Value: 1
    • Scope: global
    • Check "Relative"

obj_ball after Step 6: the two paddle/wall bounces from Step 5 plus Collision with obj_goal_left and obj_goal_right (Jump to Start + Set Variable). obj_goal_left/obj_goal_right themselves have no events -- they're invisible, solid, shown here in green only so the placement reads


Step 7: Create the Score Display Object

  1. Create a new object named obj_score
  2. No sprite needed

Event: Create

  1. Add Event → Create
  2. Add Action: ControlSet Variable
    • Variable: p1score, Value: 0, Scope: global
  3. Add Action: ControlSet Variable
    • Variable: p2score, Value: 0, Scope: global

Event: Draw

  1. Add Event → Draw
  2. Add Action: DrawDraw Text
    • Text: Player 1:
    • X: 10
    • Y: 10
  3. Add Action: DrawDraw Variable
    • Variable: global.p1score
    • X: 100
    • Y: 10
  4. Add Action: DrawDraw Text
    • Text: Player 2:
    • X: 10
    • Y: 30
  5. Add Action: DrawDraw Variable
    • Variable: global.p2score
    • X: 100
    • Y: 30

obj_score's Object Events panel: Create (two Set Variable actions) and Draw (two Draw Text + two Draw Variable actions), with no sprite set


Step 8: Design the Room

  1. Right-click on Rooms and select Create Room
  2. Name it room_pong
  3. Set the room size (e.g., 640x480)

Place the objects:

  1. Walls: Place obj_wall instances along the top and bottom edges of the room
  2. Left Paddle: Place obj_paddle_left near the left edge, centered vertically
  3. Right Paddle: Place obj_paddle_right near the right edge, centered vertically
  4. Ball: Place obj_ball in the center of the room
  5. Goals:
    • Place obj_goal_left instances along the left edge (behind where the paddle is)
    • Place obj_goal_right instances along the right edge
  6. Score Display: Place obj_score anywhere (it doesn't have a sprite, it just draws text)

Room Layout Example:

[WALL WALL WALL WALL WALL WALL WALL WALL WALL WALL]
[GOAL]  [PADDLE_L]            [BALL]            [PADDLE_R]  [GOAL]
[GOAL]  [PADDLE_L]                              [PADDLE_R]  [GOAL]
[GOAL]                                                      [GOAL]
[WALL WALL WALL WALL WALL WALL WALL WALL WALL WALL]

The Room Editor for room_pong: tan wall rows across the top and bottom, green goal columns down the left and right edges, the blue and red paddles near each side, the ball in the centre, and obj_score just inside the top wall


Step 9: Test Your Game!

  1. Click Run or press F5 to test your game
  2. Player 1 uses W (up) and S (down)
  3. Player 2 uses Up Arrow and Down Arrow
  4. Try to hit the ball past your opponent's paddle!

Enhancements (Optional)

Speed Increase

Make the ball faster each time it hits a paddle. speed isn't usable here directly — on this engine it's the sprite's animation rate, not movement speed — so track the ball's own speed in a custom variable instead:

  1. In obj_ball's Create event, add ControlSet Variable (Variable: ball_speed, Value: 6) right after the Start Moving action.
  2. In each paddle-collision event, after the Bounce action, add ControlSet Variable (Variable: ball_speed, Value: 0.5, Relative checked), then MoveSet Speed with Value: self.ball_speed to apply the new speed while keeping the current direction (Bounce already flipped it).

Sound Effects

Add sounds when:

  • The ball hits a paddle
  • The ball hits a wall
  • A player scores

Win Condition

Add a check in the Draw event:

  • If global.p1score >= 10, display "Player 1 Wins!"
  • If global.p2score >= 10, display "Player 2 Wins!"

Troubleshooting

Problem Solution
Ball goes through paddle Make sure paddles have "Solid" checked
Paddle doesn't stop at walls Add collision event with obj_wall
Score doesn't update Check that variable names match exactly (global.p1score, global.p2score)
Ball doesn't move Check the Create event has the movement action

What You Learned

Congratulations! You've created a complete two-player Pong game! You learned:

  • How to handle keyboard input for two different players
  • How to use Key Release events to stop movement
  • How to make objects bounce off each other
  • How to use global variables to track scores
  • How to display text and variables on screen

See Also

Clone this wiki locally