I just put a new version of Gravity (beta) on Kongregate.
I added support for multiple masses and also obstacles. Also, I fixed a
bug with the physics system. The physics are much more
“realistic” now. Force actually decreases with distance now!
Lessons Learned
When I added support for multiple masses, I noticed that the physics were
acting “funny”. It seemed like the little boxes were being more
attracted by masses on the opposite side of the map than the to ones they
were near.
It turns out that AS3 does not have an exponentiation operator. My late
night coding resulted in the following mistake.
// I don't think I ordered an XOR.
var dist:Number = Math.sqrt(
(massPt.x - object.x) ^ 2 +
(massPt.y - object.y) ^ 2);
// this is what I should have said.
var dist:Number = Math.sqrt(
Math.pow(massPt.x - object.x, 2) +
Math.pow(massPt.y - object.y, 2));
Also, it turns out that Flixel makes the
nice memory-saving optimization of reusing graphics of the same size when you
do makeGraphic()
. I had to tell it to make a unique version so
that I could change the background color on my buttons for add / remove.