Little Menu Engine Demo

Published 2023-06-12



(Note: I already pushed it a few days ago, but I deleted it by accident^^)

Hello,
Just programmed a simple "Menu Manager" and I thought, it can be useful for others. :)

It presents a way to write your own Menu, moving a cursor with Arrow-Keys (Up/Down), select an Entry (X) and call a Function.

The Sourcecode is well documented.

EXAMPLE

Again, the Sourcecode is well documented :)

HOW TO USE IT

6. Make sure these functions at least exist, otherwise the Menu wouldn't shown properly:

function start_game()
[...more code...]
end
[...same for "show_options" and "show_credits"...]

SOME MORE OPTIONS
You can change some Variables before calling "menu.start()":

Change the Symbol used as Cursor.

The same for the used Cursor-Color.

Color to remove the Cursor-Symbol after moving it.

A function that will be called, if the Player press Button "4". If this is set to "nil", nothing will happened.

Use it after calling "menu.start()". You can set the preselected Entry with this Variable. 0 means the first Entry, 1 the Second Entry and so on...

All this code is free to take, use, change, adapt, or whatever.

As said, I thought it can be useful for others^^.

Make sure you place

menu={}

on your Sourcecode. Not in a function, not even in _init(), it must be placed on the "highest level".

Copy every function, that starts with "menu.", from that Cartridge to your Sourcecode. Thats

function menu.start()
function menu.update()
function menu.draw()

Make sure to call the "update"- and "draw"-function in _update() and _draw(). Don't worry, these Functions won't do anything, they only react after calling another Function ("menu.start()"):

function _update()
menu.update()
end

function _draw()
menu.draw()
end

Set your Screen-Position using "cursor" (it must be done at least once).

cursor(0,0)