-
Notifications
You must be signed in to change notification settings - Fork 1
/
game_over.lua
62 lines (52 loc) · 1.5 KB
/
game_over.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
55
56
57
58
59
60
61
62
require "button"
GameOver = {}
GameOver.__index = GameOver
function GameOver:create()
local object = {}
setmetatable(object, GameOver)
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)
object.button_list = {
Button:create("Play Again", x, 150*scale, 200*scale, object.button_font:getHeight()),
{},
{},
{},
Button:create("Exit to Main", x, (150*scale+object.button_font:getHeight()+padding), 200*scale, object.button_font:getHeight())
}
return object
end
function GameOver:draw()
love.graphics.setFont(self.title_font)
love.graphics.printf("Game Over", 0, 50*scale, love.graphics.getWidth(), "center")
love.graphics.setFont(self.button_font)
for i, button in ipairs(self.button_list) do
if button.draw ~= nil then
button:draw()
end
end
end
function GameOver:hover_state(x, y)
for i, button in ipairs(self.button_list) do
if button.hover ~= nil then
button.hover = false
end
end
for i, button in ipairs(self.button_list) do
if button.hover ~= nil then
if x >= button.x and x < button.x + button.width
and y >= button.y and y < button.y + button.height then
button.hover = true
end
end
end
end
function GameOver:click(x, y)
for i, button in ipairs(self.button_list) do
if button.draw ~= nil then
if x >= button.x and x < button.x + button.width
and y >= button.y and y < button.y + button.height then
return i
end
end
end
end