Code: Select all
require "menu"
function love.load()
buttonFont = love.graphics.newFont(35)
love.graphics.setBackgroundColor(255,255,255)
song = love.audio.newSource("The Bravery.mp3")
song2 = love.audio.newSource("The Bravery (2).mp3")
love.audio.play(song)
song:setLooping(true)
song2:setLooping(true)
love.graphics.setColor(0,255,255)
font = love.graphics.newFont(45)
smallFont = love.graphics.newFont(15)
label = "Playing..."
label2 = "100"
button_spawn(200,400,"Quit","quit")
end
function love.update()
----- Getting mouse positions for the button
mousex = love.mouse.getX()
mousey = love.mouse.getY()
button_check()
-------------- volume controls
if love.keyboard.isDown("p") then
love.audio.pause()
label = "Paused"
end
if love.keyboard.isDown("r") then
love.audio.play(song)
label = "Playing..."
end
if love.keyboard.isDown("escape") then
love.event.push("quit")
end
if love.keyboard.isDown("1") then
love.audio.setVolume(.1)
label2 = "10"
end
if love.keyboard.isDown("2") then
love.audio.setVolume(.2)
label2 = "20"
end
if love.keyboard.isDown("3") then
love.audio.setVolume(.3)
label2 = "30"
end
if love.keyboard.isDown("4") then
love.audio.setVolume(.4)
label2 = "40"
end
if love.keyboard.isDown("5") then
love.audio.setVolume(.5)
label2 = "50"
end
if love.keyboard.isDown("6") then
love.audio.setVolume(.6)
label2 = "60"
end
if love.keyboard.isDown("7") then
love.audio.setVolume(.7)
label2 = "70"
end
if love.keyboard.isDown("8") then
love.audio.setVolume(.8)
label2 = "80"
end
if love.keyboard.isDown("9") then
love.audio.setVolume(.9)
label2 = "90"
end
if love.keyboard.isDown("0") then
love.audio.setVolume(1.0)
label2 = "100"
end
if love.keyboard.isDown("`") then
love.audio.setVolume(0)
label2 = "0"
end
------Switching songs from English to Japanese versions
if love.keyboard.isDown("-") then
love.audio.stop()
love.audio.rewind(song2,song)
song2:play()
end
if love.keyboard.isDown("=") then
love.audio.stop()
love.audio.rewind(song,song2)
song:play()
end
end
function love.draw()
button_draw()
love.graphics.setFont(smallFont)
love.graphics.print(label.." Volume: "..label2,150,100)
love.graphics.rectangle("fill",150,140,525,20)
love.graphics.setFont(font)
love.graphics.print("The Bravery - supercell",150,160)
love.graphics.setFont(smallFont)
love.graphics.print("Press 'p' to pause\nPress 'r' to resume\nPress 1-10 to change volume\nPress 'escape' to exit\nPress '-' to switch to Japanese Version\nPress '=' to switch to English Version",150,220)
end
function love_mousepressed(x,y)
button_click(x,y)
end
and this:
Code: Select all
button = {}
function button_spawn(x,y,text,id)
table.insert(button, {x = x, y = y, text = text, id = id, mouseover = false})
end
function button_draw()
for i,v in ipairs(button) do
if v.mouseover == false then
love.graphics.setColor(0,0,0)
end
if v.mouseover == true then
love.graphics.setColor(0,255,255)
end
love.graphics.setFont(buttonFont)
love.graphics.print(v.text,v.x,v.y)
end
end
function button_click(x,y)
for i,v in ipairs(button) do
if x > v.x and
x< v.x + buttonFont:getWidth(v.text) and
y > v.y and
y < v.y + buttonFont:getHeight() then
if v.id == "quit" then
love.event.push("quit")
end
if v.id == "start" then
gamestate = "playing"
end
end
end
end
function button_check()
for i,v in ipairs(button) do
if mousex > v.x and
mousex < v.x + buttonFont:getWidth(v.text) and
mousey > v.y and
mousey < v.y + buttonFont:getHeight(v.text) then
v.mouseover = true
else
v.mouseover = false
end
end
end
What I want it to do is for the color to be (0,255,255) on default for all the text except the button's text (it's default is black), and when I hover over the button, the button will turn to (0,255,255) and when I click on it, it would exit the program...
I would appreciate it if you helped me out!