-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDING.pde
292 lines (279 loc) · 12.1 KB
/
DING.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
Bell [] Bell = new Bell[16];
SoundGenerator Sound;
boolean GameStarted = false;
boolean DifficultyChosen = false;
boolean StartPlaying = false;
int Score = 0;
int Difficulty = -1;
int timeOut = 0;
int [] Sequence;
int SequencePosition = 0;
int UserSequencePosition = 0;
boolean Defeat = false;
boolean DisplayTutorial = false;
boolean SequenceComplete = false;
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Setup
void setup() {
fullScreen();
Bell[0] = new Bell(0,0*width/4,0*height/4,width/4,height/4,#00A2FF); //light blue
Bell[1] = new Bell(1,1*width/4,0*height/4,width/4,height/4,#820078); //dark violet
Bell[2] = new Bell(2,2*width/4,0*height/4,width/4,height/4,#00FF87); //seafoam
Bell[3] = new Bell(3,3*width/4,0*height/4,width/4,height/4,#000000); //black
Bell[4] = new Bell(4,0*width/4,1*height/4,width/4,height/4,#648D00); //dark lime
Bell[5] = new Bell(5,1*width/4,1*height/4,width/4,height/4,#FF0000); //red
Bell[6] = new Bell(6,2*width/4,1*height/4,width/4,height/4,#00FF00); //green
Bell[7] = new Bell(7,3*width/4,1*height/4,width/4,height/4,#00FFFF); //cyan
Bell[8] = new Bell(8,0*width/4,2*height/4,width/4,height/4,#FF9B00); //orange
Bell[9] = new Bell(9,1*width/4,2*height/4,width/4,height/4,#0000FF); //blue
Bell[10] = new Bell(10,2*width/4,2*height/4,width/4,height/4,#FFF000); //yellow
Bell[11] = new Bell(11,3*width/4,2*height/4,width/4,height/4,#FF00FF); //magenta
Bell[12] = new Bell(12,0*width/4,3*height/4,width/4,height/4,#6100FF); //violet
Bell[13] = new Bell(13,1*width/4,3*height/4,width/4,height/4,#108200); //dark green
Bell[14] = new Bell(14,2*width/4,3*height/4,width/4,height/4,#FF0080); //pink
Bell[15] = new Bell(15,3*width/4,3*height/4,width/4,height/4,#FFFFFF); //white
Sound = new SoundGenerator(this);
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Keyboard
void keyPressed() {
if(key=='q') {
Restart();
}
if(GameStarted==false && DisplayTutorial == false && key==ENTER) {
GameStarted = true;
}
else if(GameStarted==false && DisplayTutorial == false && key=='h') {
DisplayTutorial = true;
}
if(GameStarted==true && DifficultyChosen==true && Defeat == true && key=='r') {
StartPlaying = false;
Score = 0;
Defeat = false;
SequencePosition = 0;
DisplayTutorial = false;
}
if(GameStarted==true && DifficultyChosen==true && key==ENTER) {
StartPlaying = true;
}
if(GameStarted==true && DifficultyChosen==false && key=='1') {
Difficulty=1;
DifficultyChosen=true;
Sequence = new int[3+Difficulty];
}
if(GameStarted==true && DifficultyChosen==false && key=='2') {
Difficulty=2;
DifficultyChosen=true;
Sequence = new int[3+Difficulty];
}
if(GameStarted==true && DifficultyChosen==false && key=='3') {
Difficulty=3;
DifficultyChosen=true;
Sequence = new int[3+Difficulty];
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Mouse
void mousePressed() {
for(int i=0; i<16; i++) {
if(GameStarted==true && DifficultyChosen==true && Bell[i].isMouseOnBell()==true && Bell[i].isDisplayed==true && Defeat == false && StartPlaying == true && SequenceComplete == true) {
if(Bell[i].BellID == Sequence[UserSequencePosition]) {
Bell[i].isLit=true;
Sound.PlayDing(i, Difficulty);
if(UserSequencePosition < Sequence.length) {
UserSequencePosition++;
}
if(UserSequencePosition == Sequence.length) {
UserSequencePosition = 0;
ScoreCount(Difficulty);
}
}
else if(Bell[i].BellID != Sequence[UserSequencePosition]) {
UserSequencePosition = 0;
Bell[i].isLit=true;
Sound.PlayWrongDing();
Defeat = true;
}
}
}
}
void mouseReleased() {
if(isPlayingDing) {
Sound.CheckDingTime();
}
if(isPlayingDing==false) {
for(int i=0; i<16; i++) {
Bell[i].isLit=false;
}
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Functions
int ChooseRandomBell(int Difficulty) {
int RandomBell = -1;
if(Difficulty==1) {
RandomBell = int(random(5,11));
if(RandomBell==7) RandomBell = int(random(5,7));
if(RandomBell==8) RandomBell = int(random(9,11));
}
if(Difficulty==2) {
RandomBell = int(random(4,12));
}
if(Difficulty==3) {
RandomBell = int(random(0,16));
}
return RandomBell;
}
void Sequencer(int Difficulty) {
if(millis() >= timeOut) {
if(SequencePosition != Sequence.length) {
int RandomBell = ChooseRandomBell(Difficulty);
Sequence[SequencePosition] = RandomBell;
SequencePosition++;
Bell[RandomBell].isLit=true;
Sound.PlayDing(RandomBell, Difficulty);
timeOut = millis() + 700/Difficulty + 70/Difficulty;
}
else {SequenceComplete = true;}
}
}
void ScoreCount(int Difficulty) {
Score += (pow(4,Difficulty));
SequencePosition = 0;
if(millis() >= timeOut) {
timeOut = millis() + 1000;
}
SequenceComplete = false;
}
void Restart() {
GameStarted = false;
DifficultyChosen = false;
StartPlaying = false;
Difficulty = 0;
Score = 0;
Defeat = false;
SequencePosition = 0;
DisplayTutorial = false;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Draw()
void draw() {
background(255, 255, 255);
Sound.CheckDingTime();
if(isPlayingDing == false) {
for(int i=0; i<16; i++) {
Bell[i].isLit=false;
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Splash screen
if(GameStarted==false && DisplayTutorial == false) {
fill(0, 0, 0);
textSize(width/80);
text("Wskazówka: Zanim zaczniesz grę zapoznaj się z samouczkiem.\nJeśli nie możesz rozpocząć gry, wyświetlić samouczka lub wyjść z gry, kliknij lewym przyciskiem myszy w dowolne miejsce na ekranie i spróbuj jeszcze raz.", width/2, height/10);
textAlign(CENTER,CENTER);
textSize(width/10);
textAlign(CENTER,CENTER);
fill(255,0,0);
text("D", 5*width/16, 4*height/10);
fill(0,255,0);
text("I", 7*width/16, 4*height/10);
fill(0,0,255);
text("N", 9*width/16, 4*height/10);
fill(255,255,0);
text("G", 11*width/16, 4*height/10);
fill(0, 0, 0);
textSize(width/30);
text("Naciśnij ENTER aby zagrać!", width/2, 6*height/10);
textSize(width/80);
text("Naciśnij H aby wyświetlić samouczek.\nAby wyjść z gry naciśnij przycisk ESC i poczekaj aż gra się zamknie.", width/2, 9*height/10);
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Tutorial
if(GameStarted==false && DisplayTutorial == true) {
fill(0, 0, 0);
textSize(width/50);
text("Gra polega na zapamiętywaniu kolejności,\nw jakiej każdy z dzwoneczków zadzwoni\na następnie odtworzeniu tej samej\nmelodii przyciskając odpowiednie dzwoneczki.\nPoczekaj aż dzwoneczki skończą grać\na następnie odtwórz zagraną melodię.\n\nZa poprawne odtworzenie melodii dostaniesz\nokreśloną ilość punktów zależną od wybranego\npoziomu trudności.\n\nGra kończy się gdy odtworzysz błędną melodię.\n\nPamiętaj: W każdej chwili możesz wrócić do menu głównego przyciskając klawisz 'Q'.", width/2, 7*height/16);
textSize(width/80);
text("Naciśnij Q aby wrócić do menu głównego.", width/2, 9*height/10);
textAlign(CENTER,CENTER);
if(key==ENTER) {
DisplayTutorial = false;
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Choose difficulty
if(GameStarted==true && DifficultyChosen==false) {
fill(0, 0, 0);
textAlign(CENTER,CENTER);
textSize(width/30);
text("Wybierz poziom trudności:\n1.Łatwy\n2.Normalny\n3.Trudny", width/2, height/2);
textSize(width/80);
text("Wskazówka: Naciśnij odpowiedni numer na klawiaturze.", width/2, 9*height/10);
}
if(GameStarted==true && DifficultyChosen==true && Defeat == false) {
fill(0, 0, 0);
textSize(width/90);
textAlign(RIGHT);
text("Punkty: "+Score, 98.5*width/100, 98*height/100);
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Easy difficulty
if(GameStarted==true && DifficultyChosen==true && Difficulty==1) {
if(GameStarted==true && DifficultyChosen==true && Difficulty==1 && StartPlaying == true) {
Sequencer(Difficulty);
Bell[5].Display();
Bell[6].Display();
Bell[9].Display();
Bell[10].Display();
}
else {
Bell[5].Display();
Bell[6].Display();
Bell[9].Display();
Bell[10].Display();
fill(0, 0, 0);
textAlign(CENTER,CENTER);
textSize(width/30);
text("Naciśnij ENTER aby zacząć grę.", width/2, height/2);
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Normal difficulty
if(GameStarted==true && DifficultyChosen==true && Difficulty==2) {
if(GameStarted==true && DifficultyChosen==true && Difficulty==2 && StartPlaying == true) {
Sequencer(Difficulty);
for(int i=4; i<12; i++) {
Bell[i].Display();
}
}
else {
for(int i=4; i<12; i++) {
Bell[i].Display();
}
fill(0, 0, 0);
textAlign(CENTER,CENTER);
textSize(width/30);
text("Naciśnij ENTER aby zacząć grę.", width/2, height/2);
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Hard difficulty
if(GameStarted==true && DifficultyChosen==true && Difficulty==3) {
if(GameStarted==true && DifficultyChosen==true && Difficulty==3 && StartPlaying == true) {
Sequencer(Difficulty);
for(int i=0; i<16; i++) {
Bell[i].Display();
}
}
else {
for(int i=0; i<16; i++) {
Bell[i].Display();
}
fill(0, 0, 0);
textAlign(CENTER,CENTER);
textSize(width/30);
text("Naciśnij ENTER aby zacząć grę.", width/2, height/2);
}
}
}
else if(GameStarted==true && DifficultyChosen==true && Defeat == true) {
textAlign(CENTER,CENTER);
fill(255, 0, 0);
textSize(width/20);
text("Koniec gry :(", width/2, height/2);
fill(0, 0, 0);
textSize(width/60);
text("Liczba zdobytych punktów: "+Score, width/2, 3*height/5);
textSize(width/80);
text("Naciśnij R aby spróbować ponownie.\nNaciśnij Q aby wrócić do menu głównego.", width/2, 9*height/10);
}
}