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

@ -1,11 +1,50 @@
scenes = {}
local main = {}
main.selected = 1
main.options = {
{text = "Start Game"},
{text = "Quit"}
local select_character = {
selected = 1,
options = {
{text = "Warrior"},
{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()
for i, v in ipairs(main.options) do
@ -38,8 +77,5 @@ main.keypressed = function(key)
end
end
main.update = function(dt)
end
table.insert(scenes, main)
return scenes