-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUI.pde
367 lines (310 loc) · 11.9 KB
/
UI.pde
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
class UI {
int border = 1;
int leftFullWidth, leftFullHeight, leftInnerWidth, leftInnerHeight, leftOuterX, leftInnerX, leftOuterY, leftInnerY, leftOutline;
int mapFullWidth, mapFullHeight, mapInnerWidth, mapInnerHeight, mapOuterX, mapInnerX, mapOuterY, mapInnerY, mapOutline;
int rightFullWidth, rightFullHeight, rightInnerWidth, rightInnerHeight, rightOuterX, rightInnerX, rightOuterY, rightInnerY, rightOutline;
Controll playButton, helpButton, exitButton, pauseButton, showMapButton, soundButton, infoExitButton, pauseSoundButton, pauseNextButton, pauseExitButton;
Controll headerLabel, mapCountLabel, timeLabel, bestLabel, pauseMapsLabel, pauseTimeLabel, pauseBestLabel;
Controll infoBigLabel;
void drawStartScreen() {
drawSimpleBorder();
// controll elements values
int vMargin = Math.round((height-border*2)/13); // 4 elements with 5 margins (element weight = 2, margin -- 1) 4*2 + 5*1 = 8 + 5 = 13
int eHeight = vMargin*2;
int hMargin = Math.round((width-border*2)/4*1.5); // 1 element with 2 margins (element weight = 1, margin -- 1.5) 1*1 + 2*1.5 = 1 + 3 = 4
int eWidth = Math.round(hMargin/1.5);
headerLabel.setWidth(eWidth*2)
.setHeigth(eHeight)
.setX(hMargin-(eWidth/2))
.setY(vMargin*1+eHeight*0)
.setText("Mazelerometer")
.show(click);
playButton.setWidth(eWidth)
.setHeigth(eHeight)
.setX(hMargin)
.setY(vMargin*2+eHeight*1)
.show(click);
helpButton.setWidth(eWidth)
.setHeigth(eHeight)
.setX(hMargin)
.setY(vMargin*3+eHeight*2)
.show(click);
exitButton.setWidth(eWidth)
.setHeigth(eHeight)
.setX(hMargin)
.setY(vMargin*4+eHeight*3)
.show(click);
}
void drawInfoScreen(int type) {
drawSimpleBorder();
// controll elements values
int vMargin = Math.round((height-border*2)/13); // 4 elements with 5 margins (element weight = 2, margin -- 1) 4*2 + 5*1 = 8 + 5 = 13
int eHeight = vMargin*2;
int hMargin = Math.round(((width-border*2)/4)*1.5); // 1 element with 2 margins (element weight = 1, margin -- 1.5) 1*1 + 2*1.5 = 1 + 3 = 4
int eWidth = Math.round(hMargin/1.5);
if (type == 1) { // error
headerLabel.setText("Error");
infoBigLabel.setTextSize(80)
.setTextColor(#cf0808)
.setText("Error");
infoExitButton.setText("Exit");
} else { // help
headerLabel.setText("How to play?");
infoBigLabel.setTextSize(25)
.setTextColor(0)
.setText("You need to find exit of the maze and lead ball there.\n"+
"At at game start you can see maze map, but it will dissapear soon.\n"+
"You can show map again, but only several times (and for short time)\n"+
"Your goal and ball are always highlighted on the map.\n"+
"The sooner you finish the better.");
infoExitButton.setText("Back");
}
headerLabel.setWidth(eWidth*2)
.setHeigth(eHeight)
.setX(hMargin-(eWidth/2))
.setY(vMargin*1+eHeight*0)
.show(false);
infoBigLabel.setWidth(eWidth*2)
.setHeigth(eHeight*2+vMargin)
.setX(hMargin-(eWidth/2))
.setY(vMargin*2+eHeight*1)
.show(false);
infoExitButton.setWidth(eWidth)
.setHeigth(eHeight)
.setX(hMargin)
.setY(vMargin*4+eHeight*3)
.show(click);
}
void drawPauseScreen(int type) {
drawSimpleBorder();
// controll elements values
int vMargin = Math.round((height-border*2)/13); // 4 elements with 5 margins (element weight = 2, margin -- 1) 4*2 + 5*1 = 8 + 5 = 13
int eHeight = vMargin*2;
int hMargin = Math.round((width-border*2)/13); // 3 element with 4 margins (element weight = 3 / 5, margin -- 1 / 4) 3*3 + 4*1 = 9 + 4 = 13
int eWidthPart = hMargin;
if (type == 1) { // win
headerLabel.setText("You win");
pauseNextButton.setText("Next");
} else { // pause
headerLabel.setText("Pause");
pauseNextButton.setText("Back");
}
pauseSoundButton.setText("Sound");
pauseExitButton.setText("Exit");
headerLabel.setWidth(eWidthPart*5)
.setHeigth(eHeight)
.setX(hMargin*4)
.setY(vMargin*1+eHeight*0)
.show(false);
pauseSoundButton.setWidth(eWidthPart*3)
.setHeigth(eHeight)
.setX(hMargin)
.setY(vMargin*4+eHeight*3)
.show(click);
pauseNextButton.setWidth(eWidthPart*3)
.setHeigth(eHeight)
.setX(hMargin*2+(eWidthPart*3)*1)
.setY(vMargin*4+eHeight*3)
.show(click);
pauseExitButton.setWidth(eWidthPart*3)
.setHeigth(eHeight)
.setX(hMargin*3+(eWidthPart*3)*2)
.setY(vMargin*4+eHeight*3)
.show(click);
pauseMapsLabel.setWidth(eWidthPart*4)
.setHeigth(eHeight)
.setX(Math.round(hMargin*4.5))
.setY(vMargin*2+eHeight*1)
.setText("Maps left: "+availableMaps)
.show(false);
pauseTimeLabel.setWidth(eWidthPart*4)
.setHeigth(eHeight)
.setX(hMargin)
.setY(vMargin*3+eHeight*2)
.setText("Time spent: "+timeSpent+"s.")
.show(false);
pauseBestLabel.setWidth(eWidthPart*4)
.setHeigth(eHeight)
.setX(hMargin*4+eWidthPart*4)
.setY(vMargin*3+eHeight*2)
.setText("Best time: "+timeBest+"s.")
.show(false);
}
void drawGameScreen() {
drawBlock(0, false); // left
drawBlock(1, false); // map
drawBlock(2, false); // right
// controll elements
int lVSize = Math.round(leftInnerHeight/7.0); // (left vertical size) = 3 elements with 4 margins (element weight = 1, margin -- 1) 3*1 + 4*1 = 3 + 4 = 7
int lVMargin = lVSize; // left vertical margin
int lEHeight = lVSize; // left element height
int lHMargin = Math.round(leftInnerWidth/15); // left horizontal margin
int lEWidth = lHMargin*14; // left element width
int rVSize = Math.round(rightInnerHeight/7.0); // (right vertical size) = 3 elements with 4 margins (element weight = 1, margin -- 1) 3*1 + 4*1 = 3 + 4 = 7
int rVMargin = rVSize;
int rEHeight = rVSize;
int rHMargin = Math.round(rightInnerWidth/15); // right horizontal margin
int rEWidth = rHMargin*14;
pauseButton.setWidth(lEWidth)
.setHeigth(lEHeight)
.setX(leftInnerX+lHMargin)
.setY(leftInnerY+lVMargin*1+lEHeight*0)
.show(click);
soundButton.setWidth(lEWidth)
.setHeigth(lEHeight)
.setX(leftInnerX+lHMargin)
.setY(leftInnerY+lVMargin*2+lEHeight*1)
.show(click);
showMapButton.setWidth(lEWidth)
.setHeigth(lEHeight)
.setX(leftInnerX+lHMargin)
.setY(leftInnerY+lVMargin*3+lEHeight*2)
.show(click);
timeLabel.setWidth(rEWidth)
.setHeigth(rEHeight)
.setX(rightInnerX+rHMargin)
.setY(rVMargin*1+rEHeight*0)
.setText("Time:"+timeSpent+"s.")
.show(click);
bestLabel.setWidth(lEWidth)
.setHeigth(lEHeight)
.setX(rightInnerX+lHMargin)
.setY(rightInnerY+lVMargin*2+lEHeight*1)
.setText("Best:"+timeBest+"s.")
.show(click);
mapCountLabel.setWidth(rEWidth)
.setHeigth(rEHeight)
.setX(rightInnerX+rHMargin)
.setY(rVMargin*3+rEHeight*2)
.setText("Maps:"+availableMaps)
.show(click);
}
void initLeftBlock() {
leftOutline = border; // if want to change :-)
leftFullWidth = (width - height)/2;
leftInnerWidth = leftFullWidth - leftOutline; // left border = outline, right border from mapBlock
leftFullHeight = height;
leftInnerHeight = leftFullHeight - leftOutline*2; // top and bottom borders are outline
leftOuterX = 0; // start of screen
leftInnerX = leftOuterX + leftOutline; // outer + outline
leftOuterY = 0; // start of screen
leftInnerY = leftOuterY + leftOutline; // outer + outline
}
void initMapBlock() {
mapOutline = border; // if want to change :-)
mapFullWidth = height;
mapInnerWidth = mapFullWidth - mapOutline*2; // left border from rightBlock, right border = outline
mapFullHeight = height; // top otline, innerHeight, bottom outline
mapInnerHeight = mapFullHeight - mapOutline*2; // top and bottom borders are outline
mapOuterX = leftFullWidth; // after leftBlock
mapInnerX = mapOuterX + mapOutline; // outer + outline
mapOuterY = 0; // start of screen
mapInnerY = mapOuterY + mapOutline; // outer + outline
}
void initRightBlock() {
rightOutline = border; // if want to change :-)
rightFullWidth = (width - height)/2;
rightInnerWidth = rightFullWidth - rightOutline; // right border = outline, left border from mapBlock
rightFullHeight = height; // height
rightInnerHeight = rightFullHeight - rightOutline*2; // top border innerH. bottom border
rightOuterX = leftFullWidth + mapFullWidth; // after map border
rightInnerX = rightOuterX; // outer without outline (outline is right)
rightOuterY = 0; // start of the screen
rightInnerY = rightOuterY + rightOutline; // outer + outline
}
void initControlls() {
// buttons
playButton = new Controll(1)
.setOutlineWidth(border)
.setText("Play");
helpButton = new Controll(1)
.setOutlineWidth(border)
.setText("Help");
exitButton = new Controll(1)
.setOutlineWidth(border)
.setText("Exit");
pauseButton = new Controll(1)
.setOutlineWidth(border)
.setText("Pause");
showMapButton = new Controll(1)
.setOutlineWidth(border)
.setText("Map");
soundButton = new Controll(1)
.setOutlineWidth(border)
.setText("Sound");
infoExitButton = new Controll(1)
.setOutlineWidth(border);
pauseSoundButton = new Controll(1)
.setOutlineWidth(border);
pauseNextButton = new Controll(1)
.setOutlineWidth(border);
pauseExitButton = new Controll(1)
.setOutlineWidth(border);
// labels
headerLabel = new Controll(0)
.setOutlineWidth(border);
mapCountLabel = new Controll(0)
.setOutlineWidth(border)
.setTextSize(35);
timeLabel = new Controll(0)
.setOutlineWidth(border)
.setTextSize(35);
bestLabel = new Controll(0)
.setOutlineWidth(border)
.setTextSize(35);
pauseMapsLabel = new Controll(0)
.setOutlineWidth(border)
.setTextSize(35);
pauseTimeLabel = new Controll(0)
.setOutlineWidth(border)
.setTextSize(35);
pauseBestLabel = new Controll(0)
.setOutlineWidth(border)
.setTextSize(35);
// bid label
infoBigLabel = new Controll(2)
.setOutlineWidth(border);
}
void drawSimpleBorder() {
// screen values
int fullWidth, fullHeight, innerWidth, innerHeight, outerX, innerX, outerY, innerY, outline;
outline = border;
fullWidth = width;
innerWidth = fullWidth - outline*2;
fullHeight = height;
innerHeight = fullHeight - outline*2;
outerX = 0;
innerX = outerX + outline;
outerY = 0;
innerY = outerY + outline;
// draw screen
fill(0);
rect(outerX, outerY, fullWidth, fullHeight);
fill(255);
rect(innerX, innerY, innerWidth, innerHeight);
}
void drawBlock(int block, boolean useMap) {
if (block == 0) {
fill(0);
rect(leftOuterX, leftOuterY, leftFullWidth, leftFullHeight);
fill(255);
rect(leftInnerX, leftInnerY, leftInnerWidth, leftInnerHeight);
} else if (block == 1) {
fill(0);
rect(mapOuterX, mapOuterY, mapFullWidth, mapFullHeight);
if (useMap) {
fill(170);
} else {
fill(150);
}
rect(mapInnerX, mapInnerY, mapInnerWidth, mapInnerHeight);
} else if (block == 2) {
fill(0);
rect(rightOuterX, rightOuterY, rightFullWidth, rightFullHeight);
fill(255);
rect(rightInnerX, rightInnerY, rightInnerWidth, rightInnerHeight);
}
}
UI() {
}
}