Download Media Create Donate Forums

2012/01/25

EnemyBehavior

I've been thinking about the EnemyBehavior interface and it's tricky. I'm trying to plan for several future enemy types, but not having those spec'd out makes it hard to design the interface. Ideally, I'd code up a few very different kinds of enemies and then figure out their common interface.

Most likely an EnemyBehavior base class will have these functions:

  • move() // enemy changes position and facing direction
  • act() // enemy uses a power if appropriate

Enemy position, animation frame, and power usage would be public. Most other behavioral variables could be private, allowing completely different "black-box" implementations for creatures. E.g. some creatures might follow specific patterns (think Mega Man boss) instead of taking random %-based actions like the current creatures do. Even the enemy's "state" could be done inside the behavior object, as it should be irrelevant to the rest of the game (as long as state and animations are sufficiently decoupled).

When finalized, I'd like there to be several base enemy behavior types. Imagine a Melee type, a Ranged type, a Flying/Swooping type, and several boss types. There will be many configuration options to build a variety of creatures within each type. To add a completely new type (e.g. to design a unique boss unlike any existing creatures) would require adding a new behavior implementation in C++. Though this should be extremely rare, only for ambitious projects that are already content with hacking around in the source to do new things. Great new fan-made behavior types could be contributed back to the main Flare code base.

This is the main feature we want for v0.16 (now that A* and enemy spawning are complete). If you have ideas for enemy behavior types, or interesting pointers for implementation, drop me a note!