I'm working on a 2D action game. I have multiple of the same enemy type on the screen at once. We'll call it "enemy1." The player cannot pass through enemy1 and enemy1 cannot pass through other enemy1s. When the player strikes this enemy it is pushed backward. When enemy1 is pushed into a long line of enemy1s, it sort of pops into a random spot in line and another enemy1 pops in the front of the line. I want it to push the full line of enemies rather than one trying to force its way past the rest.
If that's confusing imagine a line of Goombas in Super Mario and imagine hitting a Goomba with a shell knocks it backward instead of killing it.
Mario kicks a shell into a line of 10 Goombas.
M>S>> 1 2 3 4 5 6 7 8 9 10
M >S>>1 2 3 4 5 6 7 8 9 10
Rather than pushing the entire line back, Goomba 1 pops backward in front of Goomba 7. Goomba 2 is now in goomba 1's position.
M 2 3 4 5 6 >>1 7 8 9 10
I want the whole line of Goombas to push backward when the first is hit with a shell.
M >S>1 2 3 4 5 6 7 8 9 10>
The best I've come up with is to have enemies moving with 8-Direction, the "push" happens as a custom movement on a player strike. The enemy is solid to keep them from passing through each other.
The difficulty for me is having to reference the same object when checking for overlap. For example, setting enemy1's X position to enemy1.x-10 on overlap of enemy1 causes jittery chain reactions. Making enemy1 solid is the only workaround I can come up with, but weird things happen when multiple solids collide.
I found this post but it makes no sense to me (create a family with only object objects???):
scirra.com/forum/problem-w-referencing-one-of-two-same-objects_topic72481.html
Thank you!