Playable at: https://sharemygame.com/@Derek_G/no-escape-from-quarantine
I spent 3 weeks of evenings and weekends building a tower defense game using the BFS / realm rush project as a starting point. It was a tough experience but well worth it.
I played with blender in the past, but I have given up trying to be both and artist and a coder So I mostly used lots of Synty Studios assets, and my favorite weapons asset Sci-Fi Arsenal by Archanor VFX.
Blending the path finding and the tower factory code was very difficult for me. I ended up rewriting it several times, and added two way travel to the paths required for picking the right road prefabs. In the end I ended up with an abstract CubeFactory for roads, footpaths, and towers.
I am still trying to fully understand SOLID principals and other coding best practices. So I fell back to single responsibility and keeping things as contained as possible.
- Donât make anything public unless you have to. Benâs âSerializeFieldâ technique is great for this. I donât see many other instructors teaching this.
- When things do talk to each other consider the dependencies carefully. For the complex chatty parts I used a centralized GameEvent class. For the simple and useful I used other singletons.
e.g. Lots of objects are interested in enemyâs being hit so the Enemy calls BroadcastEnemyHit method, and lots of classes subscribing to the âonEnemyHitâ event:
GameEvent code for the event:
public delegate void OnEnemyHit(int hitAmount);
public event OnEnemyHit onEnemyHit;
public void BroadcastEnemyHit(int hitAmount)
{
onEnemyHit?.Invoke(hitAmount);
}
Code for the subscribing class:
void Start() { GameEvent.Instance.onEnemyHit += OnEnemyHit; } void OnEnemyHit(int hitAmount) { score += hitAmount; }
The simple and useful singletons were mostly UI oriented e.g.
UIMessage.Instance.QuickError("Blocking path"); UISound.Instance.SoundError.Play();
I also tried using the UI as a layer of separation. Such as the âtower selection panelâ used the tower class, it was not part of the tower class.