Skip to content

Commit 095b0bf

Browse files
authored
Add files via upload
1 parent f1427c5 commit 095b0bf

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

testProject/main.lua

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
-- use alt+L to open love2D
2+
-- you need to linker love2D first
3+
function love.load()
4+
target = {}
5+
target.x = 300
6+
target.y = 300
7+
target.radius = 50
8+
9+
score = 0
10+
timer = 0
11+
12+
gameFont = love.graphics.newFont(40)
13+
end
14+
15+
function love.update(dt)
16+
end
17+
18+
function love.draw()
19+
love.graphics.setColor(1, 0, 0)
20+
love.graphics.circle("fill", target.x, target.y, target.radius)
21+
22+
love.graphics.setColor(1, 1, 1)
23+
love.graphics.setFont(gameFont)
24+
love.graphics.print(score, 0, 0)
25+
end
26+
27+
function love.mousepressed(x, y, button, istouch, presses)
28+
if button == 1 then
29+
-- 1 is mean primary button
30+
-- 2 is secondary button
31+
-- 3 is middle button
32+
local mouseToTarget = distanceBetween(x, y, target.x, target.y)
33+
if mouseToTarget < target.radius then
34+
score = score + 1
35+
target.x = math.random(target.radius, love.graphics.getWidth() - target.radius)
36+
target.y = math.random(target.radius, love.graphics.getHeight() - target.radius)
37+
end
38+
end
39+
end
40+
41+
function distanceBetween(x1, y1, x2, y2)
42+
return math.sqrt((x2 - x1)^2 + (y2 - y1)^2)
43+
end

0 commit comments

Comments
 (0)