-
Notifications
You must be signed in to change notification settings - Fork 0
/
characters.js
445 lines (379 loc) · 14 KB
/
characters.js
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
const characterImages = [
"characters_img/rhythme1.png",
"characters_img/rhythme2.png",
"characters_img/rhythme3.png",
"characters_img/rhythme4.png"
];
const shadowImages = [
"shadow_img/shadow1.png",
"shadow_img/shadow2.png",
"shadow_img/shadow3.png",
"shadow_img/shadow4.png",
"shadow_img/shadow5.png"
];
const instructionImages = [
"text_img/pressSorK_text3.png",
"text_img/pressSorK_text4.png"
];
var instructionInterval;
$(document).ready(function() {
// 현재 URL에서 query string을 가져옴
var queryParams = new URLSearchParams(window.location.search);
console.log("character 진입\n"+queryParams.toString());
//이전 페이지에서 모자 미사용여부 정보가 있을때
if(queryParams.has("resetHat")){
var resetHat = JSON.parse(queryParams.get("resetHat")); //resetHat : 모자 미사용여부
console.log("모자 미사용여부: "+ resetHat);
} else {
var resetHat = true;
console.log("모자 미사용여부 파라미터가 없습니다.");
}
//이전 페이지에서 모자 색 정보가 있을때
if(queryParams.has("hatColor")){
var hatColor = queryParams.get("hatColor");
var hatIndex = calIndex(hatColor);
console.log(hatIndex);
console.log("모자 색: "+ hatColor);
} else {
var hatColor = "pink";
var hatIndex = 1;
console.log("모자 색 파라미터가 없습니다.");
}
//이전 페이지에서 옷 미사용여부 정보가 있을때
if(queryParams.has("resetClothes")){
var resetClothes = JSON.parse(queryParams.get("resetClothes")); //resetClothes : 옷 미사용여부
console.log("옷 미사용여부: "+ resetClothes);
} else {
var resetClothes = true;
console.log("옷 미사용여부 파라미터가 없습니다.");
}
//이전 페이지에서 옷 색 정보가 있을때
if(queryParams.has("clothesColor")){
var clothesColor = queryParams.get("clothesColor"); //clothesColor : 옷 색
var clothesIndex = calIndex(clothesColor);
console.log("옷 색: "+ clothesColor);
} else {
var clothesColor = "pink";
var clothesIndex = 1;
console.log("옷 색 파라미터가 없습니다.");
}
var index = 0;
var jumping = false;
var character = $('.rhythme');
var shadow = $('.shadow');
var hat = $('.wearing_hat');
var clothes = $('.wearing_clothes');
var instruction = $('.press');
var currentCharacterIndex = 0;
var currentHatIndex = 0;
var currentClothesIndex = 0;
var currentShadowIndex = 1;
instructionInterval = setInterval(function() {
instruction.attr('src', instructionImages[index]);
index = (index + 1) % instructionImages.length;
}, 500);
init();
//페이지 진입 시작 함수
function init(){
setHatImagesInCharacterBox(hatIndex);
setHatImagesInItemBox(hatIndex);
setClothesImagesInCharacterBox(clothesIndex);
setClothesImagesInItemBox(clothesIndex);
if (resetHat) {
$('#reset_hat img').attr("src", "buttons_img/reset_btn2.png");
} else {
$('#reset_hat img').attr("src", "buttons_img/reset_btn1.png");
}
if (resetClothes) {
$('#reset_clothes img').attr("src", "buttons_img/reset_btn2.png");
} else {
$('#reset_clothes img').attr("src", "buttons_img/reset_btn1.png");
}
}
//color에 대응되는 index 계산하는 함수
function calIndex(color){
switch(color){
case "pink":
return 1;
case "green":
return 2;
case "yellow":
return 3;
case "blue":
return 4;
}
}
//아이템 박스 안에서의 모자 이미지를 설정하는 함수
function setHatImagesInItemBox(hatIndex) {
switch (hatIndex) {
case 1:
$('#hat img').attr("src", "clothes_img/pink_hat1.png");
console.log(currentHatIndex);
hatColor = 'pink';
break;
case 2:
$('#hat img').attr("src", "clothes_img/green_hat1.png");
hatColor = 'green';
break;
case 3:
$('#hat img').attr("src", "clothes_img/yellow_hat1.png");
console.log(currentHatIndex);
hatColor = 'yellow';
break;
case 4:
$('#hat img').attr("src", "clothes_img/blue_hat1.png");
hatColor = 'blue';
break;
default:
break;
}
}
//캐릭터 박스 안에서의 모자 이미지를 설정하는 함수
function setHatImagesInCharacterBox(hatIndex) {
switch (hatIndex) {
case 1:
hat.attr("src", "clothes_img/pink_hat" + (currentHatIndex + 2) + ".png");
console.log(currentHatIndex);
break;
case 2:
hat.attr("src", "clothes_img/green_hat" + (currentHatIndex + 2) + ".png");
break;
case 3:
console.log(currentHatIndex);
hat.attr("src", "clothes_img/yellow_hat" + (currentHatIndex + 2) + ".png");
break;
case 4:
hat.attr("src", "clothes_img/blue_hat" + (currentHatIndex + 2) + ".png");
break;
default:
break;
}
}
//아이템 박스 안에서의 옷 이미지를 설정하는 함수
function setClothesImagesInItemBox(clothesIndex) {
switch (clothesIndex) {
case 1:
$('#clothes img').attr("src", "clothes_img/pink_clothes1.png");
clothesColor = 'pink';
break;
case 2:
$('#clothes img').attr("src", "clothes_img/green_clothes1.png");
clothesColor = 'green';
break;
case 3:
$('#clothes img').attr("src", "clothes_img/yellow_clothes1.png");
clothesColor = 'yellow';
break;
case 4:
$('#clothes img').attr("src", "clothes_img/blue_clothes1.png");
clothesColor = 'blue';
break;
default:
break;
}
}
//캐릭터 박스 안에서의 옷 이미지를 설정하는 함수
function setClothesImagesInCharacterBox(clothesIndex) {
switch (clothesIndex) {
case 1:
clothes.attr("src", "clothes_img/pink_clothes" + (currentClothesIndex + 2) + ".png");
break;
case 2:
clothes.attr("src", "clothes_img/green_clothes" + (currentClothesIndex + 2) + ".png");
break;
case 3:
clothes.attr("src", "clothes_img/yellow_clothes" + (currentClothesIndex + 2) + ".png");
break;
case 4:
clothes.attr("src", "clothes_img/blue_clothes" + (currentClothesIndex + 2) + ".png");
break;
default:
break;
}
}
if(resetHat){
$('.wearing_hat').hide();
}else{
setHatImagesInItemBox(hatIndex);
setHatImagesInCharacterBox(hatIndex);
}
if(resetClothes){
$('.wearing_clothes').hide();
}else {
setClothesImagesInItemBox(clothesIndex);
setClothesImagesInCharacterBox(clothesIndex);
}
$('#reset_hat img').hover(function(){
if(resetHat){
$(this).attr("src", "buttons_img/reset_btn1.png");
}
else{
$(this).attr("src", "buttons_img/reset_btn2.png");
}
$(this).css('width','5vw');
}, function() {
if(resetHat){
$(this).attr("src", "buttons_img/reset_btn2.png");
}
else{
$(this).attr("src", "buttons_img/reset_btn1.png");
}
});
$('#reset_hat').click(()=>{
if(!resetHat){
resetHat = true;
$('.wearing_hat').hide();
} else {
resetHat = false;
$('.wearing_hat').show();
}
});
$('#reset_clothes img').hover(function(){
if(resetClothes){
$(this).attr("src", "buttons_img/reset_btn1.png");
}
else{
$(this).attr("src", "buttons_img/reset_btn2.png");
}
$(this).css('width','5vw');
}, function() {
if(resetClothes){
$(this).attr("src", "buttons_img/reset_btn2.png");
}
else{
$(this).attr("src", "buttons_img/reset_btn1.png");
}
});
$('#reset_clothes').click(()=>{
if(!resetClothes){
resetClothes = true;
console.log(resetHat);
console.log(resetClothes);
$('.wearing_clothes').hide();
} else {
resetClothes = false;
console.log(resetHat);
console.log(resetClothes);
$('.wearing_clothes').show();
}
});
$('#lower_arrow1 img').hover(function(){
$(this).attr("src", "buttons_img/left_arrow_btn2.png");
$(this).css('width','7vw');
}, function() {
$(this).attr("src", "buttons_img/left_arrow_btn1.png");
});
$('#lower_arrow1').click(()=>{
if (hatIndex > 1) {
hatIndex -= 1;
}
setHatImagesInItemBox(hatIndex);
setHatImagesInCharacterBox(hatIndex);
console.log("Current hat: " + hatColor);
});
$('#raise_arrow1 img').hover(function(){
$(this).attr("src", "buttons_img/right_arrow_btn2.png");
$(this).css('width','7vw');
}, function() {
$(this).attr("src", "buttons_img/right_arrow_btn1.png");
});
$('#raise_arrow1').click(()=>{
if (hatIndex < 4) {
hatIndex += 1;
}
setHatImagesInItemBox(hatIndex);
setHatImagesInCharacterBox(hatIndex);
console.log("Current hat: " + hatColor);
});
///////////////////////////////
$('#lower_arrow2 img').hover(function(){
$(this).attr("src", "buttons_img/left_arrow_btn2.png");
$(this).css('width','7vw');
}, function() {
$(this).attr("src", "buttons_img/left_arrow_btn1.png");
});
$('#lower_arrow2').click(()=>{
if (clothesIndex > 1) {
clothesIndex -= 1;
}
setClothesImagesInItemBox(clothesIndex);
setClothesImagesInCharacterBox(clothesIndex);
console.log("Current Difficulty: " + clothesColor);
});
$('#raise_arrow2 img').hover(function(){
$(this).attr("src", "buttons_img/right_arrow_btn2.png");
$(this).css('width','7vw');
}, function() {
$(this).attr("src", "buttons_img/right_arrow_btn1.png");
});
$('#raise_arrow2').click(()=>{
if (clothesIndex < 4) {
clothesIndex += 1;
}
setClothesImagesInItemBox(clothesIndex);
setClothesImagesInCharacterBox(clothesIndex);
console.log("Current Difficulty: " + clothesColor);
});
$('#back img').hover(function(){
$('#back img').hover(function(){
$(this).attr("src", "buttons_img/back_btn1.png");
$(this).css('width','7vw');
}, function() {
$(this).attr("src", "buttons_img/back_btn2.png");
});
$('#back').click(()=>{
queryParams.set("resetHat", resetHat.toString());
queryParams.set("resetClothes", resetClothes.toString());
queryParams.set("hatColor", hatColor);
queryParams.set("clothesColor", clothesColor);
var url = "index.html?" + queryParams.toString();
location.href=url;
});
});
// 게임 시작 및 점프 이벤트 핸들러
document.addEventListener("keydown", function(event) {
if (!jumping && (event.key === 's' || event.key === 'S' || event.key === 'k' || event.key === 'K')) {
JumpAction();
}
});
var imageInterval;
function JumpAction() {
jumping = true;
clearInterval(imageInterval);
character.attr('src', characterImages[0]);
shadow.attr('src', shadowImages[4]);
hat.attr('src',"clothes_img/" + hatColor + "_hat2.png");
clothes.attr('src',"clothes_img/" + clothesColor + "_clothes2.png");
hat.animate({ top: '39.1%' }, 190, 'linear')
.animate({ top: '43.1%' }, 150, 'linear', function() {
hat.attr('src',"clothes_img/" + hatColor + "_hat2.png");
jumping = false;
});
clothes.animate({ top: '38.8%' }, 190, 'linear')
.animate({ top: '42.8%' }, 150, 'linear', function() {
clothes.attr('src',"clothes_img/" + clothesColor + "_clothes2.png");
jumping = false;
});
character.animate({ top: '39%' }, 190, 'linear')
.animate({ top: '43%' }, 150, 'linear', function() {
character.attr('src', characterImages[3]);
shadow.attr('src',shadowImages[0]);
hat.attr('src',"clothes_img/" + hatColor + "_hat5.png");
clothes.attr('src',"clothes_img/" + clothesColor + "_clothes5.png");
jumping = false;
imageInterval = setInterval(function() {
currentClothesIndex = (currentClothesIndex + 1) % 4;
clothes.attr('src',"clothes_img/" + clothesColor + "_clothes" + (currentClothesIndex + 2) + ".png");
currentHatIndex = (currentHatIndex + 1) % 4;
hat.attr('src',"clothes_img/" + hatColor + "_hat" + (currentHatIndex + 2) + ".png");
currentCharacterIndex = (currentCharacterIndex + 1) % characterImages.length;
currentShadowIndex = (currentShadowIndex + 1) % (shadowImages.length-1);
character.attr('src', characterImages[currentCharacterIndex]);
shadow.attr('src',shadowImages[currentShadowIndex]);
}, 100);
});
}
setTimeout(() => {
JumpAction();
},100);
});