-
Notifications
You must be signed in to change notification settings - Fork 1
/
highscore_table.lua
50 lines (39 loc) · 1.5 KB
/
highscore_table.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
require "button"
HighscoreTable = {}
HighscoreTable.__index = HighscoreTable
function HighscoreTable:create()
local object = {}
setmetatable(object, HighscoreTable)
object.button_font = love.graphics.newFont("assets/fonts/AmaticSC-Regular.ttf", 40*scale)
object.title_font = love.graphics.newFont("assets/fonts/AmaticSC-Regular.ttf", 80*scale)
x = love.graphics.getWidth() - (200*scale) - 10
y = love.graphics.getHeight() - object.button_font:getHeight() - 10
object.button = Button:create("Return to Main", x, y, 200*scale, object.button_font:getHeight())
return object
end
function HighscoreTable:draw()
love.graphics.setFont(self.title_font)
love.graphics.printf("As The Crow Flies Highscores", 0, (50*scale), love.graphics.getWidth(), "center")
y = self.title_font:getHeight() + (50*scale) + 10
love.graphics.setFont(self.button_font)
for i, score, name in highscore() do
love.graphics.printf(i .. ". " .. name .. " - " .. score, 0, y+((i-1)*self.button_font:getHeight()), love.graphics.getWidth(), "center")
end
self.button:draw()
end
function HighscoreTable:hover_state(x, y)
if x >= self.button.x and x < self.button.x + self.button.width
and y >= self.button.y and y < self.button.y + self.button.height then
self.button.hover = true
else
self.button.hover = false
end
end
function HighscoreTable:click(x, y)
if x >= self.button.x and x < self.button.x + self.button.width
and y >= self.button.y and y < self.button.y + self.button.height then
return Buttons.Menu
else
return nil
end
end