FINALLY!

June 3, 2011

See what happens when I focus and actually work? I finally get orbits to work about the screen center (or anywhere else I might like for that matter). It was a case of simple vector math. Even though I swear I tried this before, I’m guessing I just didn’t get the vector subtraction quite right. The proper solution turned out to be as follows:

static void
planetGravityVelocityFunc(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt)
{
// Gravitational acceleration is proportional to the inverse square of
// distance, and directed toward the origin. The central planet is assumed
// to be massive enough that it affects the satellites but not vice versa.
// Sun position
cpVect disp = cpv(160, 240);
// Point mass position
cpVect p = body->p;
// Point mass relative to Sun
p = cpvsub(p, disp);
cpFloat sqdist = cpvlengthsq(p);
cpVect g = cpvmult(p, -gravityStrength / (sqdist * cpfsqrt(sqdist)));
cpBodyUpdateVelocity(body, g, damping, dt);

}

So now that I finally have the mechanics working, I want to test collisions and how, exactly, I can manipulate the mechanics to create collisions. The collision detection itself however should be simple as it’s built into Chipmunk.

Some of the “weapons” I originally imagined would require the velocity function of affected planets to either be reset or added to in complex ways so I may have to cut those. I might reduce the scope down to simply orbit changing affects such as slowing/speeding a planet and then using the result planetary shrapnel (a destroyed planet could be removed from the scene and replaced with a small number of smaller bodies set with velocities related to origin body). In this way, I might just make the game even more “Osmosis” like but with the ability to apply forces to any body in the system and use the resulting explosions to cause chain reactions. Perhaps a few one-off weapons, such as the “Rubble Maker” which simply detonates planets instantly and possibly “Anti-Gravity Beam” that breaks a planet from the star’s gravitational pull and sends it off in straight line to collide with a neighbor when timed correctly. Each planet, depending on size, would have a different amount of health determining how many micro-meteorite hits it could take. The problem is if I do want more interesting planetary orbits for later levels, I’ll have to craft them carefully to ensure no self-destruciton.

The next big hurdle is figuring out how to set up my game to build multiple levels/puzzles. While I still need to research example projects, I’m assuming a new scene can be built based on a specific input when an old scene/level is completed. E.g. I’ll have a level builder class which will loop through an array of planetoids and pop them into a scene with corresponding sprites, velocities, masses, etc. along with the target number of moves for the solution.

The last hurdle for game play itself will be navigation. Scaling the scene up and down to allow players to see the greater picture is obviously demanded since the screen is so oblong. However, I think I’ll make it so while the scale between planets will change, the planets themselves will not, to a point, so that they can be seen easily. If Chipmunk supports a pinch gesture then that’s definitely the way to go, otherwise a slider will have to do. And while I originally wanted to allow some time step control, this may prove difficult. I could easily lower the amount of computations per frame but increasing would negatively effect performance. Will have to bench test that later if possible.

Furthermore, it will be important to somehow represent the path of the planets. Computing and drawing an appropriate shape would be impossibly complex since it would require either precomputing future time steps or estimating an ellipse based on the current position relative to the center and velocity vector. If I can find an easy way to do the latter, that would be optimal. However a easier short term solution is simply to draw a point at a regular interval, leaving a trail behind the planetoid that will fade over time.

Finally I’ll need to implement a basic menu with a level selection and high score board. While I’ve procrastinated terribly up until now, I still have a month to work. I’d like to be finished with game play by the 15th at the latest so I’ll have another half month to test and tweak. I’ve nothing else going at the moment and plan on finishing my independent study once I’m reunited with my PC in NYC so I’m confident I’m capable of this. I’m sure some things, like the art and sound, may not be as polished as I want them to be come end time but I’m sure I’ll have, at the very least, a playable game. Wish me luck!

 

PS: The guy that told me at Alphas that he could get me an iPhone developer login credential was on the TagTanium team of PennApps (pretty sure though it might have been TagAlong). If anyone knows anyone from that team, any contact info would be greatly appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *