[KongchangAI]
· 2 min read· 1,458 words

Building an FPS Game with ECS Architecture and AI: A First-Person Shooter from Scratch

Building an FPS Game with ECS Architecture and AI: A First-Person Shooter from Scratch

Build a fully functional FPS game from scratch using ECS architecture combined with AI-assisted programming.

This article uses the "Zone N" FPS game as a case study to explain the core principles of ECS (Entity-Component-System) architecture and how AI-assisted programming tools like GitHub Copilot, Cursor, and Claude can help developers rapidly build a first-person shooter complete with movement, shooting, magazine management, and a minimap — all from scratch.

Introduction: A New Paradigm for AI-Assisted Game Development

As AI programming tools continue to mature, the barrier to game development is being redefined. This article uses the "Zone N" FPS game development project — shared by a Bilibili creator — as a case study to demonstrate how to combine the classic ECS (Entity-Component-System) architecture with AI-assisted programming to build a fully functional first-person shooter with movement, shooting, magazine management, a minimap, and more, all from scratch.

The project has two standout highlights: it uses the industry-recognized ECS architecture for system design, and it leverages AI to help generate code and accelerate development iteration. The project is still ongoing, but it already demonstrates a clear architectural approach and a working game prototype.

What Is ECS Architecture

ECS is a data-oriented architectural pattern that emphasizes "composition over inheritance." It is widely used in modern game engines (such as Unity's DOTS and parts of Unreal's subsystems). It consists of three core concepts:

Industry Background: The rise of ECS architecture stems from game engineers' long-standing frustration with "deep inheritance chains." In traditional object-oriented game development, developers often built massive class inheritance trees (e.g., GameObject → Character → Player). As features evolved, these trees became bloated and led to hard-to-maintain problems like "diamond inheritance." ECS fundamentally avoids this pitfall by completely decoupling data (Components) from logic (Systems). Unity's DOTS (Data-Oriented Technology Stack), introduced in 2018, combines ECS principles with CPU cache-friendly memory layouts. When handling large-scale entity scenes (e.g., tens of thousands of soldiers on screen simultaneously), performance improvements of tens of times have been demonstrated, thoroughly validating the engineering value of this architecture.

Entity

An entity is simply an "identity" — it carries no concrete logic or data. In this project, developers first initialize an entity as a carrier onto which functionality is later attached. Think of an entity as an empty shell; what truly defines what it "is" are the components attached to it.

At the technical implementation level, an Entity is typically just an integer ID (e.g., uint32_t entityId = 42), so lightweight it incurs almost no memory overhead. This design allows the engine to efficiently create and destroy thousands of entities in bulk, without the performance cost of object instantiation in traditional object-oriented programming.

We initialize an entity

Component

Components define an entity's properties and behaviors. An entity's position updates, per-frame update logic, and performance characteristics are all defined by its components. After creating a component, developers attach it to the corresponding entity. A single entity is typically composed of multiple components, which together give it specific behavioral capabilities.

The greatest advantage of this design is that behaviors can be shared and reused across different entities. For example, a "Movable" component can be attached to both the player and enemies without duplicating logic. In terms of memory organization, ECS typically stores the same type of Component data contiguously (Structure of Arrays, SoA), allowing the CPU to fully exploit cache locality when batch-processing entities of the same type. This is the core performance advantage of ECS over traditional OOP.

This entity

System

In this project, the System layer is handled by the EntityManager. Developers set each entity's parent to the EntityManager, which then uniformly manages all entities.

A System's responsibility is to "iterate over all entities that possess a specific combination of components and execute logic on them." For example, a "Rendering System" only cares about entities that have both a TransformComponent and a MeshComponent, and doesn't need to know anything about the "Sound System" or "AI System." This separation of concerns allows each system to be developed, tested, and optimized independently.

Set its parent

How the Update Loop Works

The essence of ECS architecture is reflected in the game's main loop. Each iteration, the EntityManager calls the update method on all entities it manages; and an entity's update is essentially calling the update on each of its attached components.

This creates a clear call chain:

EntityManager.update()
   → Entity.update()
      → Component.update()

Since components hold a reference to their entity, they can modify the entity's position, state, and other attributes during update, ultimately driving visual and logic updates. This layered invocation keeps each part focused on its own responsibility, resulting in clean, extensible code.

