Taking graphics programming to the next level with SDL! This demonstrates real collision detection between moving objects and particle explosion effects. Building on the concepts from my JavaScript fireworks project, but implementing them in C for deeper understanding of game engine fundamentals.
Eight colorful squares bouncing around the screen, but here's where it gets interesting: when two squares collide, they explode into a burst of 25 colorful particles that fall with gravity and fade out over time! The colliding squares immediately respawn at new positions with fresh colors and velocities. It's like a continuous fireworks show triggered by physics.
cd c/pixel_renderer
# Install SDL2 if you don't have it (Ubuntu/Debian)
make install-deps
# Build and run
make build-runPress ESC to exit, or any other key to reset the simulation with new colors!
This implements several advanced game development concepts in a classic game loop architecture:
- Handle Input - Process keyboard events and user interactions
- Update Game State - Move squares, detect collisions between objects, spawn particle explosions
- Update Particles - Apply gravity, reduce particle life, handle fading effects
- Render Graphics - Draw squares, render particles with alpha blending, present frame
- Frame Rate Control - Maintain 60 FPS for smooth animation
The collision detection uses bounding box intersection - when two squares overlap, they explode into particles using the same trigonometric spread pattern from my JavaScript fireworks, but implemented in C with proper memory management.
- Number of squares (line 25): Change
NUM_SQUARESto 4 or 12 for different collision frequencies - Particle count (line 26): Adjust
MAX_PARTICLESfor more/fewer explosion effects - Explosion size (line 27): Modify
PARTICLE_LIFEfor longer/shorter particle trails - Square size (line 28): Change
SQUARE_SIZEto alter collision probability - Explosion intensity (line 94): Modify the particle count in
create_explosion(currently 25) - Gravity strength (line 170): Adjust the
0.1fvalue for different particle physics - Speed range (lines 48-49): Change velocity calculations for faster/slower movement
This project taught me advanced game development concepts that go well beyond basic graphics:
- Object collision systems - Implementing proper bounding box detection between multiple moving entities
- Particle system architecture - Managing hundreds of short-lived objects with different lifespans
- Memory management patterns - Using fixed-size arrays and active flags for efficient object pooling
- Multi-system coordination - Squares create particles, particles respond to physics, all rendering in sync
- Performance optimization - Handling 200+ particles at 60 FPS requires efficient update loops
What's exciting is seeing how this connects to my JavaScript fireworks project - the same mathematical concepts (trigonometry, gravity, fading) work in both languages, but C gives me direct control over memory layout and performance. This is exactly the foundation I need for building game engines where managing thousands of sprites and particles efficiently matters.