• Create Account

Posted 22 July 2013 - 04:50 PM

For the shmup I created, I implemented an Enemy Action framework.  Each enemy had a list of these actions it executed in order.  Each individual action was a simple, specific action.  Like an action to move to a specified location, an action to start firing weapons, an action to chase the player, an action to hold position for a period of time.

Actually, I have implemented something similar - for bullets with complex movements. Every complex bullet has its own vector of instructions which are executed at specified time frames. It's not perfect, since I would also love to make a bullet spawn other bullets with an instruction. Aside from that, I'm very happy with this.

That's how it looks like:

//BasicEnemy::Logic()

for(int i=0;i<360;i+=15)
{
bulletManager->AddEnemyComplexBullet(B_BULLET1, x, y, basev, i-a, 0, 0);
bulletManager->AddEnemyBulletData(45, BULLET_ANGULAR_VELOCITY, SET, 5);
bulletManager->AddEnemyBulletData(45, BULLET_ACCEL, SET, -0.7);
bulletManager->AddEnemyBulletData(55, BULLET_ANGULAR_VELOCITY, SET, 0);
bulletManager->AddEnemyBulletData(55, BULLET_ACCEL, SET, 0);
}

Anyway, that was the first thing I thought about when thinking about enemy behaviors, but unfortunately it won't work. That's simply because, no matter how complex the instruction is, it won't allow looping (...but I hope I'm wrong about that). If I want to shoot 100 bullets in a circle, writing 100 instructions for each shot makes no sense. That's exactly why I couldn't make the bullet spawn other bullets.

You could separate it out to an "EnemyAI" sort of class, that chooses the right behavior based on the AI (it can have states for example and change state depending on surroundings), which is then applied to the enemy. Then you would write these different states and corresponding behaviours, and the logic for choosing between a state.

I don't really need to use states and respond to any behavior, because I don't need the enemies to respond to anything whatsoever. I just need a clean way to set a behavior once, when creating the enemy or declare it when the program begins and then assign it to enemy during its creation.

(and as "behavior" I just mean either "at a given frame since creation, set/change velocity and direction" or "shoot a bullet/a lot of bullets in a given direction" OR "...with a random offset" OR "...in the player's direction" OR "in the player's direction with a random offset" OR ... )

Posted 22 July 2013 - 04:46 PM

For the shmup I created, I implemented an Enemy Action framework.  Each enemy had a list of these actions it executed in order.  Each individual action was a simple, specific action.  Like an action to move to a specified location, an action to start firing weapons, an action to chase the player, an action to hold position for a period of time.

Actually, I have implemented something similar - for bullets with complex movements. Every complex bullet has its own vector of instructions which are executed at specified time frames. It's not perfect, since I would also love to make a bullet spawn other bullets with an instruction. Aside from that, I'm very happy with this.

That's how it looks like:

//BasicEnemy::Logic()

for(int i=0;i<360;i+=15)
{
bulletManager->AddEnemyComplexBullet(B_BULLET1, x, y, basev, i-a, 0, 0);
bulletManager->AddEnemyBulletData(45, BULLET_ANGULAR_VELOCITY, SET, 5);
bulletManager->AddEnemyBulletData(45, BULLET_ACCEL, SET, -0.7);
bulletManager->AddEnemyBulletData(55, BULLET_ANGULAR_VELOCITY, SET, 0);
bulletManager->AddEnemyBulletData(55, BULLET_ACCEL, SET, 0);
}

Anyway, that was the first thing I thought about when thinking about enemy behaviors, but unfortunately it won't work. That's simply because, no matter how complex the instruction is, it won't allow looping (...but I hope I'm wrong about that). If I want to shoot 100 bullets in a circle, writing 100 instructions for each shot makes no sense. That's exactly why I couldn't make the bullet spawn other bullets.

You could separate it out to an "EnemyAI" sort of class, that chooses the right behavior based on the AI (it can have states for example and change state depending on surroundings), which is then applied to the enemy. Then you would write these different states and corresponding behaviours, and the logic for choosing between a state.

I don't really need to use states and respond to any behavior, because I don't need the enemies to respond to anything whatsoever. I just need a clean way to set a behavior once, when creating the enemy or declare it when the program begins and then assign it to enemy during its creation.

PARTNERS