21 July 2013
Comments: 0

Transmutation: rewriting isn’t so hard

The Transmuation rewrite is turning out to be easier than I expected, simpler than it was the first time I wrote it in Shiva, a bit over a year ago.

That’s quite an achievement because at the time I’d been using Shiva for about 18 months, and I’ve only been working with Unity for four months.

The main difference, which I’ve mentioned before, is that Unity has a full-featured programming language, and lots of useful 3rd party plugins.

For example, Transmutation features a 2D array of “virus” objects that need to be monitored by the app. When it was written, Shiva only had a very limited “table” which was roughly equivalent to a one dimensional list of either strings, numbers, or built in objects. I ended up having to create a whole series of lists for things like “x coordinate”, “y coordinate”, “state”, “animation”, and so on. Writing code to deal with all of these separate lists was not difficult, but it was time consuming and it produced some ugly code.

When rewriting Transmutation in Unity, I started off by creating a “virus”, which is just a Game Object with the virus graphic attached. I then appended a “virus” class which contained all of the needed properties that I’d previously stored in lists in Shiva. Finally, I created a method to trigger the animation when a virus “transmutes”.

Most of the work was performed by a few plugins:

  • Animation by iTween. All that’s required is a simple scale function that shrinks the object until it’s invisible, swaps the graphic, then scales it back to it’s original size.
  • Instancing of objects by Pool Manager. When no longer needed, Pool Manager parks the object somewhere out of the way and makes it invisible so that it can be re-used later.
  • Positioning guided by the Grid Framework plugin. If the grid is scaled to fit the screen resolution, then RectGrid.GridToWorld offers an easy way to convert a grid cell position into a 3D world coordinate.

In the original version of Transmuation, I had to write the tweening code using lists and timers. I had to write the code to instance objects and hide them when not used. I also had to write the code to calculate on-screen coordinates for positioning everything. All of this in a version of Lua that’s missing some of the more useful features of modern programming languages.

The Unity version of Transmutation is currently playable and the menus work, though the graphics have yet to be updated.

TransmutationRewritePt1    shot3
On the left is the new WIP Unity version of Transmutation vs the old Shiva version on the right

Galaxy Explorer update

I’ve now got approval from Dropbox to release the app. A little more testing, and it’ll be ready to go.