main menu

This commit is contained in:
Simo-Pekka Kerkelä 2019-02-08 19:11:41 +02:00
parent 538fea556d
commit 2b7ef7c276
2 changed files with 54 additions and 39 deletions

View file

@ -1,49 +1,45 @@
scenes = {}
time_since_start = 0
loops = 0
main_scene = {}
looping_scene = {}
looping_scene.draw = function()
love.graphics.print("Loopdy loo", 110, 120)
end
looping_scene.update = function(dt)
time_since_start = time_since_start + dt
if time_since_start > 2 then
looping_scene.draw = function()
love.graphics.print("Looping continues", 200, 150)
end
end
if time_since_start > 8 then
time_since_start = 0
table.remove(scenes)
loops = loops + 1
end
end
local main = {}
main.selected = 1
main.options = {
{text = "Start Game"},
{text = "Quit"}
}
main_scene.update = function(dt)
time_since_start = time_since_start + dt
if time_since_start > 2 then
main_scene.draw = function()
love.graphics.print("Main Scene extended", 400, 300)
end
end
if time_since_start > 6 then
time_since_start = 0
if loops < 4 then
table.insert(scenes, looping_scene)
main.draw = function()
for i, v in ipairs(main.options) do
if i == main.selected then
love.graphics.print({{255, 255, 0}, v.text}, 200, 100 + (15 * i))
else
main_scene.draw = function()
love.graphics.print("Damn, enough with the looping..", 100, 100)
end
love.graphics.print(v.text, 200, 100 + (15 * i))
end
end
end
main_scene.draw = function()
love.graphics.print("Main Scene", 400, 300)
main.keypressed = function(key)
if key == "up" then
main.selected = main.selected + 1
if main.selected > #main.options then
main.selected = 1
end
elseif key == "down" then
main.selected = main.selected - 1
if main.selected < 1 then
main.selected = #main.options
end
elseif key == "return" then
local next = main.options[main.selected].next_scene
if next then
table.insert(scenes, next)
else
table.remove(scenes)
end
end
end
table.insert(scenes, main_scene)
main.update = function(dt)
end
table.insert(scenes, main)
return scenes