-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
85 lines (70 loc) · 2.78 KB
/
main.lua
File metadata and controls
85 lines (70 loc) · 2.78 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
local targetImage
local targetX, targetY
local targetWidth, targetHeight
local isTargetClicked
function love.load()
love.window.setMode(800, 600, {resizable=true, vsync=0, minwidth=400, minheight=300})
target = {}
target.x = 200
target.y = 200
target.radius = 50 -- Corrigido 'radius' em vez de 'raidus'
target.radius1 = 40
target.radius2 = 30
target.radius3 = 20
target.radius4 = 10
background = love.graphics.newImage("img/fundo.png")
score = 0
misses = 0 -- Novo contador de erros
timer = 0
gameFont = love.graphics.newFont(40)
end
function love.keypressed(key)
if key == "r" then
timer = 0
end
end
function love.update(dt)
timer = timer + dt
end
function love.draw()
-- Redefine a cor para branco antes de desenhar o fundo
love.graphics.setColor(1, 1, 1)
-- Desenho do background
for i = 0, love.graphics.getWidth() / background:getWidth() do
for j = 0, love.graphics.getHeight() / background:getHeight() do
love.graphics.draw(background, i * background:getWidth(), j * background:getHeight())
end
end
love.graphics.draw(background, 0, 0, 0, love.graphics.getWidth() / background:getWidth(), love.graphics.getHeight() / background:getHeight())
-- Desenho dos círculos do alvo
love.graphics.setColor(1, 0, 0)
love.graphics.circle("fill", target.x, target.y, target.radius)
love.graphics.setColor(1, 1, 1)
love.graphics.circle("fill", target.x, target.y, target.radius1)
love.graphics.setColor(1, 0, 0)
love.graphics.circle("fill", target.x, target.y, target.radius2)
love.graphics.setColor(1, 1, 1)
love.graphics.circle("fill", target.x, target.y, target.radius3)
love.graphics.setColor(1, 0, 0)
love.graphics.circle("fill", target.x, target.y, target.radius4)
-- Desenho da pontuação e do temporizador
love.graphics.setColor(1, 1, 1)
love.graphics.setFont(gameFont)
love.graphics.print("Score: " .. score .. " " .. misses, 0, 0) -- Exibindo a pontuação e os erros no formato "Score: 0 0"
love.graphics.print("Timer: " .. string.format("%.2f", timer), 300, 0) -- Timer na posição corrigida
end
function love.mousepressed(x, y, button, istouch, presses)
if button == 1 then
local mouseToTarget = distanceBetween(x, y, target.x, target.y)
if mouseToTarget < target.radius then
score = score + 1
target.x = math.random(target.radius, love.graphics.getWidth() - target.radius)
target.y = math.random(target.radius, love.graphics.getHeight() - target.radius)
else
misses = misses + 1 -- Incrementa os erros quando clica fora do alvo
end
end
end
function distanceBetween(x1, y1, x2, y2)
return math.sqrt((x2 - x1)^2 + (y2 - y1)^2)
end