[1Ed] Prototype 8: Omega Mage
Omega Mage is a game prototype that mixes the dungeon exploration of The Legend of Zelda or Rogue with element-based spell-casting and an interface that works for either mouse or touchscreen (Android, iOS, and so on).
This is the last prototype of the book and therefore the most complex. At the end, you’ll have a nice skeleton for an action-adventure game.
Errata
- p.729 – “Change the name of Main Camera to __MainCamer” should be “__MainCamera”.
- p.733 – The method public void BuildRoom(PT_XMLHashtable room) begins on this page, but this is incompatible with the call at the end of Awake() to BuildRoom(roomNumber) .To make the code on this page work properly, you will also need to add the overload of public void BuildRoom(string rNumStr) that appears on p.765 and below:
// Build a room based on room number. This is an alternative version of // BuildRoom that grabs roomXML based on num. public void BuildRoom(string rNumStr) { PT_XMLHashtable roomHT = null; for (int i=0; i<roomsXML.Count; i++) { PT_XMLHashtable ht = roomsXML[i]; if (ht.att("num") == rNumStr) { roomHT = ht; break; } } if (roomHT == null) { Utils.tr("ERROR","LayoutTiles.BuildRoom()", "Room not found: "+rNumStr); return; } BuildRoom(roomHT); }
- PT_Mover.cs : PT_Loc Class : Bezier method : Line 133 – In the old version of the Starter Package, this code made use of the System.Array.Copy method to copy from one array to another. I had a typo on line 133. The error message for this typo read: Assets/__Scripts/ProtoTools/PT_Mover.cs(133,10): error CS1001: Unexpected symbol `.’, expecting identifier. To fix this error:
// Replace this line 133 PT_Loc[].Copy(locs, 1, locsR, 0, len); // With this corrected line 133 System.Array.Copy(locs, 1, locsR, 0, len);
This should eliminate the error message. However, I’ve since realized that this old method of computing Bezier curves was ridiculously inefficient from a memory standpoint, so I highly recommend replacing the entire PT_Loc:Bezier method (lines 119-138) with this improved version.
// This is the new, fast and efficient version of PT_Loc.Bezier() public static PT_Loc Bezier(float u, PT_Loc[] locs, int iL=0, int iR=-1) { // iL and iR are indices into the array locs. // In this version, instead of creating lots of new arrays and wasting // memory and time we pass the same array into each recursion and // adjust these indices. if (iR == -1) { iR = locs.Length-1; } // This is the terminal case when both iL and iR point to the same element if (iL == iR) { return locs[iL]; } // Since they still point to two different elements of locs, // recur to divide the problem PT_Loc res = PT_Loc.Lerp( Bezier(u, locs, iL, iR-1), Bezier(u, locs, iL+1, iR), u ); return res; }
Unity 5 Update
Unity made a few changes to their C# code for Unity 5. The PDF below contains full code listings for the EnemyBug.cs, EnemySpiker.cs, Mage.cs, Prototools/PT_MonoBehaviour.cs, Tile.cs, and Prototools/Utils.cs code files, which all require small changes due to Unity 5. These few changes are all highlighted in yellow in the code listings.
Starter Package
(updated to Unity 5.6, with new PT_Loc.Bezier() method)