Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- show = false
- game = {
- state = {
- menu = true,
- run = false
- }
- }
- buttons = {
- menu = {},
- run = {}
- }
- function button (text, fn)
- return {text = text, fn = fn}
- end
- function start()
- game.state['menu'] = false
- game.state['run'] = true
- end
- function love.load()
- table.insert(buttons.menu, button('Play', start))
- table.insert(buttons.menu, button('Exit', love.event.quit))
- end
- function love.draw()
- if game.state['menu'] then
- local sx, sy = love.graphics.getWidth() * (1/3), 50
- local margin = 10
- local tot = (sy + margin) * #buttons.menu
- local cursor = 0
- -- initialize the button to false
- currentButton = false
- for i,s in ipairs(buttons.menu) do
- local x, y = love.graphics.getWidth() * 0.5 - sx * 0.5, love.graphics.getHeight() * 0.5 - (tot * 0.5) + cursor
- mx, my = love.mouse.getPosition()
- -- make this local just so its easier to make sense of the code
- local hot = mx > x and mx < x + sx and my > y and my < y + sy
- if hot and show then
- buttons.menu[i].fn()
- end
- local color = {0.4, 0.4, 0.5, 1}
- if hot then
- color = {0.8, 0.8, 0.9, 1}
- end
- love.graphics.setColor(unpack(color))
- love.graphics.rectangle('fill', x, y, sx, sy)
- cursor = cursor + sy + margin
- font = love.graphics.newFont(20)
- love.graphics.setColor(0, 0, 0)
- love.graphics.printf(s.text, font, x, y + (sy * 0.5) - 10, sx, 'center')
- end
- --if show == true then
- -- buttons.menu[play]:button.fn
- --end
- show = false
- end
- end
- function love.mousereleased (x, y, button)
- if button == 1 then
- show = true
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement