-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgui.lua
More file actions
95 lines (81 loc) · 3.47 KB
/
Copy pathgui.lua
File metadata and controls
95 lines (81 loc) · 3.47 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
91
92
93
94
95
local GUI = {}
local Player = require("player")
function GUI:load()
self.coins = {}
self.coins.img = love.graphics.newImage("assets/coin-new.png")
self.coins.width = self.coins.img:getWidth()
self.coins.height = self.coins.img:getHeight()
self.coins.scale = 3
self.coins.x = 50
self.coins.y = 100
self.font = love.graphics.newFont("assets/bit.ttf", 36)
-- Existing initialization
self.musicButton = {
img = love.graphics.newImage("assets/sound-off.png"), -- Assuming you have a 'sound-off' sprite
imgOn = love.graphics.newImage("assets/sound-on.png"), -- Assuming you have a 'sound-on' sprite
-- x = love.graphics.getWidth() - 100, It was not working in Love 10 -- Positioning the button on the top-right
x = 1180,
y = 50,
scale = 3,
width = nil,
height = nil,
isMusicOn = true -- Music is initially on
}
self.musicButton.width = self.musicButton.img:getWidth() * self.musicButton.scale
self.musicButton.height = self.musicButton.img:getHeight() * self.musicButton.scale
self.hearts = {}
self.hearts.img = love.graphics.newImage("assets/heart.png")
self.hearts.width = self.hearts.img:getWidth()
self.hearts.height = self.hearts.img:getHeight()
self.hearts.x = 0
self.hearts.y = 50
self.hearts.scale = 3
self.hearts.spacing = self.hearts.width * self.hearts.scale + 10
end
function GUI:draw()
self:drawCoins()
self:drawCoinsText()
self:drawHearts()
if self.musicButton.isMusicOn then
love.graphics.draw(self.musicButton.imgOn, self.musicButton.x, self.musicButton.y, 0, self.musicButton.scale, self.musicButton.scale)
else
love.graphics.draw(self.musicButton.img, self.musicButton.x, self.musicButton.y, 0, self.musicButton.scale, self.musicButton.scale)
end
end
function GUI:update(dt)
end
function GUI:drawCoins()
love.graphics.setColor(0, 0, 0, 127)
love.graphics.draw(self.coins.img, self.coins.x + 2, self.coins.y + 2, 0, self.coins.scale, self.coins.scale)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.draw(self.coins.img, self.coins.x, self.coins.y, 0, self.coins.scale, self.coins.scale)
end
function GUI:drawCoinsText()
love.graphics.setFont(self.font)
local x = self.coins.x + self.coins.width * self.coins.scale
local y = self.coins.y + self.coins.height / 2 * self.coins.scale - self.font:getHeight() / 2
love.graphics.setColor(0, 0, 0, 127)
love.graphics.print(" : "..Player.coins, x + 1, y + 1)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print(" : "..Player.coins, x, y)
end
function GUI:drawHearts()
for i = 1, Player.hearts.current do
local x = self.hearts.x + i * self.hearts.spacing
love.graphics.setColor(0, 0, 0, 127)
love.graphics.draw(self.hearts.img, x + 1, self.hearts.y + 1, 0, self.hearts.scale, self.hearts.scale)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.draw(self.hearts.img, x, self.hearts.y, 0, self.hearts.scale, self.hearts.scale)
end
end
function GUI:mousePressed(x, y)
if x > self.musicButton.x and x < self.musicButton.x + self.musicButton.width and y > self.musicButton.y and y < self.musicButton.y + self.musicButton.height then
self.musicButton.isMusicOn = not self.musicButton.isMusicOn
if self.musicButton.isMusicOn then
SFX:resumeBackgroundMusic()
else
SFX:stopBackgroundMusic()
end
end
end
return GUI