Skip to content

Instantly share code, notes, and snippets.

@qoh
Created March 3, 2013 03:33
Show Gist options
  • Save qoh/5074372 to your computer and use it in GitHub Desktop.
Save qoh/5074372 to your computer and use it in GitHub Desktop.
function createMenu(options)
local menu = Gamestate.new()
local font = assets.font.large
local textHeight = 40
local selection = 1
local selectObj = {x=0, y=0, width=0, height=0}
local offset = {x=100, y=100}
local padding = {x=8, y=0}
local glowfx = 0
local scrolltime = 0.2
function menu:enter()
end
function menu:update(dt)
glowfx = glowfx + dt
menuAnimUpdate(dt)
local _, aY = love.joystick.getAxes(1)
end
function menu:draw()
menuAnimDraw()
selectObj.x = offset.x - padding.x
love.graphics.setLine(1,'smooth')
love.graphics.setColor(255,255,255,100 + math.sin(glowfx*4)*30)
love.graphics.rectangle('fill',selectObj.x,selectObj.y,selectObj.width,selectObj.height)
love.graphics.setColor(255,255,255)
love.graphics.rectangle('line',selectObj.x,selectObj.y,selectObj.width,selectObj.height)
local shadow = 2
for i,v in pairs(options) do
local x,y = offset.x, offset.y + (i-1)*textHeight
local width = font:getWidth(v.text) + padding.x*2
local height = font:getHeight(v.text) + padding.y*2
if selection == i then
selectObj.y = y
selectObj.width = width
selectObj.height = height
local infoheight = assets.font.small:getHeight(v.info)
love.graphics.setFont(assets.font.small)
love.graphics.print(
v.info,
x + width + padding.x
, y + height/2 - infoheight/2
)
end
love.graphics.setFont(font)
love.graphics.setColor(0,0,0,100)
love.graphics.print(v.text,x+shadow,y+shadow)
love.graphics.setColor(255,255,255)
love.graphics.print(v.text,x,y)
end
end
function menu:keypressed(k,uni)
if k=='down' then
selection = (selection<#options and selection+1 or 1)
elseif k=='up' then
selection = (selection>1 and selection-1 or #options)
elseif k=='return' then
local option = options[selection]
option:action()
elseif k=='escape' then
love.event.quit()
end
end
function menu:joystickpressed(joy,b)
end
return menu
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment