-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
66 lines (57 loc) · 1.57 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function love.load()
button = {}
button.x=200
button.y=200
button.size=50
score = 0
timer = 10
gameState = true
fimjogo=0
myFont=love.graphics.newFont(40)
end
function love.update(dt)
if gameState==false then
if timer > 0 then
timer = timer-dt
end
if timer < 0 then
timer=0
gameState=true
fimjogo=1
end
end
end
function love.draw()
if gameState==false then
love.graphics.setColor(20, 100, 20)
love.graphics.circle("fill", button.x, button.y, button.size)
love.graphics.setColor(255, 255, 255)
love.graphics.setFont(myFont)
love.graphics.print("Score: "..score)
--math.ceil arredonda para cima
love.graphics.print("Timer: "..math.ceil(timer),200,0)
elseif fimjogo==1 then
love.graphics.setFont(myFont)
love.graphics.print("Para começar clique em qualquer lugar da tela",0, love.graphics.getHeight()/2)
love.graphics.print("Score: "..score)
else
love.graphics.setFont(myFont)
love.graphics.print("Para começar clique em qualquer lugar da tela",0, love.graphics.getHeight()/2)
end
end
function love.mousepressed(x, y, buttonMouse, isTouch)
if gameState then
gameState=false
timer=10
score = 0
end
distancia = math.sqrt((y-button.y)^2 + (x-button.x)^2)
if buttonMouse == 1 and gameState==false then
if distancia < button.size then
score=score+1
-- love.graphics.getWidth pega largura e altura da janela
button.x=math.random(button.size, love.graphics.getWidth()-button.size)
button.y=math.random(button.size, love.graphics.getHeight()-button.size)
end
end
end