Join me live on December 18-19, 2024 for the 2D Text-Based Breakout Game Workshop and discover how to defuse traditional IF-heavy collision detection! We’ll dive into Anti-IF Programming, Emergent Design, and Test-Driven Development (TDD) to develop a collision system where each object handles interactions independently.
Challenge
One of my personal challenges—something I’ve been mulling over for years—is collision detection. We all know classic 2D games like Mario and Space Invaders. And if you think about it, the real magic, the moment that makes you cheer for Mario or brace yourself in Space Invaders, comes down to one thing: collision detection. Without it, there’s no game.
I’ve read countless articles and books on collision detection algorithms. And, time and again, the answer is the same: a centralized, algorithmic system that decides “from above” whether Mario has hit a coin or if a bullet from your base collides with an invader. This inevitably leads to code heavy with if statements—an omniscient logic that checks every condition.
But what if there’s another way? What if collisions could be detected directly between objects, in a decentralized, emergent, intentional object-driven way? And what if we developed this system one test at a time, incrementally and carefully?
This workshop was born to explore that question. It’s about creating a collision detection system that’s flexible, adaptable, and developed incrementally, one test at a time—where each object knows its role in a larger dance of interaction.
def detect_collision(rect, circ):
if circ.x + circ.radius < rect.x or circ.x - circ.radius > rect.x + rect.width:
return False
if circ.y + circ.radius < rect.y or circ.y - circ.radius > rect.y + rect.height:
return False
if rect.x <= circ.x <= rect.x + rect.width:
if rect.y - circ.radius <= circ.y <= rect.y + rect.height + circ.radius:
return True
if rect.y <= circ.y <= rect.y + rect.height:
if rect.x - circ.radius <= circ.x <= rect.x + rect.width + circ.radius:
return True
for corner_x, corner_y in [(rect.x, rect.y), (rect.x + rect.width, rect.y),
(rect.x, rect.y + rect.height), (rect.x + rect.width, rect.y + rect.height)]:
if ((circ.x - corner_x) 2 + (circ.y - corner_y) 2) <= circ.radius ** 2:
return True
return False
Workshop Highlights
🚀 Decentralized Collision Detection
🎯 Object-Driven Interactions
⚙️ Lowering the Cost of Change
👥 Hands-On Mentoring with me, Francesco Cirillo
Pricing & Enrollment
🎟 Individual & Group Discounts Available
⏱ 7 Hours of Hands-On Training Over 2 Days
Challenge Accepted? Ready to change the way you develop software? Register now!
Discover more from Defuse The If Strategy
Subscribe to get the latest posts sent to your email.
Like this:
Share this: