Outside of a tetris clone, a crappy 2D top-down shooter, and some messing around with stuff like Unity and Flixel, I realize that I have yet to complete a single, polished, bells-and-whistles game. I want to change this, and I have an idea for my next project.
The idea is that you're an amoeba. Amoebas have these eye-like cores (or something like that, I don't know biology), and you have two of 'em. You control one with WASD and the other with IJKL. There has to be a constant radius of stuff around each of the cores:
And the area of the amoeba has to stay constant. So if you move a core in one direction, you increase the amoeba's area, but that increase is compensated by a decrease somewhere else:
Aaaaaand I'd like to implement a vagination mechanic. You absorb things by engulfing them, like a boss. Maybe even an extra core, or a needle that pops you and causes all your inner stuff to start gushing out:
But here's the problem: I don't know how to make this. However, I would like some ideas on how to implement it. Should I explore physics libraries like Box2D? Or maybe something involving fluid physics? Any help would be much appreciated.
P.S. Feel free to steal this idea. I have plenty of ideas. If you do, please tell me how you made it so I can try it myself.
Answer
Off the top of my head, the clause that sticks out to me is that you want the area to be constant. That strikes me as the pain in all of this, so let's try and come up with a easy solution to that.
Take a piece of string and tie the ends together to make a circle. I may be wrong, but my intuition says that the inside of that string has a constant area, or would act an awful lot like your amoeba boundary.
So I would say: implement the string. ;) Most physics libraries can do springs (in Box2D this looks like the distance joint), and the easiest way to make a string is to connect lots of strings together. Join the last one up to the first to create a loop. Make sure the springs in the string have a high enough spring constant to not get stretched apart - you want them to be quite rigid and move in unison, not to expand out.
Next, create forces to act on the string. Trivially, your two cores/eyes/control points create forces onto the points that make up the string. Make the force fall off with an inverse square function:
float forceOnPoint(point, ball)
{
float d = distance(point, ball);
return K / (d*d);
}
And make the direction of the force directly away from the control eye/ball, like a repellent force emanating from the ball. Tweak K to control the strength of the force. Make sure that K isn't too high - you don't want it to just be pushed out massively by the force, just keep it away from the balls. Leave plenty of slack in your string.
With just those two you will probably end up with quite a uniform shape, so I'd also suggest you create some weaker forces around in the surrounding 'soup' to change the shape of the amoeba. You can make these random places, change their force regularly (you could make it a sinusoid function for nice movements) and make them work in the same way as the balls.
Vagination(fnarr): this is the difficult one. You cause it to envelop an object by checking to see if two non-adjacent points on the string have managed to get close enough, and if so you need to:
Measure the distance between the points on the string. Count the number of spring sections. Find the 'shorter' path from A to B.
Break the string and re-join it with the two points adjacent. In other words, directly join point A to point B and discard all the stuff inbetween.
Re-insert the missing number of points (plus any bonus points if you want to expand in size by eating something) into the string in the other side - i.e, the side from B to A. If you insert them equally along the length and make them shorter than the desired distance between points, you should get a nice springy-expandy effect.
I think that covers everything. By the way: idea sounds awesome.
No comments:
Post a Comment