I made a menu engine cuz it was fun. Here's how to use it...
-Files-
Other than the .mzx, there are five files (LoadOnceMenu.txt, Menu.txt, Items.mzm, Menu.mzm, and MenuMask.mzm). As you'd expect LoadOnceMenu loads all of the variables, the 3 sprites I use to draw the Menu (numbers 249-251), while Menu is the engine itself. Items.mzm contains the graphical data for the cursor and the items and the cursor. Menu.mzm should be obvious, while MenuMask.mzm was intended to be used to prevent the menu sprite from grabbing the color from the layer below it.
- Variables -
My personal preference with variables is that I tend to avoid using local variables (since locals can't be debugged with f11, and aren't descriptive). To avoid naming conflicts, I group similar variables so that they sort of represent the data contained by an "object".
menu - This group of variables manages the Sprite (#250) that will display Menu.mzm. The sprite itself is static. To move the menu, send the Menu robot to #MoveMenu to reposition the menu on the screen, or #HideMenu to hide it completely. These variables also manages the Sprite (#249) that displays MenuMask.mzm beneath the menu.
inv - The group of variables that manage the items that can be wielded (current inventory), and how they are formatted in the menu. invX/Y manages the position that the inventory appears, which is relative to the upper right corner of the Menu. InvW/H manages the number of columns/rows of items that you can have.
$inv - a 1-dimensional array that contains the items you currently have stowed away. The length of this array is InvW*InvH, and each element defaults to "None". To add an item to the inventory, set $addItem to the item name you defined with $items, and send the robot "Menu" to #additem.
item - the group of variables that determine the size of each item icon. I've set that to 3x3, since the cursor I drew is 3x3, and is also the reason why Items.mzm has the cursor graphic in it.
$item(s) - the group of variables that determine how Items.mzm should be formatted, and are used to determine which icon to use for which item. The $items variable is used to give the item icons a "name". See LoadOnceMenu.txt to get an idea of what i mean.
$ERROR - used for debugging purposes. Helps to find my screw-ups.
- Engine Functions -
: "OpenMenu" - Locks the player and opens the menu. Directionals move the cursor, Z equips an item to $weapA, X equips an item to $weapB, enter leaves the menu. Right now, you have to use another robot to open up the menu, but not to close it... I probably should fix that.
: "#MoveMenu" - Moves the menu to MenuX, MenuY
: "#HideMenu" - Removes the menu from the screen.
: "#AddItem" - Adds the item stored in $additem to the next open spot in the inventory, or sets $ERROR if it can't
- Future Improvements -
If you make up a menu layout for me, I could also make it possible for each item to show off a unique description, like in the Gameboy games.
There are also a few small things I can fix, like making it so that you can actually see what item you've equipped.
This post has been edited by Old-Sckool: 14 August 2010 - 05:08 AM