-
Notifications
You must be signed in to change notification settings - Fork 1
/
ui.lua
169 lines (126 loc) · 5.23 KB
/
ui.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
----------------------------------------------------------------------------------------------------
-- Code related to drawing the UI (user interface)
----------------------------------------------------------------------------------------------------
function drawUI()
love.graphics.setColor(1, 1, 1, 1)
-- rectangle for health bars and around play area
love.graphics.rectangle('line', 2, 2, WIDTH - 4, 30)
love.graphics.rectangle('line', 2, 32, WIDTH - 4, HEIGHT - 34)
drawShootButton()
drawLives()
drawHealthBars()
love.graphics.setColor(1, 1, 1, 1)
end
-- shoot BUTTON rectangle -- change states while shot in progress
function drawShootButton()
if shotInProgress == true then
love.graphics.setColor(0.5, 0, 0, 1)
love.graphics.ellipse('fill', WIDTH - 50, HEIGHT - 50, 30, 30)
else
love.graphics.setColor(16 / 255, 178 / 255, 197 / 255, 1)
love.graphics.ellipse('fill', WIDTH - 50, HEIGHT - 50, 30, 30)
end
end
-- draw how many lives each has
function drawLives()
love.graphics.setColor(1, 1, 0, 1)
for i = 1, player1.lives do
love.graphics
.ellipse('fill', WIDTH / 2 + 35 + 20 * i, 16, 8, 8)
end
for i = 1, player2.lives do
love.graphics
.ellipse('fill', WIDTH / 2 - 35 - 20 * i, 16, 8, 8)
end
end
-- draw health bars - responsive depending on WIDTH
function drawHealthBars()
topOffset = 10
barWidth = WIDTH / 2 - 200
-- right health bar
love.graphics.setColor((255 - player1.health * 2.55) / 255, 1, 0, 1)
love.graphics.rectangle('fill', WIDTH / 2 + 150, topOffset, barWidth, 10)
if player1.health < 100 then
love.graphics.setColor(223 / 255, (45 + player1.health) / 255,
(45 + player1.health) / 255, 1)
love.graphics.rectangle('fill', (WIDTH / 2 + 150) + barWidth - barWidth *
((100 - player1.health) / 100), topOffset,
barWidth - barWidth * ((player1.health) / 100), 10)
end
-- left health bar
love.graphics.setColor((255 - player2.health * 2.55) / 255, 1, 0, 1)
love.graphics.rectangle('fill', WIDTH / 2 - barWidth - 150, topOffset, barWidth, 10)
if player2.health < 100 then
love.graphics.setColor(224 / 255, (45 + player2.health) / 255,
(45 + player2.health) / 255, 1)
love.graphics.rectangle('fill', (WIDTH / 2 - barWidth - 150), topOffset,
barWidth - barWidth * ((player2.health) / 100), 10)
end
end
function drawForceAndAngle(playerN, tempHack)
-- different offset depending on player
if tempHack == 1 then
xOffset = playerN.x - 140
angleY = playerN.y + 80
forceY = playerN.y + 92
else
xOffset = playerN.x + 55
angleY = playerN.y + 78
forceY = playerN.y + 90
end
-- black background behind angle and force
love.graphics.setColor(0, 0, 0, 0.7)
love.graphics.rectangle('fill', xOffset + 12, angleY, 70, 13, 4, 4)
love.graphics.rectangle('fill', xOffset + 24, forceY + 1, 66, 12, 4, 4)
-- print force (red)
love.graphics.setColor(1, 0, 0, 1)
love.graphics.setFont(pixelFont, 20)
love.graphics.print('GJ', xOffset + 76, forceY) -- GigaJoules
love.graphics.printf(string.format("%.5f", playerN.force), xOffset, forceY, 75, 'right')
-- print angle (white)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.printf(string.format("%.5f", 360 - playerN.angle), xOffset, angleY, 75, 'right')
love.graphics.ellipse('line', xOffset + 78, angleY + 3, 2, 2)
end
function drawShips()
-- in the user interface (top left and top right)
love.graphics.draw(ss1, 24, 11)
love.graphics.draw(ss2, WIDTH - 32, 11)
-- love.graphics.setColor(1, 0.6, 0.6, 1)
-- love.graphics.ellipse('fill', player1.x, player1.y, 8, 8)
-- love.graphics.ellipse('fill', player2.x, player2.y, 8, 8)
if player1.health > 0 then
love.graphics.draw(ss1, player1.x - 4, player1.y - 4)
end
if player2.health > 0 then
love.graphics.draw(ss2, player2.x - 4, player2.y - 4)
end
-- love.graphics.draw(ss1, player1.x, player1.y, player1.angle, 1, 1, 4, 4)
end
--[[
Dim all the shot trails on the screen
meant to run after every shot
works by drawing a black rectangle with low opacity over the whole screen
then redraws all other elements on top
--]]
function dimTrails()
print("dimTrails EXECUTED")
love.graphics.setCanvas(canvas)
love.graphics.setColor(0, 0, 0, 0.15) -- don't fortget to reset ?
love.graphics.rectangle('fill', 0, 0, WIDTH, HEIGHT)
love.graphics.setColor(1, 1, 1, 1) -- reset back !?
drawPlanets() -- execute inside `canvas` ?!
drawShips()
drawUI()
love.graphics.setCanvas() -- reset canvas ?!
end
function drawPlanets()
for i = 1, numOfPlanets do
love.graphics.setColor(0.1, 0.1, 0.1, 1)
love.graphics.ellipse('fill', allPlanets[i].x, allPlanets[i].y,
allPlanets[i].r, allPlanets[i].r)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.ellipse('line', allPlanets[i].x, allPlanets[i].y,
allPlanets[i].r, allPlanets[i].r)
end
end