main menu
This commit is contained in:
parent
538fea556d
commit
2b7ef7c276
2 changed files with 54 additions and 39 deletions
23
main.lua
23
main.lua
|
@ -3,9 +3,28 @@ function love.load()
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
scenes[#scenes].update(dt)
|
if #scenes == 0 then
|
||||||
|
love.event.quit()
|
||||||
|
end
|
||||||
|
if scenes[#scenes].update then
|
||||||
|
scene_ended = scenes[#scenes].update(key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.keypressed(key)
|
||||||
|
if scenes[#scenes].keypressed then
|
||||||
|
scenes[#scenes].keypressed(key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.keyreleased(key)
|
||||||
|
if scenes[#scenes].keyreleased then
|
||||||
|
scenes[#scenes].keyreleased(key)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
scenes[#scenes].draw()
|
if scenes[#scenes].draw then
|
||||||
|
scenes[#scenes].draw()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
70
scenes.lua
70
scenes.lua
|
@ -1,49 +1,45 @@
|
||||||
scenes = {}
|
scenes = {}
|
||||||
|
|
||||||
time_since_start = 0
|
local main = {}
|
||||||
loops = 0
|
main.selected = 1
|
||||||
main_scene = {}
|
main.options = {
|
||||||
looping_scene = {}
|
{text = "Start Game"},
|
||||||
looping_scene.draw = function()
|
{text = "Quit"}
|
||||||
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
|
|
||||||
|
|
||||||
main_scene.update = function(dt)
|
main.draw = function()
|
||||||
time_since_start = time_since_start + dt
|
for i, v in ipairs(main.options) do
|
||||||
if time_since_start > 2 then
|
if i == main.selected then
|
||||||
main_scene.draw = function()
|
love.graphics.print({{255, 255, 0}, v.text}, 200, 100 + (15 * i))
|
||||||
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)
|
|
||||||
else
|
else
|
||||||
main_scene.draw = function()
|
love.graphics.print(v.text, 200, 100 + (15 * i))
|
||||||
love.graphics.print("Damn, enough with the looping..", 100, 100)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
main_scene.draw = function()
|
main.keypressed = function(key)
|
||||||
love.graphics.print("Main Scene", 400, 300)
|
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
|
end
|
||||||
|
|
||||||
table.insert(scenes, main_scene)
|
main.update = function(dt)
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(scenes, main)
|
||||||
return scenes
|
return scenes
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue