char select

This commit is contained in:
Simo-Pekka Kerkelä 2019-02-09 18:18:50 +02:00
parent 240cfb51f7
commit 6ff7fe3d1b
2 changed files with 46 additions and 9 deletions

View file

@ -5,6 +5,7 @@ end
function love.update(dt) function love.update(dt)
if #scenes == 0 then if #scenes == 0 then
love.event.quit() love.event.quit()
return
end end
if scenes[#scenes].update then if scenes[#scenes].update then
scene_ended = scenes[#scenes].update(key) scene_ended = scenes[#scenes].update(key)
@ -24,7 +25,7 @@ function love.keyreleased(key)
end end
function love.draw() function love.draw()
if scenes[#scenes].draw then if #scenes > 0 and scenes[#scenes].draw then
scenes[#scenes].draw() scenes[#scenes].draw()
end end
end end

View file

@ -1,11 +1,50 @@
scenes = {} scenes = {}
local main = {} local select_character = {
main.selected = 1 selected = 1,
main.options = { options = {
{text = "Start Game"}, {text = "Warrior"},
{text = "Quit"} {text = "Mage"},
{text = "Rogue"}
}
} }
local main = {
selected = 1,
options = {
{text = "Start Game", next_scene = select_character},
{text = "Quit"}
}
}
select_character.draw = function()
for i, v in ipairs(select_character.options) do
if i == select_character.selected then
love.graphics.print({{255, 255, 0}, v.text}, 200, 100 + (15 * i))
else
love.graphics.print(v.text, 200, 100 + (15 * i))
end
end
end
select_character.keypressed = function(key)
if key == "up" then
select_character.selected = select_character.selected + 1
if select_character.selected > #select_character.options then
select_character.selected = 1
end
elseif key == "down" then
select_character.selected = select_character.selected - 1
if select_character.selected < 1 then
select_character.selected = #select_character.options
end
elseif key == "return" then
local next = select_character.options[select_character.selected].next_scene
if next then
table.insert(scenes, next)
else
table.remove(scenes)
end
end
end
main.draw = function() main.draw = function()
for i, v in ipairs(main.options) do for i, v in ipairs(main.options) do
@ -38,8 +77,5 @@ main.keypressed = function(key)
end end
end end
main.update = function(dt)
end
table.insert(scenes, main) table.insert(scenes, main)
return scenes return scenes