This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
-- desc: Life of a programmer in the Vector
|
-- desc: Life of a programmer in the Vector
|
||||||
-- site: http://teletype.hu
|
-- site: http://teletype.hu
|
||||||
-- license: MIT License
|
-- license: MIT License
|
||||||
-- version: 0.5
|
-- version: 0.6
|
||||||
-- script: lua
|
-- script: lua
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
@@ -204,31 +204,49 @@ function Input.back() return btnp(5) end
|
|||||||
-- UI Module
|
-- UI Module
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function UI.draw_top_bar(title)
|
function UI.draw_top_bar(title)
|
||||||
rect(0, 0, Config.screen.width, 10, Config.colors.black)
|
rect(0, 0, Config.screen.width, 10, Config.colors.dark_grey)
|
||||||
print(title, 3, 2, Config.colors.light_grey)
|
print(title, 3, 2, Config.colors.green)
|
||||||
end
|
end
|
||||||
|
|
||||||
function UI.draw_dialog()
|
function UI.draw_dialog()
|
||||||
rect(40, 40, 160, 80, Config.colors.black)
|
rect(40, 40, 160, 80, Config.colors.black)
|
||||||
rectb(40, 40, 160, 80, Config.colors.dark_grey)
|
rectb(40, 40, 160, 80, Config.colors.green)
|
||||||
print(State.dialog_text, 120 - #State.dialog_text * 2, 45, Config.colors.light_grey)
|
print(State.dialog_text, 120 - #State.dialog_text * 2, 45, Config.colors.light_grey)
|
||||||
|
UI.draw_menu(State.dialog_menu_items, State.selected_dialog_menu_item, 50, 60)
|
||||||
|
end
|
||||||
|
|
||||||
for i, item in ipairs(State.dialog_menu_items) do
|
function UI.draw_menu(items, selected_item, x, y)
|
||||||
local color = Config.colors.dark_grey
|
for i, item in ipairs(items) do
|
||||||
if i == State.selected_dialog_menu_item then
|
local current_y = y + (i-1)*10
|
||||||
color = Config.colors.green
|
if i == selected_item then
|
||||||
|
print(">", x - 8, current_y, Config.colors.green)
|
||||||
end
|
end
|
||||||
print(item.label, 50, 60 + (i-1)*10, color)
|
print(item.label, x, current_y, Config.colors.green)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function UI.update_menu(items, selected_item)
|
||||||
|
if Input.up() then
|
||||||
|
selected_item = selected_item - 1
|
||||||
|
if selected_item < 1 then
|
||||||
|
selected_item = #items
|
||||||
|
end
|
||||||
|
elseif Input.down() then
|
||||||
|
selected_item = selected_item + 1
|
||||||
|
if selected_item > #items then
|
||||||
|
selected_item = 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return selected_item
|
||||||
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Splash Module
|
-- Splash Module
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function Splash.draw()
|
function Splash.draw()
|
||||||
cls(Config.colors.black)
|
cls(Config.colors.dark_grey)
|
||||||
print("Mr. Anderson's", 78, 60, Config.colors.light_grey)
|
print("Mr. Anderson's", 78, 60, Config.colors.green)
|
||||||
print("Addventure", 90, 70, Config.colors.light_grey)
|
print("Addventure", 90, 70, Config.colors.green)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Splash.update()
|
function Splash.update()
|
||||||
@@ -242,7 +260,7 @@ end
|
|||||||
-- Intro Module
|
-- Intro Module
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function Intro.draw()
|
function Intro.draw()
|
||||||
cls(Config.colors.black)
|
cls(Config.colors.dark_grey)
|
||||||
local x = (Config.screen.width - 132) / 2 -- Centered text
|
local x = (Config.screen.width - 132) / 2 -- Centered text
|
||||||
print(State.intro.text, x, State.intro.y, Config.colors.green)
|
print(State.intro.text, x, State.intro.y, Config.colors.green)
|
||||||
end
|
end
|
||||||
@@ -271,29 +289,13 @@ end
|
|||||||
-- Menu Module
|
-- Menu Module
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function Menu.draw()
|
function Menu.draw()
|
||||||
cls(Config.colors.light_grey)
|
cls(Config.colors.dark_grey)
|
||||||
UI.draw_top_bar("Main Menu")
|
UI.draw_top_bar("Main Menu")
|
||||||
for i, item in ipairs(State.menu_items) do
|
UI.draw_menu(State.menu_items, State.selected_menu_item, 108, 70)
|
||||||
local color = Config.colors.dark_grey
|
|
||||||
if i == State.selected_menu_item then
|
|
||||||
color = Config.colors.green
|
|
||||||
end
|
|
||||||
print(item.label, 108, 70 + (i-1)*10, color)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Menu.update()
|
function Menu.update()
|
||||||
if Input.up() then
|
State.selected_menu_item = UI.update_menu(State.menu_items, State.selected_menu_item)
|
||||||
State.selected_menu_item = State.selected_menu_item - 1
|
|
||||||
if State.selected_menu_item < 1 then
|
|
||||||
State.selected_menu_item = #State.menu_items
|
|
||||||
end
|
|
||||||
elseif Input.down() then
|
|
||||||
State.selected_menu_item = State.selected_menu_item + 1
|
|
||||||
if State.selected_menu_item > #State.menu_items then
|
|
||||||
State.selected_menu_item = 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if Input.action() then
|
if Input.action() then
|
||||||
local selected_item = State.menu_items[State.selected_menu_item]
|
local selected_item = State.menu_items[State.selected_menu_item]
|
||||||
@@ -309,12 +311,12 @@ end
|
|||||||
function Game.draw()
|
function Game.draw()
|
||||||
local currentScreenData = State.screens[State.current_screen]
|
local currentScreenData = State.screens[State.current_screen]
|
||||||
|
|
||||||
cls(Config.colors.light_grey)
|
cls(Config.colors.dark_grey)
|
||||||
UI.draw_top_bar(currentScreenData.name)
|
UI.draw_top_bar(currentScreenData.name)
|
||||||
|
|
||||||
-- Draw platforms
|
-- Draw platforms
|
||||||
for _, p in ipairs(currentScreenData.platforms) do
|
for _, p in ipairs(currentScreenData.platforms) do
|
||||||
rect(p.x, p.y, p.w, p.h, Config.colors.dark_grey)
|
rect(p.x, p.y, p.w, p.h, Config.colors.green)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Draw items
|
-- Draw items
|
||||||
@@ -432,17 +434,7 @@ function Game.update()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Game.update_dialog()
|
function Game.update_dialog()
|
||||||
if Input.up() then
|
State.selected_dialog_menu_item = UI.update_menu(State.dialog_menu_items, State.selected_dialog_menu_item)
|
||||||
State.selected_dialog_menu_item = State.selected_dialog_menu_item - 1
|
|
||||||
if State.selected_dialog_menu_item < 1 then
|
|
||||||
State.selected_dialog_menu_item = #State.dialog_menu_items
|
|
||||||
end
|
|
||||||
elseif Input.down() then
|
|
||||||
State.selected_dialog_menu_item = State.selected_dialog_menu_item + 1
|
|
||||||
if State.selected_dialog_menu_item > #State.dialog_menu_items then
|
|
||||||
State.selected_dialog_menu_item = 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if Input.action() then
|
if Input.action() then
|
||||||
local selected_item = State.dialog_menu_items[State.selected_dialog_menu_item]
|
local selected_item = State.dialog_menu_items[State.selected_dialog_menu_item]
|
||||||
|
|||||||
Reference in New Issue
Block a user