From 6ff7fe3d1b3166437780a2e9d2fc7c93ea4a1a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simo-Pekka=20Kerkel=C3=A4?= Date: Sat, 9 Feb 2019 18:18:50 +0200 Subject: [PATCH] char select --- main.lua | 3 ++- scenes.lua | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/main.lua b/main.lua index b07bf59..e6794c1 100644 --- a/main.lua +++ b/main.lua @@ -5,6 +5,7 @@ end function love.update(dt) if #scenes == 0 then love.event.quit() + return end if scenes[#scenes].update then scene_ended = scenes[#scenes].update(key) @@ -24,7 +25,7 @@ function love.keyreleased(key) end function love.draw() - if scenes[#scenes].draw then + if #scenes > 0 and scenes[#scenes].draw then scenes[#scenes].draw() end end diff --git a/scenes.lua b/scenes.lua index 3bc6b88..1a6f292 100644 --- a/scenes.lua +++ b/scenes.lua @@ -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