Pushing a Line of Enemies-Identical Object Overlap

Get help using Construct 2

Post » Wed Sep 04, 2013 6:29 pm

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???):
http://www.scirra.com/forum/problem-w-referencing-one-of-two-same-objects_topic72481.html

Thank you!
B
3
Posts: 3
Reputation: 396

Post » Thu Sep 05, 2013 5:27 am

If they're all identical enemies why does it matter which order they are in? How can the user tell ?
B
46
S
16
G
74
Posts: 2,089
Reputation: 44,187

Post » Thu Sep 05, 2013 11:41 am

A fake, invisible grid... Grid is registered and updated on an array. Each enemy is registered in one of the grid squares, always updated. When enemy is pushed, do the magic math on the array to "move" their places in the array, and update the positions accordingly.

Just on the top of my head. There may visually be problems, like enemies pushing eachther even though they are not touching eachother... Or different sizes of enemies may cause problems... But maybe this will give ideas?

Sorry if it was too vauge. Not good with changing ideas into language.
B
18
S
4
G
1
Posts: 332
Reputation: 3,149

Post » Thu Sep 05, 2013 1:57 pm

The user can tell because the enemies have 3 hit points. It also looks sloppy visually when the enemies are making sudden, jerky movements to make room in the line. If it happened smoothly I wouldn't have anything to complain about.
B
3
Posts: 3
Reputation: 396

Post » Thu Sep 05, 2013 2:12 pm

I haven't tried it yet, but I imagine an array will have similar problems assigning values to specific instances. You may be going somewheres with the grid. They're ghastly enemies so grid-based movement wouldn't be uncharacteristic, but I'd hate to invest a lot of time in such a small mechanic.
B
3
Posts: 3
Reputation: 396


Return to How do I....?

Who is online

Users browsing this forum: evillair, Exabot [Bot], LunchboxGames, NumberOne, rekjl and 15 guests