state changes and a menu
This commit is contained in:
+36
-3
@@ -1,10 +1,43 @@
|
||||
function DrawMenu()
|
||||
love.graphics.setFont(GameFont)
|
||||
local function button(x,y, w, h, text, selected)
|
||||
--x,y is the top left corner of the button
|
||||
local rounding = 30 -- used for rounding the buttons
|
||||
|
||||
if not selected then
|
||||
love.graphics.setColor(love.math.colorFromBytes(41,134,204))
|
||||
elseif selected then
|
||||
love.graphics.setColor(love.math.colorFromBytes(244,67,54))
|
||||
end
|
||||
-- Draw rectangle
|
||||
love.graphics.rectangle("line", x, y, w, h, rounding, rounding)
|
||||
|
||||
-- Get width and height of text
|
||||
local tw = MenuFont:getWidth(text)
|
||||
local th = MenuFont:getHeight(text)
|
||||
-- Calculate position to center the text
|
||||
local textX = x + (w - tw) / 2
|
||||
local textY = y + (h - th) / 2
|
||||
-- Place text inside the rectangle
|
||||
love.graphics.setFont(MenuFont)
|
||||
love.graphics.print(text, textX, textY)
|
||||
|
||||
end
|
||||
|
||||
local function title()
|
||||
local height = love.graphics.getHeight()
|
||||
local width = love.graphics.getWidth()
|
||||
love.graphics.setColor(1,1,1)
|
||||
love.graphics.setFont(GameFont)
|
||||
love.graphics.setColor(0.5,1,1)
|
||||
love.graphics.rectangle("fill", 0, 0, width, height)
|
||||
love.graphics.setColor(0,0,0)
|
||||
love.graphics.print("MENU", 100,100)
|
||||
end
|
||||
|
||||
|
||||
function DrawMenu()
|
||||
local bwidth, bheight = 300, 140
|
||||
title()
|
||||
button(100, 200, bwidth, bheight, "Play", MENU_POS == 0 and true or false)
|
||||
button(100, 350, bwidth, bheight, "???", MENU_POS == 1 and true or false)
|
||||
button(100, 500, bwidth, bheight, "???", MENU_POS == 2 and true or false)
|
||||
button(100, 650, bwidth, bheight, "Quit", MENU_POS == 3 and true or false)
|
||||
end
|
||||
+35
-5
@@ -1,10 +1,40 @@
|
||||
function MenuKeyPressed(key)
|
||||
if key == "escape" then
|
||||
love.event.quit()
|
||||
if key == 'return' then
|
||||
-- 0 Start Game
|
||||
-- 1 ??
|
||||
-- 2 ???
|
||||
-- 3 Quit
|
||||
if MENU_POS == 0 then
|
||||
--Change state to GAME!
|
||||
_G.GAMESTATE = "GAME"
|
||||
print("STATE CHANEGD: GAME!")
|
||||
|
||||
elseif MENU_POS == 1 then
|
||||
print("STATE CHANEGD: DUNNO!")
|
||||
|
||||
elseif MENU_POS == 2 then
|
||||
print("STATE CHANEGD: DUNNO!")
|
||||
|
||||
elseif MENU_POS == 3 then
|
||||
love.event.quit()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if key == "space" then
|
||||
--Change state to GAME!
|
||||
GAMESTATE = "GAME"
|
||||
if love.keyboard.isDown("up") then
|
||||
if _G.MENU_POS == 0 then
|
||||
_G.MENU_POS = 0
|
||||
else
|
||||
_G.MENU_POS = _G.MENU_POS - 1
|
||||
end
|
||||
end
|
||||
|
||||
if love.keyboard.isDown("down") then
|
||||
if _G.MENU_POS >= _G.MENU_MAX then
|
||||
_G.MENU_POS = _G.MENU_MAX
|
||||
else
|
||||
_G.MENU_POS = _G.MENU_POS + 1
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user