Solar Fortress Chronicles 2: Hours 5 – 9

Solar Fortress Chronicles 2: Hours 5 – 9

This is a short update on my latest mini retro remake, Solar
Fortress (pronounced Star Castle).

I wasted a lot of time today working on collision detection for
Solar Fortress today. I think I finally have a decent path toward
my final set of code, but I spent an inordinate amount of time mostly
frustrated.

My goal was to use BitmapData collision detection between
the player ship and each rotating line segment in the fortress walls.
For some reason when my objects were rotated inside Sprites, the
collision detection would not work. It seemed that the rotation was not taken into account in the collision map. Hmm,  I think I remember this from the
docs I read a long time ago, but for the first three hours today I
thought I could do detection on rotated Bitmaps (and the associated
BitmapData) inside my sprites. This seemed to work on and off with
strange results most of the time.

It worked perfectly for 2
identically sized objects and I was actually able to cobble together
a few sets of different sized objects and associated offsets that
worked OK, but it was not reliable enough to go forward with (yet, I
may go back to this for the missile to wall hits).

Finally, I decide to add 4 hit points to the ship and tested this
against a rotated (but enlarged) yellow line segment. This worked
pretty well, so I started to code up a loop to test all 4 ship hit
points against all circle segments when I had a revelation…In Star
Castle, the player ship never actually goes inside of the ‘Castle’,
so why waste cycles checking 4 hit points on the ship against every
line segment? Why not just do a circle v. circle between the ship and
the fortress. So, that’s what I did. It took a couple of tries
because I was late and I forgot that RADIUS is not DIAMETER (duhh, maybe I should have spend more time in Math listening instead of drawing space ships) and
needed to make a few minor adjustments before it started to work
pretty well.

One thing I have not done (other than some rudimentary code) is
figure out the correct collision reaction between the ship and the
fortress. This and the ability to shoot the walls is next on my list.

Here is an interactive (arrow keys) swf of the current hour 9 build.
I left in the test objects and the player ship 4 hit spots as they
might prove useful down the line.

0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.