guides
Game Development
Pygame and Arcade physics, collision, and game loop optimisation.
Published May 30, 2026
Game Loop
def game_loop(entities, dt):
for entity in entities:
entity.x += entity.vx * dt
entity.y += entity.vy * dt
entity.vy += 9.8 * dt
Collision Detection (AABB)
def aabb_collide(a, b):
return (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)
Vector Math
def normalize(vx, vy):
length = (vx * vx + vy * vy) ** 0.5
if length == 0:
return 0, 0
return vx / length, vy / length