2D builder

Overview

A foundational 2D sandbox building game prototype, inspired by Terraria, was conceptualized, generated, debugged, and refined using primarily Large Language Model (LLM) interaction. The game was written entirely in Python 3.11 using the Pygame and noise libraries, strictly adhering to the constraints of a single .py file and no external assets.

The result: a self-contained, runnable prototype demonstrating core mechanics of the genre, including procedural world generation, tile-based building and destruction, physics-driven player movement, basic enemy AI, and a dynamic camera system.

Implemented Mechanics and Systems

  1. Core Gameplay & Interaction
    • Player Character: Controlled via WASD/Arrows with physics-based movement (gravity, acceleration).
    • Jumping: Standard jump mechanic triggered by Space/W/Up Arrow.
    • Tile Interaction: Mouse-driven block breaking (left-click) and placing (right-click) within a defined player reach.
    • Item Selection: Cycling through placeable block types (Dirt, Stone, Grass) via mouse wheel or number keys (1-3).
    • Collision System: Accurate tile-based collision detection and resolution for player and enemies.
  2. World System
    • Procedural Generation: Infinite-feeling world created using Perlin noise (noise library) for terrain height, distinct layers (Grass, Dirt, Stone), and basic cave formation. World seed displayed for reproducibility.
    • Tile Grid: Efficient dictionary-based storage for potentially large worlds, managing Tile objects with properties (solid, color).
    • Dynamic Tile Updates: Simple world logic, such as grass growing on exposed dirt or turning to dirt when covered.
  3. Enemy System
    • Slime Archetype: Basic “Slime” enemy with patrol behavior (moving side-to-side), edge/wall detection for turning, and randomized jumping AI.
    • Procedural Spawning: Enemies spawn dynamically near the player based on proximity, ground availability, and a maximum count.
    • Basic Combat Interaction: Player knockback upon collision with enemies.
  4. Camera & UI Feedback
    • Dynamic Camera: Smoothly follows the player’s position.
    • Visual Feedback: Mouse cursor highlights the targeted tile within reach, changing color based on interaction distance.
    • Basic UI: Displays the currently selected block type and a visual preview.
    • Debug Overlay: Toggleable (F3) display showing FPS, player/camera coordinates, velocity, entity counts, and world seed.

LLM-Driven Efficiency

The entire system was generated from a single, detailed prompt, showcasing:

  • Zero external assets: All visuals are procedurally drawn rectangles; no image or sound files were used.
  • Constraint Adherence: Strictly followed the single-file Python script requirement.
  • Rapid Prototyping: Core mechanics were established quickly through generated code structure and logic.
  • Iterative Refinement: Debugging and minor feature adjustments (like error correction based on Pylance feedback) were handled through conversational interaction with the LLM.
  • Procedural Focus: All core content (world layout, enemy placement) is generated algorithmically at runtime.

Final Deliverable

  • Approximately 700 lines of structured Python code within a single file.
  • Runnable .py requiring only Pygame and noise library installations.
  • A functional proof-of-concept for a 2D sandbox builder, generated without manual coding or traditional game engines.