Last time I wrote about how I implemented the strategy pattern into my state machine to allow for customized behavior that was easy to change and maintain.
(You can ready more about that by clicking here if you want).
Well, since then I have added more and more desired behavior into my Game Design Document, and I realized that the strategy pattern wouldn't cut it anymore.
So I broke the code into small chunks and created a behavior tree.
A behavior tree will allow me to have very complex behavior that is still fairly easy to maintain (although it is quite intensive to set up).
(This article describes behavior trees very well).
I still have my state machine, but it uses different behavior trees as per my wish (if that's a sentence I can use).
And since each node can take parameters, I can actually have a friendly NPC and an enemy NPC use the same behavior tree, but they act differently because of the parameters set.
The player would never know they use the same code base.
Furthermore, different variations of the enemy can use different behavior trees that will allow for more variation in the behaviors, making the game feel more alive.
I'm not an expert programmer. By far.
But I love modular code that is easy to maintain and expand upon, following the SOLID principle whenever possible.
And I'm having SO MUCH fun with this - and after all, that's why we want to make games in the first place, isn't it?
I'd love to hear about your experience with behavior trees, state machines and the strategy pattern - and if you have any preferences.
Oh, and I'm really looking forward to the day I can show some functioning demo of the game! ?
Nice work! Behavior trees are hard as hell to implement but definitely a lot more reliable than state machine when it comes to AI