I was bored at work, so I started on this backend for some kind of top down shooting game (swf attached). One thing I noticed is while your playing, if you let the baddies chase you around without killing them, after a short while, they begin to overlap eachother and after less then a minute, they are just one green circle (or close to it)
What would be the best way to prevent this (try out the game to see what I mean). I could keep an array with a list of every active enemy and have every one hitTest eachother (or atleast check some kind of distance variable) but is there a better way? and if not, what would be the most efficiant way to code it the way I thought of.
Thanks
Controls for the game: WASD to move, mouse to aim, click to shoot.
lol, it would be difficult, since there are many enemies
advanced collision detection would help greatly, but would make it very cpu intensive.
btw, i could kill most of the enemies by letting them go on top of the blue guy and clicking on top of them
hittesting all those circles against each other each frame is pretty much the only way to stop them from overlapping.
Robotron & Smash TV pretty much don’t even take this issue into account because if you haven’t killed them by the time they get to you… it’s over. So, your problem might not even be a problem, since we are talking about a situation that won’t exist when you allow your hero to be killed. It’ll still happen, but not to the extent that you are able to make it happen right now.
Another option that might reduce this effect, although still not perfect, would be implementing some kind of formations for sets of circles. That way you could ensure that each circle in that formation wouldn’t overlap without doing hittests. But, you’d have to devise a way to deal with overlapping formation, so dealing with the same problem on a larger scale.
Negatives would be that it wouldn’t seem like each circle had a mind of it’s own, if that is the effect you are going for. But for an army based game, that might be exceptable as attack formations actually make sense in that genre.
not exactly, tile based would make it a world of alot easier, and other then that i can’t see you writing a nice algorthim that wouldn’t slow you comp down
I had an idea that would make it alot less of a problem. If I give each enemy a random speed, then even if they were alive for along time, they wouldnt all group together. And like sslaby said, it most likely wont even be a problem once I give them the ability to attack.
In a tile based solution, you’d basically be tracking which tiles are occupied by a circle. So, you just code it so that it checks to see if the tile location is occupied before moving a circle to it’s new tile location. That way you really aren’t doing any hittesting, you are just tracking which tiles are occupied.
I was just looking for a solution based on the way the game was currently designed - not tile based.
thats exactly how you do it, if you wan’t to learn more on tile based check out tonypa or just ask me on how to tile-base but tonypa has a whole resource dedicated to your learning how to tile-base which is always there unlike me so i would check that out
you can use the class from gskinner (collisionDetection) then they will not be able to overlap, and you can add rules to their moving engine, that when they are too close a force is add to separate them…
Cheers