Gaming Your Way

May contain nuts.

Refactoring... Joy

The other day I wrote about the gyroscope / fan / blades of death thing. I wasn't too happy about it, I wanted it so if you pushed an object in there, say a crate, the blades would really hit it hard and send it flying.

After an hour or so of should I / shouldn't I, I opted to update the version of Nape I was using for all the physics in the game. That's come as quite a shock, as I'm using a really old version and even though I wrote a wrapper class to try and shield me from pain like this, in real life unless everything goes through the wrapper ( Which is slow ) it means a lot of re-writing.

The current version [ of Nape ] is really excellent, feels quicker and does a whole lot more much easier than before. For example the laser sight on your weapon works by ray casting. We fire a ray out until it hits something, then use some trig to calculate what the new length ( Technically the height ) of the line should be. Using the new version of Nape my 20+ lines of code is now about 3. Sexy.

New Nape also rotates objects around 0,0 rather than having to centre align everything, which means I no longer need to put objects into Sprites to centre align them, I can just add a bitmap to the stage. This means nice performance improvements.
Taking a crate as an example, I'd have a sprite with the actual crate image in it, the fire animation and then another sprite for it's shadow ( So the shadow would rotate correctly ). Now we just add the crate and shadow bitmaps to the screen directly. This meant that I now have to have the fire animation in it's own movieclip, which means updating it's x,y and rotation. A small overhead really, as the fire isn't always active.
The added bonus from this is that I can put the fire animation in a different layer, which is what I've done. It's now in a layer above the shadows, so if you shoot something until it catches fire you can then push that object into a dark corner and it'll light it up. It doesn't sound much I know, but it's right, and it opens up some game play possibilities ( Such as having a dark area where you have to set things a light to find your way through it ).

Ok, this has turned into a dry techy ramble. Long story short, the change has affected around 50 classes, which means going through each one fixing them then optimising them. Painfully boring, but it'll pay off.

Squize. 

Comments (1) -

  • Zedacus

    1/11/2013 3:09:37 PM |

    Like :P

Comments are closed