Code Optimization: Enemy AI

Over the process of two days after two months of hiatus, I have finished some major enemy AI cleanup as part of the gamekit's optimization and cleanup phase before polishing and release.

The family category/group that enemies were sorted into now actually has an actual function, as enemies now inherit various variables from the parent-family instead of having their own variables; which makes for easier enemy management. This includes setting HP dynamically per enemy on the fly during runtime, among other values.

Enemy AI now uses one set of general events to cover damage and knockback for almost all enemies and enemies also now drop items properly. This was done in preparation for enemies to drop unique items, with a spoils-bag system akin to the loot system in Final Fantasy XII. A text-based variable is also also now used to tag each kind of enemy per instance so the system can decide if to trigger unique behavior, such as if the player should be electrocuted upon attacking a Buzzblob-like enemy compared if to attacking an ordinary wandering AI.

I also have a new patrolling AI that uses actual A* pathfinding (look it up if you like design or programming, A* pathfinding is interesting stuff) behavior via the built-in behavior and it is a lot less events and doesn't bump into walls as easily and are smarter AI as a result of the A* pathfinding. 

They automatically avoid solid obstacles and think/update on the fly on how to reach the randomly assigned X/Y point on a map. However, it is completely unimplemented in the actual gamekit and is in an other test project so it will be implemented soon to replace the old state-machine patrolling AI. It may likely replace said state-system altogether, as it has produced more convincing AI.

Leave a comment

Log in with your itch.io account to leave a comment.