-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.lua
More file actions
156 lines (138 loc) · 4.35 KB
/
ui.lua
File metadata and controls
156 lines (138 loc) · 4.35 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
local ui = {}
-- aesthetics
ui.menu = love.graphics.newImage("images/menu.png")
ui.background = love.graphics.newImage("images/uiBackground.png")
ui.backgroundTop = love.graphics.newImage("images/uiBackgroundTop.png")
ui.arrow = love.graphics.newImage("images/arrow.png")
ui.arrowTransparency = 0
-- reference values
ui.mapWidth = 30
ui.mapHeight = 20
ui.tileWidth = 32
ui.tileHeight = 32
ui.width = ui.tileWidth * ui.mapWidth
ui.height = ui.tileHeight * ui.mapHeight
ui.pauseMenu = false
-- custom mouse cursor
pngCursor = love.graphics.newImage("images/target_30.png")
love.mouse.setVisible(false)
love.mouse.setGrabbed(true)
-- Fonts
ui.fontMain = love.graphics.newFont("fonts/Audiowide-Regular.ttf", 40)
ui.fontTitle1 = love.graphics.newFont("fonts/Audiowide-Regular.ttf", 30)
ui.fontTitle2 = love.graphics.newFont("fonts/Audiowide-Regular.ttf", 24)
ui.fontText1 = love.graphics.newFont("fonts/Iceland-Regular.ttf", 20)
-- sound
ui.alarm = love.audio.newSource("sounds/503855__tim-kahn__deep-space-alarm.wav", "static")
ui.alarm:setLooping(true)
ui.alarm:setVolume(0.5)
ui.alarm:setPitch(1.2)
-- health
ui.lifes = {}
ui.maxLife = 4
ui.lifeManager = {}
ui.lifeManager.currentLife = ui.maxLife
ui.lifeManager.isInvincible = false
ui.lifeManager.timer = 0
for i = 1, ui.maxLife do
ui.lifes[i] = {}
ui.lifes[i].img = love.graphics.newImage("images/LED_green.png")
ui.lifes[i].img2 = love.graphics.newImage("images/LED_red.png")
ui.lifes[i].imgCurrent = ui.lifes[i].img
ui.lifes[i].x = 760 + 40 * i
ui.lifes[i].y = ui.mapHeight * ui.tileHeight + 25
ui.lifes[i].ox = ui.lifes[i].img:getWidth()/2
ui.lifes[i].oy = ui.lifes[i].img:getHeight()/2
ui.lifes[i].scale = 1
end
-- enemy counter
ui.currentMob = 0
ui.maxMob = 0
function LoseLife(lifes, lifeManager, dt)
local lifeMax = #lifes
print("Max life =", lifeMax)
if lifeManager.isInvincible == true then
print("I'm invicible!")
elseif lifeManager.currentLife > 0 then
lifeManager.currentLife = lifeManager.currentLife - 1
lifeManager.timer = 1.5
lifeManager.isInvincible = true
print("Current Life =", lifeManager.currentLife)
else
lifeManager.currentLife = 0
print("Game Over!")
end
return(lifeManager.currentLife)
end
function Blink(scale, dt)
if scale >= 0 and scale < 1 then
scale = math.cos(math.acos(scale) + 2 * dt)
elseif scale > - 0.9 and scale < 0 then
scale = math.cos(math.acos(scale) + 5 * dt)
else scale = 0.99
end
return(scale)
end
function ui.PrintCentered(x, y, font, text)
local string = tostring(text)
love.graphics.setFont(font)
love.graphics.print(
string,
x, y,
0, 1, 1,
font:getWidth(string) / 2,
font:getHeight(string) / 2)
end
------------------------------------
function ui.Update(dt)
if ui.lifeManager.currentLife == 1 then
ui.lifes[1].imgCurrent = ui.lifes[1].img2
ui.lifes[1].scale = Blink(ui.lifes[1].scale, dt)
ui.alarm:play()
else
ui.alarm:stop()
ui.lifes[1].imgCurrent = ui.lifes[1].img
ui.lifes[1].scale = 1
end
if ui.currentMob == 0 then
ui.arrowTransparency = ui.arrowTransparency + dt
if ui.arrowTransparency <= 1 then
ui.arrowTransparency = ui.arrowTransparency + dt
elseif ui.arrowTransparency > 1 then
ui.arrowTransparency = 0
end
end
end
------------------------------------
function ui.Draw()
-- bg
love.graphics.draw(ui.background, 0, ui.mapHeight * ui.tileHeight)
love.graphics.draw(ui.backgroundTop, ui.tileWidth * ui.mapWidth / 2, 0,
0, 1, 1, ui.backgroundTop:getWidth() / 2)
love.graphics.setColor(1, 1, 1, 1)
-- health
for i = 1, ui.lifeManager.currentLife do
love.graphics.draw(ui.lifes[i].imgCurrent,
ui.lifes[i].x, ui.lifes[i].y,
0, ui.lifes[i].scale, ui.lifes[i].scale,
ui.lifes[i].ox, ui.lifes[i].oy)
end
-- mob counter
love.graphics.setColor(41/100, 66/100, 52/100, 1)
love.graphics.setFont(ui.fontTitle2)
love.graphics.print(
tostring(ui.currentMob).."/"..tostring(ui.maxMob),
ui.width / 2, 5,
0, 1, 1,
ui.fontTitle2:getWidth(tostring(ui.currentMob).."/"..tostring(ui.maxMob))/2)
-- draw arrow if enemies are all dead
love.graphics.setColor(1, 1, 1, ui.arrowTransparency)
if ui.currentMob == 0 then
love.graphics.draw(
ui.arrow,
ui.mapWidth * ui.tileWidth - ui.arrow:getWidth(),
(ui.mapHeight * ui.tileHeight) / 2)
end
love.graphics.setColor(1, 1, 1, 1)
end
return ui