-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
90 lines (80 loc) · 2.26 KB
/
main.lua
File metadata and controls
90 lines (80 loc) · 2.26 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
86
87
88
89
90
require "player"
function love.load()
timeLimit = 10 --seconds
mouseClicks = 0
time = 0
players = {Player.new(), Player.new()}
currentPlayer = 1
inactivePlayer = 2
screenW, screenH = love.graphics.getDimensions()
screenWMid, screenHMid = screenW / 2, screenH / 2
love.mouse.setVisible(false)
arraySize = 0
r = 255
g = 255
b = 0
end
function love.update(dt)
time = time + dt
if time >= timeLimit then
timeReset()
end
love.graphics.setColor(r, g, b)
love.graphics.setBackgroundColor(255-r,255-g,255-b)
end
function love.draw()
love.graphics.setNewFont(250/1080*screenH)
love.graphics.print("Clicks : "..mouseClicks, screenWMid -700 , screenHMid - 175)
love.graphics.setNewFont(40/1080*screenH)
local timeRounded = math.floor(time * 100 + 0.5) / 100
timeLeft = timeLimit - timeRounded
love.graphics.print("Time Left : "..timeLeft, 0, 0)
love.graphics.print("Last Scores : ", screenW - 375, 0)
for i,s in ipairs(players[currentPlayer].scores) do
love.graphics.print(s, screenW - 100, i*40)
end
love.graphics.print("Your High Score : "..players[currentPlayer].highScore, screenW - 400, screenH - 50)
love.graphics.print("Opponents High Score : "..players[inactivePlayer].highScore, 10, screenH - 50)
end
function love.mousepressed(x, y, button, isTouch)
mouseClicks = mouseClicks + 1
r = love.math.random(255)
g = love.math.random(255)
b = love.math.random(255)
end
function love.keypressed(key)
if key == 'escape' then
love.event.quit()
end
if key == 'r' then
timeReset()
players[currentPlayer].highScore = 0
end
if key == 'c'then
cheat()
end
if key == 'backspace' then
timeReset()
-- players[currentPlayer].score = lastScore
player = currentPlayer
currentPlayer = inactivePlayer
inactivePlayer = player
end
end
function timeReset()
lastScore = mouseClicks
if lastScore >= players[currentPlayer].highScore then
players[currentPlayer].highScore = lastScore
end
if lastScore > 0 then
table.insert(players[currentPlayer].scores, 1, lastScore)
end
time = 0
mouseClicks = 0
if table.getn(players[currentPlayer].scores) > 10 then
table.remove(players[currentPlayer].scores, 11)
end
end
function cheat()
mouseClicks = mouseClicks + love.math.random(1,4)
end