Holds a reference to this entity

Separating Physics Calculations from Regular Updates

Interestingly, the developer intentionally separates physics engine calculations from regular position updates. Physics-related motion (such as gravity, collision, and ballistics) requires a dedicated calculation pipeline and cannot simply be merged into the regular position update.

This separation is typically implemented in engineering through a Fixed Timestep mechanism. The regular update() is tied to the screen frame rate (e.g., 60 FPS, approximately 16.7ms per frame), while the physics fixedUpdate() runs independently at a fixed frequency (typically 50Hz, every 20ms), with the two synchronized visually through interpolation. This design effectively prevents frame rate fluctuations from causing abnormal physics behavior — such as bullets passing through thin walls at low frame rates, or characters bouncing too high at high frame rates. It is the core engineering principle behind Unity's separation of FixedUpdate and Update. For FPS games, this directly impacts the "feel" and "physical authenticity" perceived by the player.

Implementing Core FPS Game Features

Building on the ECS architecture above, the project has implemented the core gameplay elements of an FPS game:

  • Character Movement: WASD controls for moving the player through the scene
  • Shooting and Weapon System: Mechanics for firing, magazine management, and more
  • Enemy System: Interactive enemy units placed throughout the scene

Minimap System

The developer also implemented a minimap feature — an important component for improving playability in FPS games. The minimap displays in real time:

  • The player's current position and facing direction
  • Locations of magazines to be picked up
  • The distribution of enemies

With the minimap, players can better perceive the battlefield situation. This also reflects the plug-and-play nature of feature modules under ECS architecture — the minimap, as an independent display system, only needs to subscribe to each entity's TransformComponent (position data) to complete rendering, without intruding into the internal logic of the player system or enemy system. This is a vivid embodiment of the core ECS principle of "decoupling systems through data."

The Value of AI-Assisted Programming in Game Development

The most characteristic aspect of this project for our era is that AI assists in generating game code. Today's mainstream AI programming tools (such as GitHub Copilot, Cursor, and Claude) are based on large language model (LLM) technology. Pre-trained on vast amounts of open-source code, they can understand code context and generate pattern-consistent code. In a highly modular architecture like ECS — where each component's responsibilities are clearly defined — AI-assisted programming can deliver an even greater collaborative effect:

  1. Standardized Component Generation: ECS components typically follow fixed interface specifications (such as requiring an update method to be implemented). This kind of highly standardized "code pattern" is precisely the structure that LLMs are best at recognizing and reproducing, resulting in AI-generated code with higher usability and consistency.
  2. Reuse of Repetitive Logic: AI can quickly generate structurally similar components and systems, reducing the amount of manual boilerplate code writing and allowing developers to focus their energy on game design itself.
  3. Rapid Prototype Iteration: From an empty scene to a working FPS prototype, AI dramatically shortens the cycle from idea to implementation and lowers the cognitive barrier for newcomers entering game development.

ECS's "compositional" design philosophy complements AI's code generation capabilities well — clear architectural constraints make AI output more controllable and easier to review, while AI in turn accelerates the rapid realization of the architecture.

Summary: A Practical Path for Game Development with ECS + AI

The "Zone N" project gives us a vivid case study: how to use an engineering-minded architecture (ECS) combined with AI programming tools to efficiently develop a fully functional FPS game.

Its core lessons can be summarized as follows:

  • Architecture First: ECS's entity-component-system layering makes complex game logic manageable and reusable, and provides clear pattern constraints for AI-assisted code generation.
  • Separation of Concerns: Distinguishing physics calculations (fixed timestep) from regular frame updates ensures system robustness and consistent game feel.
  • AI-Empowered Development: Under a well-defined architectural framework, AI can significantly boost development efficiency, reduce repetitive work, and enable even solo indie developers to build fairly complete game prototypes.

For developers who want to get into game development and also want to experience AI-assisted programming, the "ECS + AI" combination is undoubtedly a practical path worth exploring in depth. ECS provides clear engineering boundaries; AI bridges the gap in implementation details. Together, they make "building a game solo" more achievable than ever before.

Key Takeaways

#ECS architecture#FPS game development#AI-assisted programming#Entity-Component-System#game development tutorial#Unity DOTS#indie game development
Share:

Related articles