-
Notifications
You must be signed in to change notification settings - Fork 4
/
helpers.lua
54 lines (46 loc) · 1.45 KB
/
helpers.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
-- Copyright 2013 Arman Darini
helpers = {
----------------------------------------------------------
convertExpToLevel = function(exp)
for i = 1, #game.exp do
if exp < game.exp[i] then return i - 1 end
end
end,
----------------------------------------------------------
getPlayerLevel = function()
return helpers.convertExpToLevel(player.exp)
end,
----------------------------------------------------------
expSinceLevel = function()
return player.exp - game.exp[helpers.getPlayerLevel()]
end,
----------------------------------------------------------
percentLevelComplete = function()
return helpers.expSinceLevel() / (game.exp[helpers.getPlayerLevel() + 1] - game.exp[helpers.getPlayerLevel()])
end,
----------------------------------------------------------
cycleGameBet = function()
game.bet = game.bet + 1
if game.bet > #game.bets then
game.bet = 1
end
return game.bets[game.bet]
end,
----------------------------------------------------------
computeStars = function(score, level)
i = 1
while i < #game.levels[level].stars and score >= game.levels[level].stars[i] do
i = i + 1
end
return i
end,
----------------------------------------------------------
isLevelUnlocked = function(level)
if 1 == level or player.levels[level].highScore > game.levels[level].stars[1] or player.levels[level - 1].highScore > game.levels[level - 1].stars[1] then
return true
else
return false
end
end,
}
return helpers