This phase focuses on the technical design and systems programming side of the project.
Here, i ask myself whether i can build a gameplay framework that is extensible enough for new mechanics and content, while keeping the systems understandable and safe for other programmers to work with.
I decided, rather than building each feature directly around Unity components, to focus on designing gameplay systems and objects responsible for the actual game rules, and separate those from systems that communicate the game's presentation with Unity.
The result is a framework built around reusable abstractions, explicit APIs, event-driven interactions, centralized content definitions, and clear ownership of game state.
The first phase of the project was deliberately focused on the framework rather than the individual game content.
I wanted gameplay classes to describe what they do, without requiring every new plant, zombie, or projectile to understand how the board, entities, projectiles, or Unity objects are implemented internally.
A plant should be able to express:
if (AnyZombiesInFront())
ShootProjectile(ProjectileType.Pea, ActorFace.PlantShooterMouth);
rather than manually searching lanes, inspecting entity collections, calculating positions, spawning objects, and communicating with Unity.
That distinction became the basis for much of the architecture.
A concrete plant should not need deep knowledge of the framework in order to implement its behaviour. Instead, the framework exposes operations such as:
AnyZombiesInFront()
ShootProjectile()
SummonSun()
AttemptMovingPlant()
and similar helpers.
This effectively creates a small gameplay language for content programmers.
One of the core design decisions was to separate gameplay objects from their Unity representations.
Plant, Zombie, and Projectile are gameplay classes. Their Unity-side representation is handled through EntityActor and its concrete implementations.
The gameplay object owns the game state and behaviour. The Actor owns the Unity representation: sprites, transforms, visual effects, sorting layers, and other presentation concerns.
This means the gameplay model does not need to inherit from MonoBehaviour or structure its behaviour around Unity's component lifecycle. Altough it is to note many scripts still implement the UnityEngine library, but most of the time this is simply to use its Debug class.
The intended boundary was that the gameplay framework could remain largely intact if the engine-facing layer were replaced. Not due to planning that it would, but because that comes with great advantages, such as developers not needing to know any Unity specific functionality to work on most of the game.
In practice, the current project still contains some framework-to-framework coupling that I would restructure in a second iteration, but the distinction between gameplay representation and engine representation is fundamental to the design.
Early in development, Plant, Zombie, and Projectile scripts shared enough functionality that I repeatedly found myself reworking the same systems in three different places.
Instead of continuing to duplicate those behaviours, I introduced an abstract Entity base class. It provides common functionality such as health and damage handling, death, status effects, team relationships, equipment, updates, and more (even if the number of these responsibilities get mentioned in Known Limitations & Hindsight).
The important part was not simply reducing code duplication. Once these objects shared a meaningful abstraction, higher-level systems could reason about them consistently. Systems such as damage, effects, equipment, targeting, and lifecycle management no longer needed to know whether they were dealing with a plant, zombie, or projectile.
I found this to be one of the most valuable architectural changes in the project because it turned several separate implementations into a coherent gameplay model.
Plants frequently need to react to zombies entering or leaving relevant areas.
One approach would have been to have every plant continuously search the board for zombies during every update.
Instead, TileData supports subscriptions to zombie movement.
A specific plant identifies the tiles it is interested in, the plant class subscribes it to them, and it receives callbacks when zombies enter or leave those tiles.
This changes the relationship from:
Plant repeatedly asks the board what is happening
to:
Board notifies the plant when relevant state changes
The same system also supports higher-level queries such as ZombiesInFront, ZombiesInArea, and ZombiesInRadius.
The result is a combination of event-driven notifications for persistent spatial relationships and query APIs for behaviours that need an immediate answer.
It also keeps the implementation of spatial bookkeeping inside the board framework rather than forcing every plant to reimplement it.
Another major architectural change came from how I initially approached zombie armour.
I originally considered armour to be a property of a specialized zombie subclass, such as an ArmoredZombie.
That, i found, became increasingly restrictive as soon as different entities could have different kinds of equipment or protections. Some protection behaves like a directional shield. Other equipment may behave differently, may be removable, or may interact with other systems.
I replaced the specialized inheritance approach with an Equipment abstraction that any Entity can own and manage.
Armor is then one implementation of equipment.
This allows behaviour to be composed onto entities instead of continually expanding the inheritance hierarchy. The pattern became useful beyond armour because it established a general rule: If a behaviour describes something an entity can possess rather than what that entity fundamentally is, it is a candidate for composition rather than inheritance.
I initially considered dividing plants into specialized behavioural categories such as attacking plants, sun producers, or walls.
That would have made the hierarchy increasingly restrictive once plants began combining behaviours.
Instead, plants share one common Plant abstraction and use independent tags/capabilities to describe properties. This allows a plant to combine capabilities without requiring a new branch of the inheritance hierarchy for every combination.
Content creation originally used simple factory-style mappings.
As the number of things the rest of the framework needed to know about each plant increased, I expanded that idea into PlantRegistry.
The registry centralizes many systems, such as construction, gameplay statistics, and visual references. Adding a plant therefore becomes a single registry definition rather than requiring the same information to be manually synchronized across several systems. For the framework's intended users, this creates a predictable workflow: register the content once, provide its definition, and the rest of the systems can retrieve what they need through the registry.
The same pattern was then applied to other entity types.
This was intentionally not designed as an elaborate data-driven content pipeline. It was a pragmatic way to create one authoritative boundary for content definitions and reduce the number of places that a programmer could accidentally forget to update.
Entity removal exposed one of the more interesting problems in the framework.
Originally, an entity could remove itself from the game's collections immediately, but that created a classic iteration problem:
while one entity was being updated, another entity could be killed and removed from the same collection currently being traversed.
My first solution was to hold the removal for until the end of the game update.
That solved the collection problem, but introduced another one: the entity still existed in the game's collections for the rest of the frame and could therefore remain visible to lookups performed by other entities. So any entity could see, or even target a dead one.
The final solution separated the two requirements.
Before updating, the current entity collections are copied into update buffers. Entities can then be removed from the actual game state immediately while the update traversal continues over the stable buffer.
This means that logical existence and iteration safety are handled independently.
That was a useful architectural lesson for the project: solving a technical problem is not necessarily the same as satisfying the underlying gameplay requirement.
The framework works, but there are several areas where I would design a theoretical second iteration differently.
Both managers accumulated more responsibilities than they should have.
GameManager currently combines game progression, persistent state, scene transitions, prefab creation, UI coordination, rewards, and other application-level concerns.
LevelManager similarly handles simulation updates, entity lifecycle, spatial queries, economy, tile manipulation, projectiles, and level flow.
The next iteration would split these responsibilities into smaller systems, with a clearer boundary between game state, simulation systems, and engine communication.
This would also clear the recurring "GameManager.Instance.LevelManager." throughout most of the systems, which while safe and Unity free, it highlights the problem with these classes.
The original spatial model made Lane the primary owner of zombies and TileData the primary owner of plants.
As the mechanics expanded, tiles also needed to know about zombies for enter/leave events and plant interactions.
In hindsight, I would likely make TileData the more fundamental spatial representation and treat a zombie's continuous X position as its relationship to the tiles it is crossing.
The current implementation performs well enough at the scale of this game, so this is primarily an architectural hindsight rather than a performance problem.
Some classes became broader as the framework matured.
The project demonstrates that the abstractions solved real problems, but it also showed me where “one convenient central API” can eventually become too large.
The Entity class has also accumulated too many responsibilities. I often use #region to organize related functionality, partly because those sections could later be extracted into separate classes. I have hesitated to do so when the extracted functionality would only be used by Entity, but separating these responsibilities could still improve maintainability.
By the end of Phase 1, I had a reusable gameplay framework rather than a collection of individual mechanics.
New content can interact with the framework through a defined set of APIs instead of directly manipulating the underlying implementation.
Gameplay entities are represented separately from their Unity-facing Actors.
Common functionality is shared through meaningful abstractions.
Optional behaviours use composition and capabilities where inheritance became restrictive.
Content is registered through centralized definitions.
Most importantly, the framework gave me something I could test as a technical-design problem:
Could another programmer understand it well enough to use it without needing to understand its internal implementation first?
That question became the focus of Phase 3, where I planned to hand the framework and its documentation to programmers with little or no Unity experience and observe where the architecture, APIs, or documentation failed to communicate their intended use.
But in the next phase, i design a new world for plants vs zombies, disregarding my framework for a moment to not bias myself for its possible limitations, to then give those designs to the programmers.