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
|
||||
|
||||
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
|
||||
|
||||
function love.draw()
|
||||
scenes[#scenes].draw()
|
||||
if scenes[#scenes].draw then
|
||||
scenes[#scenes].draw()
|
||||
end
|
||||
end
|
||||
|
|
70
scenes.lua
70
scenes.lua
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue