📝 Worksheet← Lesson← Course
BitWithBite
Pygame Mastery · Quick Reference

Physics Cheat Sheet

Pygame Mastery
In one line: Every simulation is Euler integration — vel += acc*dt then pos += vel*dt — gravity, bouncing, momentum and projectiles are just different ways of setting acceleration and velocity.

Key Ideas

1Euler Integration. Every physics step: vel += acc*dt, then pos += vel*dt — always update velocity from acceleration before position from velocity.
2Gravity. A constant downward acceleration (e.g. Vector2(0,980) px/sec²) added to acc.y every frame before integrating — nothing more exotic than that.
3Momentum. Mass × velocity. A heavier or faster object carries more momentum into a collision.
4Elastic Collisions (equal mass). Swap the velocity components along the axis connecting the two objects' centers — the simplest, most common case in games.
5Restitution & Bouncing. Reverse the velocity component perpendicular to the surface, scaled by a 0–1 restitution value; each bounce loses a little energy.
6Projectile Motion. vx=speed*cos(angle), vy=-speed*sin(angle) — negative because Pygame's y-axis increases downward — then let gravity take over.

Bounce + Gravity

GRAVITY = pygame.Vector2(0, 980)
RESTITUTION = 0.7

def update(body, dt, floor_y, radius):
  body.vel += GRAVITY * dt
  body.pos += body.vel * dt
  if body.pos.y + radius >= floor_y:
    body.pos.y = floor_y - radius
    body.vel.y *= -RESTITUTION

Projectile Launch

angle_rad = math.radians(angle_degrees)
vx = speed * math.cos(angle_rad)
vy = -speed * math.sin(angle_rad)
# up is -y in Pygame

Equal-Mass Collision

direction = (b.pos - a.pos).normalize()
va = a.vel.dot(direction)
vb = b.vel.dot(direction)
a.vel += (vb - va) * direction
b.vel += (va - vb) * direction
# net effect: velocities swap
heighttime
Each bounce reverses vel.y × RESTITUTION, so peak height shrinks a little every impact.