Skip to content

Quadstronaut/Pong

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pong — Learning Suite

Six complete implementations of Pong, each in a different language or framework. Every variant implements the exact same game with the exact same physics, AI, and rules so you can read them side-by-side and see how the same concepts translate across ecosystems.

Variants

Directory Language Framework Level
pygame/ Python PyGame Beginner
html5/ JavaScript Vanilla Canvas Beginner
love2d/ Lua LÖVE2D Beginner
godot4/ GDScript Godot 4 Intermediate
raylib/ C Raylib Intermediate
unity/ C# Unity Intermediate

What Every Variant Teaches

The universal game loop

All six variants share the same three-phase loop, just spelled differently:

┌─────────────────────────────────────────────────┐
│  1. Gather input                                │
│  2. Update state (move objects, check collisions│
│  3. Render (draw everything to screen)          │
└─────────────────────────────────────────────────┘
Variant Loop mechanism
PyGame while running: + clock.tick(60)
HTML5 requestAnimationFrame(loop)
LÖVE2D love.update(dt) + love.draw() callbacks
Raylib while (!WindowShouldClose())
Godot 4 _process(delta) + _draw() (engine-driven)
Unity Update() + render pipeline (engine-driven)

Delta time

Every variant multiplies velocity by delta time (dt) so movement is frame-rate independent:

# PyGame
ball.x += ball.vx * dt

# LÖVE2D
ball.x = ball.x + ball.vx * dt

# Raylib (C)
ball.x += ball.vx * dt;

# HTML5
ball.x += ball.vx * dt;

# GDScript
position += velocity * delta

# Unity (C#)
transform.position += new Vector3(velocity.x * dt, velocity.y * dt, 0f);

AABB collision

All six use Axis-Aligned Bounding Box collision — the simplest 2-D overlap test:

Two rectangles overlap when neither is entirely to the left, right, above, or below the other.

A overlaps B  ⟺  A.x < B.x+B.w  AND  A.x+A.w > B.x
               AND  A.y < B.y+B.h  AND  A.y+A.h > B.y

The AI

All six AIs use the same algorithm: move the paddle toward the ball's y-centre, limited by PADDLE_SPEED × difficulty × dt. The difficulty factor (0.80) makes the AI beatable.

Running Each Variant

PyGame (Python)

cd pygame
pip install -r requirements.txt
python pong.py

HTML5 (JavaScript)

Open html5/index.html in any modern browser. No install required.

LÖVE2D (Lua)

Install LÖVE2D 11.x from https://love2d.org/

love love2d/

Windows: drag the love2d/ folder onto love.exe

Godot 4 (GDScript)

  1. Install Godot 4.2+ from https://godotengine.org/
  2. Open Godot → Import → select godot4/project.godot
  3. Press F5 to run

Raylib (C)

cd raylib
# Install raylib first (see Makefile header for instructions)
make run

Unity (C#)

See unity/README.md for full scene setup instructions.

Controls (all variants)

Key Action
W or Move player paddle up
S or Move player paddle down
ENTER Start / restart
ESC Quit (where applicable)

Cross-Reference Map

Each source file is heavily commented with references to the equivalent code in the other five variants. When you read about velocity * delta in the PyGame version, the comment tells you exactly where to find the same line in LÖVE2D, Raylib, GDScript, HTML5, and C#.

Concepts Covered

  • Game loop and frame timing
  • Delta time and frame-rate independence
  • Velocity vectors and 2-D movement
  • AABB collision detection
  • Bounce angle variation (hit position → outgoing angle)
  • State machines (menu / playing / point / win)
  • Event systems (return values, callbacks, signals, C# events)
  • Component vs script architectures
  • Manual vs engine-driven physics

About

Pong implemented in 6 languages/frameworks: PyGame, HTML5 Canvas, LÖVE2D, Raylib (C), Godot 4, Unity — heavily commented learning suite

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors