Lua Game modes


Example

If you want a title screen or an endgame screen, consider setting up a mode switching mechanism:

function _init()
  mode = 1
end

function _update()
  if (mode == 1) then
    if (btnp(5)) mode = 2
  elseif (mode == 2) then
    if (btnp(5)) mode = 3
  end
end

function _draw()
  cls()
  if (mode == 1) then
    title()
  elseif (mode == 2) then
    print("press 'x' to win")
  else
    end_screen()
  end 
end

function title()
  print("press 'x' to start game")
end

function end_screen()
  print("a winner is you")
end