function love.load()
mainButton = {}
mainButton.x = 200
mainButton.y = 200
mainButton.size = 50
bonusButton = {}
bonusButton.x = mainButton.x + mainButton.size
bonusButton.y = mainButton.y + mainButton.size
bonusButton.size = 25
score = 0
bonusFlag = 10
timer = 10
gameState = 1
myFont = love.graphics.newFont(40)
end
function love.update(dt)
if gameState == 2 then
if timer > 0 then
timer = timer - dt
end
if timer < 0 then
timer = 0
gameState = 1
score = 0
end
end
end
function love.draw()
if gameState == 2 then
love.graphics.setColor(255, 0, 0)
love.graphics.circle("fill", mainButton.x, mainButton.y, mainButton.size)
if score > 0 and score % 25 == 0 then
love.graphics.setColor(0, 255, 0)
love.graphics.circle("fill", bonusButton.x, bonusButton.y, bonusButton.size)
end
end
love.graphics.setFont(myFont)
love.graphics.setColor(255, 255, 255)
love.graphics.print("Score: " .. score)
love.graphics.print("Time: " .. math.ceil(timer), 300, 0)
if gameState == 1 then
love.graphics.printf("Click anywhere to begin!", 0, love.graphics.getHeight()/2, love.graphics.getWidth(), "center")
end
end
function love.mousepressed( x, y, b, istouch )
if b == 1 and gameState == 2 then
if distanceBetween(mainButton.x, mainButton.y, love.mouse.getX(), love.mouse.getY()) < mainButton.size then
score = score + 1
if score % 5 == 0 then
timer = timer + 1
elseif score % 10 == 0 then
timer = timer + 2
elseif score % 15 == 0 then
timer = timer + 3
end
mainButton.x = math.random(mainButton.size, love.graphics.getWidth() - mainButton.size)
mainButton.y = math.random(mainButton.size, love.graphics.getHeight() - mainButton.size)
end
if distanceBetween(bonusButton.x, bonusButton.y, love.mouse.getX(), love.mouse.getY()) < bonusButton.size then
score = score + 25
timer = timer + 10
bonusButton.x = math.random(bonusButton.size, love.graphics.getWidth() - bonusButton.size)
bonusButton.y = math.random(bonusButton.size, love.graphics.getHeight() - bonusButton.size)
end
end
if gameState == 1 then
gameState = 2
timer = 10
end
end
function distanceBetween(x1, y1, x2, y2)
return math.sqrt((y2 - y1)^2 + (x2 - x1)^2)
end