Specialization Project

Falling Sand Game in TGA2D Engine

Project Summary

I attempted to create a falling sand game using the TGA2D engine. While it didn't go exactly as planned, I worked around challenges to deliver a functional result. I hope to improve on this project in my free time using a better-suited engine.

My Falling Sand Game

Reference: Falling sand game footage from YouTube

Implementation Details

I created a falling sand game utilizing the TGA2D game engine. The architecture included a sand world to govern all aspects, a sand manager to oversee particle behavior, and IMGUI for the user interface. For rendering, I employed a sprite batch technique.

To optimize performance, I implemented a Grid system and threaded the sand manager. The UI at the bottom displays: current sand count, selected sand type, mouse position, sand type buttons with colors, a brush size slider, and a wall collider toggle to contain particles on screen.

I created a brush system supporting various sizes for efficient sand spawning. Additionally, I developed an image-to-sand converter that allows importing images via code or drag-and-drop, converting each pixel to the nearest sand type.

A key lesson: after encountering batch rendering difficulties in week two, I should have reassessed my approach. Instead, I persisted and lost valuable time. In hindsight, building a basic engine myself or choosing a better-documented engine would have been wiser.

Plan vs. What Actually Happened

Original Plan

  • Week 1: Research, download TGA2D, set up Perforce, get base game working
  • Week 2: Add SandWorld, Sand, Sand Type, SandManager
  • Week 3: Add Grid/Chunks, Threading, ObjectPool
  • Week 4: 3 days Optimization, 1 day Debugging
  • Week 5: 4 days Polish/Debugging

What Actually Happened

  • Week 1: Research, download TGA2D, set up Perforce, base game working
  • Week 2: Add SandWorld, Sand, Sand Type, SandManager
  • Week 3: SpriteBatch, Threading, ObjectPool — batch rendering problems
  • Week 4: 1 day Optimization, 3 days Debugging batch rendering
  • Week 5: 2 days Polish, 2 days Debugging — crisis management mode

Each Thursday was for debugging, and Friday I stepped back to adjust the plan — this didn't always hold.

Classes Created

  • Sand.cpp — Collider, Sprite, Texture, Position, Velocity, Size, Acceleration, Density, Friction, Type, Name, ID, Gravity
  • SandManager.cpp — Tracks all sand: spawning, removing, manipulation
  • SandType.cpp — Sand parameters: Name, Tooltip, texturePath
  • SandWorld.cpp — Centralized game control
  • ObjectPool.hpp — Basic object pooling system
  • UI.cpp — All UI via IMGUI
  • Utilities.hpp — Drag and drop functions

Sand Types

Sand – sinks in water
Water – eats salt
Water Well – water source
Stone – does not move
Fire – burns stuff
Torch – fire source
Plant – grows if watered
Oil – burns on fire contact
Oil Well – oil source
Methane – steam but flammable
Eraser – removes other sands
Salt – dissolves in water
Acid – eats most things
Steam – fire meets water
Lava – mix of fire and stone