Tossing Balls
High school graduation project — 2D physics puzzle game with Box2D integration and data-driven level loading
Overview
A high school graduation project (maturitetna naloga) — an Angry Birds-style 2D physics puzzle game where the player fires balls from a rotatable cannon at structures made of wood, stone, and glass blocks. Box2D handles realistic physics simulation with impulse-based damage, levels are entirely data-driven via XML, and the rendering uses OpenGL with a custom camera mapping between Box2D world coordinates and screen coordinates. ~3,800 lines across 38 source files, built at age 17.
Architecture
The core entity system uses a clean inheritance tree: gEntity (abstract base with Render/Update/MouseOver) branching into TBBody (physics-enabled), TBSprite (static), TBCannon (composite), gButton (interactive UI), and TBDialog (container). WorldContext acts as the central state container owning the b2World, Camera, all entities, and a deferred disposal queue. TBWorld is a factory class handling dual creation of game entities and corresponding Box2D physics bodies linked via SetUserData.
Code Highlights
void TossingBalls::BeginContact(b2Contact* contact) {
TBBody* a = static_cast<TBBody*>(body1->GetUserData());
TBBody* b = static_cast<TBBody*>(body2->GetUserData());
if(a && b) {
if(a->getType() != EBT_groundObject) a->collision = true;
if(b->getType() != EBT_groundObject) b->collision = true;
}
}
void TossingBalls::PostSolve(b2Contact* contact, const b2ContactImpulse* impulse) {
if(a->collision) { a->force = impulse->normalImpulses[0]; a->collision = false; }
if(b->collision) { b->force = impulse->normalImpulses[0]; b->collision = false; }
}Highlights
- High school graduation project (age 17) — built a complete 2D physics game engine from scratch in C++ with a custom entity system, polymorphic animation framework, Box2D physics integration, and data-driven level loading from XML
- Implemented a correct three-phase Box2D collision protocol: flag contacts in BeginContact, capture impulse magnitudes in PostSolve, apply HP damage in EndContact
- Fully data-driven architecture: levels, UI layouts, game config, textures, and sounds all externalized into XML and INI files requiring zero code changes to add content
- Composable animation system with five animator types (fade, blink, scale, image sequence, timed stop) attachable to any entity via a vector
Related Projects
Monte Carlo Path Tracer + Spline Engine
Physically-based renderer with importance sampling and a functorial spline animation system
Physically-based Monte Carlo path tracer implementing the rendering equation with importance sampling, Russian roulette termination, explicit direct light sampling via solid-angle cone sampling, and three BxDF models (Lambertian, specular with Fresnel, Oren-Nayar rough diffuse)
3D Rendering Engine with Shadow Mapping
Custom OpenGL engine comparing four shadow mapping algorithms with runtime switching
Implemented and compared four shadow mapping algorithms (default, PCF, VSM with Gaussian blur, CSM with per-cascade resolution) in a single engine with runtime switching
Pac-Man
Arcade-faithful clone with per-ghost personality AI and A* pathfinding
Implemented authentic Pac-Man ghost AI with per-ghost personality targeting algorithms (direct pursuit, 4-tile ambush, vector-doubling flanking, distance-threshold retreat) faithfully matching the original arcade's documented behavior