-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_old.js
More file actions
4919 lines (4383 loc) · 186 KB
/
game_old.js
File metadata and controls
4919 lines (4383 loc) · 186 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
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
// 반응형 캔버스: 논리 해상도는 500×700 고정, CSS 스케일로 대응
const CANVAS_LOGICAL_W = 500;
const CANVAS_LOGICAL_H = 700;
canvas.width = CANVAS_LOGICAL_W;
canvas.height = CANVAS_LOGICAL_H;
function resizeCanvas() {
const container = document.getElementById('game-container');
if (!container) return;
const vpW = window.innerWidth;
const vpH = window.innerHeight;
// 게임 캔버스 비율 유지하며 최대 크기
const scaleX = vpW / CANVAS_LOGICAL_W;
const scaleY = vpH / CANVAS_LOGICAL_H;
const scale = Math.min(scaleX, scaleY, 1.4); // 최대 1.4배
canvas.style.width = Math.floor(CANVAS_LOGICAL_W * scale) + 'px';
canvas.style.height = Math.floor(CANVAS_LOGICAL_H * scale) + 'px';
// postprocess 캔버스도 동일하게
const ppCanvas = document.getElementById('postProcessCanvas');
if (ppCanvas) {
ppCanvas.style.width = canvas.style.width;
ppCanvas.style.height = canvas.style.height;
}
}
window.addEventListener('resize', resizeCanvas);
// 첫 리사이즈는 게임 컨테이너가 표시될 때
document.addEventListener('DOMContentLoaded', () => {
const observer = new MutationObserver(() => {
const gc = document.getElementById('game-container');
if (gc && gc.style.display !== 'none') resizeCanvas();
});
observer.observe(document.body, { attributes: true, subtree: true, attributeFilter: ['style'] });
});
// 선택된 캐릭터
let selectedCharacter = 'human';
let gameStarted = false;
// 게임 모드 설정
let gameMode = 'normal'; // 'normal' 또는 'bet'
let maxJumps = 10;
let currentJumps = 0;
let gameEnded = false;
// 게임 상수
const GRAVITY = 0.5;
const MAX_JUMP_POWER = 18;
const CHARGE_SPEED = 0.4;
const HORIZONTAL_SPEED = 5;
const BLOCK_WIDTH = 80;
const BLOCK_HEIGHT = 20;
const FLOOR_HEIGHT = 30;
// 향상된 물리 시스템
const COYOTE_TIME = 8; // 플랫폼 이탈 후 점프 가능한 프레임 수
const JUMP_BUFFER_TIME = 10; // 점프 버퍼링 프레임 수
const AIR_FRICTION = 0.985; // 공중 마찰 (기존 0.99에서 감소)
const GROUND_FRICTION = 0.85; // 지면 마찰 (슬라이딩 효과)
const AIR_CONTROL = 0.6; // 공중 제어력 (기존 0.8에서 감소)
const VARIABLE_JUMP_MULTIPLIER = 0.5; // 짧은 점프용 중력 배수
// 월드 좌표계 기준점 (바닥 y 좌표)
const WORLD_FLOOR_Y = 1000;
// 플레이어 설정 (월드 좌표계 사용)
const player = {
x: canvas.width / 2 - 15,
y: WORLD_FLOOR_Y - 40, // 월드 좌표
width: 30,
height: 40,
velocityX: 0,
velocityY: 0,
isOnGround: true,
isCharging: false,
jumpPower: 0,
direction: 0, // -1: 왼쪽, 0: 없음, 1: 오른쪽
facingRight: true,
currentBlock: null, // 현재 서 있는 블록 추적
// Physics animation properties
squashStretch: 1.0, // 1.0 = normal, <1 = squash, >1 = stretch
animTimer: 0,
breathePhase: 0,
landingImpact: 0, // 0 to 1, decays over time
trailParticles: [], // motion trail
blinkTimer: 0,
isBlinking: false,
blinkDuration: 0,
coyoteTimer: 0,
jumpBufferTimer: 0,
wasOnGround: false,
walkCycle: 0,
isMoving: false,
lastGroundY: WORLD_FLOOR_Y - 40
};
// 카메라 오프셋 (스크롤용)
let cameraY = 0;
let maxHeight = 0;
// Scanline cache for performance optimization
let scanlineCache = null;
function createScanlineCache() {
const scanlineCanvas = document.createElement('canvas');
scanlineCanvas.width = canvas.width;
scanlineCanvas.height = canvas.height;
const scanlineCtx = scanlineCanvas.getContext('2d');
// Pre-render scanlines to offscreen canvas
scanlineCtx.strokeStyle = 'rgba(0, 0, 0, 0.03)';
scanlineCtx.lineWidth = 1;
for (let i = 0; i < canvas.height; i += 4) {
scanlineCtx.beginPath();
scanlineCtx.moveTo(0, i);
scanlineCtx.lineTo(canvas.width, i);
scanlineCtx.stroke();
}
return scanlineCanvas;
}
scanlineCache = createScanlineCache();
// 체크포인트 시스템
let lastCheckpointHeight = 0;
let checkpointFlashTimer = 0;
const CHECKPOINT_HEIGHTS = [100, 200, 300, 400, 500];
// ===== AUDIO SYSTEM =====
let audioCtx = null;
let bgmGainNode = null;
let currentZoneMusic = null;
let lastMusicZone = -1;
let audioInitialized = false;
function initAudio() {
if (audioInitialized) return;
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
bgmGainNode = audioCtx.createGain();
bgmGainNode.gain.value = 0.08;
bgmGainNode.connect(audioCtx.destination);
audioInitialized = true;
}
function playSFX(type) {
if (!audioCtx) return;
const now = audioCtx.currentTime;
switch(type) {
case 'jump_charge':
const chargeOsc = audioCtx.createOscillator();
const chargeGain = audioCtx.createGain();
chargeOsc.connect(chargeGain);
chargeGain.connect(audioCtx.destination);
chargeOsc.frequency.setValueAtTime(200, now);
chargeOsc.frequency.exponentialRampToValueAtTime(400, now + 0.3);
chargeGain.gain.setValueAtTime(0.1, now);
chargeGain.gain.exponentialRampToValueAtTime(0.01, now + 0.3);
chargeOsc.start(now);
chargeOsc.stop(now + 0.3);
break;
case 'jump_release':
const jumpOsc = audioCtx.createOscillator();
const jumpGain = audioCtx.createGain();
jumpOsc.connect(jumpGain);
jumpGain.connect(audioCtx.destination);
jumpOsc.frequency.setValueAtTime(600, now);
jumpOsc.frequency.exponentialRampToValueAtTime(300, now + 0.15);
jumpGain.gain.setValueAtTime(0.15, now);
jumpGain.gain.exponentialRampToValueAtTime(0.001, now + 0.15);
jumpOsc.start(now);
jumpOsc.stop(now + 0.15);
break;
case 'landing':
const landOsc = audioCtx.createOscillator();
const landFilter = audioCtx.createBiquadFilter();
const landGain = audioCtx.createGain();
landOsc.connect(landFilter);
landFilter.connect(landGain);
landGain.connect(audioCtx.destination);
landFilter.type = 'lowpass';
landFilter.frequency.value = 200;
landOsc.frequency.setValueAtTime(150, now);
landGain.gain.setValueAtTime(0.2, now);
landGain.gain.exponentialRampToValueAtTime(0.001, now + 0.1);
landOsc.start(now);
landOsc.stop(now + 0.1);
break;
case 'footstep':
// Short low-frequency tap with slight variation
const footOsc = audioCtx.createOscillator();
const footGain = audioCtx.createGain();
footOsc.connect(footGain);
footGain.connect(audioCtx.destination);
footOsc.frequency.setValueAtTime(100 + Math.random() * 20, now);
footGain.gain.setValueAtTime(0.08, now);
footGain.gain.exponentialRampToValueAtTime(0.001, now + 0.05);
footOsc.start(now);
footOsc.stop(now + 0.05);
break;
case 'rain':
// Random high-frequency ticks for rain
const rainOsc = audioCtx.createOscillator();
const rainFilter = audioCtx.createBiquadFilter();
const rainGain = audioCtx.createGain();
rainOsc.connect(rainFilter);
rainFilter.connect(rainGain);
rainGain.connect(audioCtx.destination);
rainFilter.type = 'highpass';
rainFilter.frequency.value = 3000 + Math.random() * 2000;
rainOsc.frequency.setValueAtTime(5000 + Math.random() * 3000, now);
rainGain.gain.setValueAtTime(0.05, now);
rainGain.gain.exponentialRampToValueAtTime(0.001, now + 0.08);
rainOsc.start(now);
rainOsc.stop(now + 0.08);
break;
case 'crumble':
// Low rumbling for crumbling blocks
const crumbleOsc = audioCtx.createOscillator();
const crumbleGain = audioCtx.createGain();
crumbleOsc.connect(crumbleGain);
crumbleGain.connect(audioCtx.destination);
crumbleOsc.frequency.setValueAtTime(80, now);
crumbleOsc.frequency.exponentialRampToValueAtTime(30, now + 0.2);
crumbleGain.gain.setValueAtTime(0.12, now);
crumbleGain.gain.exponentialRampToValueAtTime(0.001, now + 0.2);
crumbleOsc.start(now);
crumbleOsc.stop(now + 0.2);
break;
case 'bounce_block':
// Springy boing sound
const bounceOsc1 = audioCtx.createOscillator();
const bounceOsc2 = audioCtx.createOscillator();
const bounceMerge = audioCtx.createGain();
const bounceGain = audioCtx.createGain();
bounceOsc1.type = 'sine';
bounceOsc2.type = 'sine';
bounceOsc1.frequency.setValueAtTime(300, now);
bounceOsc1.frequency.exponentialRampToValueAtTime(900, now + 0.08);
bounceOsc2.frequency.setValueAtTime(200, now);
bounceOsc2.frequency.exponentialRampToValueAtTime(600, now + 0.08);
bounceOsc1.connect(bounceMerge);
bounceOsc2.connect(bounceMerge);
bounceMerge.connect(bounceGain);
bounceGain.connect(audioCtx.destination);
bounceGain.gain.setValueAtTime(0.18, now);
bounceGain.gain.exponentialRampToValueAtTime(0.001, now + 0.25);
bounceOsc1.start(now); bounceOsc1.stop(now + 0.25);
bounceOsc2.start(now); bounceOsc2.stop(now + 0.25);
break;
case 'ice_slide':
// Icy swish sound
const iceOsc = audioCtx.createOscillator();
const iceFilter = audioCtx.createBiquadFilter();
const iceGain = audioCtx.createGain();
iceOsc.type = 'sine';
iceOsc.frequency.setValueAtTime(1200, now);
iceOsc.frequency.linearRampToValueAtTime(800, now + 0.15);
iceFilter.type = 'highpass';
iceFilter.frequency.value = 600;
iceOsc.connect(iceFilter);
iceFilter.connect(iceGain);
iceGain.connect(audioCtx.destination);
iceGain.gain.setValueAtTime(0.06, now);
iceGain.gain.exponentialRampToValueAtTime(0.001, now + 0.15);
iceOsc.start(now); iceOsc.stop(now + 0.15);
break;
case 'ember':
// Crackling fire-like sound
const emberOsc = audioCtx.createOscillator();
const emberGain = audioCtx.createGain();
emberOsc.connect(emberGain);
emberGain.connect(audioCtx.destination);
emberOsc.frequency.setValueAtTime(200 + Math.random() * 300, now);
emberGain.gain.setValueAtTime(0.06, now);
emberGain.gain.exponentialRampToValueAtTime(0.001, now + 0.15);
emberOsc.start(now);
emberOsc.stop(now + 0.15);
break;
case 'heartbeat':
// Low rhythmic thump for horror zones
const beatOsc = audioCtx.createOscillator();
const beatGain = audioCtx.createGain();
beatOsc.connect(beatGain);
beatGain.connect(audioCtx.destination);
beatOsc.frequency.setValueAtTime(60, now);
beatGain.gain.setValueAtTime(0.15, now);
beatGain.gain.exponentialRampToValueAtTime(0.001, now + 0.12);
beatOsc.start(now);
beatOsc.stop(now + 0.12);
break;
case 'wind_rush':
const windOsc = audioCtx.createOscillator();
const windFilter = audioCtx.createBiquadFilter();
const windGain = audioCtx.createGain();
windOsc.type = 'sawtooth';
windOsc.frequency.value = 100 + Math.random() * 50;
windFilter.type = 'bandpass';
windFilter.frequency.value = 800;
windFilter.Q.value = 0.5;
windOsc.connect(windFilter);
windFilter.connect(windGain);
windGain.connect(audioCtx.destination);
windGain.gain.setValueAtTime(0.05, now);
windGain.gain.exponentialRampToValueAtTime(0.001, now + 0.3);
windOsc.start(now);
windOsc.stop(now + 0.3);
break;
case 'story_appear':
// Mysterious chime for story milestones
const storyOsc1 = audioCtx.createOscillator();
const storyOsc2 = audioCtx.createOscillator();
const storyGain = audioCtx.createGain();
const storyFilter = audioCtx.createBiquadFilter();
storyOsc1.type = 'sine';
storyOsc2.type = 'sine';
storyFilter.type = 'lowpass';
storyFilter.frequency.value = 2000;
storyOsc1.connect(storyFilter);
storyOsc2.connect(storyFilter);
storyFilter.connect(storyGain);
storyGain.connect(audioCtx.destination);
storyOsc1.frequency.setValueAtTime(523.25, now); // C5
storyOsc1.frequency.exponentialRampToValueAtTime(783.99, now + 0.3); // G5
storyOsc2.frequency.setValueAtTime(659.25, now + 0.1); // E5
storyOsc2.frequency.exponentialRampToValueAtTime(1046.5, now + 0.4); // C6
storyGain.gain.setValueAtTime(0, now);
storyGain.gain.linearRampToValueAtTime(0.12, now + 0.05);
storyGain.gain.exponentialRampToValueAtTime(0.001, now + 0.6);
storyOsc1.start(now);
storyOsc1.stop(now + 0.5);
storyOsc2.start(now + 0.1);
storyOsc2.stop(now + 0.6);
break;
case 'danger_ambient':
// Deep rumbling for dangerous zones
const dangerOsc = audioCtx.createOscillator();
const dangerOsc2 = audioCtx.createOscillator();
const dangerGain = audioCtx.createGain();
dangerOsc.type = 'sawtooth';
dangerOsc2.type = 'sine';
dangerOsc.frequency.setValueAtTime(40, now);
dangerOsc.frequency.exponentialRampToValueAtTime(30, now + 0.5);
dangerOsc2.frequency.setValueAtTime(55, now);
dangerOsc.connect(dangerGain);
dangerOsc2.connect(dangerGain);
dangerGain.connect(audioCtx.destination);
dangerGain.gain.setValueAtTime(0.08, now);
dangerGain.gain.exponentialRampToValueAtTime(0.001, now + 0.5);
dangerOsc.start(now);
dangerOsc.stop(now + 0.5);
dangerOsc2.start(now);
dangerOsc2.stop(now + 0.5);
break;
case 'achievement':
// Triumphant arpeggio for major milestones
const notes = [523.25, 659.25, 783.99, 1046.5]; // C5, E5, G5, C6
notes.forEach((freq, idx) => {
const achOsc = audioCtx.createOscillator();
const achGain = audioCtx.createGain();
achOsc.type = 'sine';
achOsc.frequency.value = freq;
achOsc.connect(achGain);
achGain.connect(audioCtx.destination);
const startTime = now + idx * 0.08;
achGain.gain.setValueAtTime(0, startTime);
achGain.gain.linearRampToValueAtTime(0.1, startTime + 0.02);
achGain.gain.exponentialRampToValueAtTime(0.001, startTime + 0.4);
achOsc.start(startTime);
achOsc.stop(startTime + 0.4);
});
break;
case 'charge_loop':
// Rising tone while charging jump
const clOsc = audioCtx.createOscillator();
const clGain = audioCtx.createGain();
const clFilter = audioCtx.createBiquadFilter();
clOsc.type = 'triangle';
clFilter.type = 'lowpass';
clFilter.frequency.value = 500;
clOsc.connect(clFilter);
clFilter.connect(clGain);
clGain.connect(audioCtx.destination);
clOsc.frequency.setValueAtTime(100, now);
clOsc.frequency.linearRampToValueAtTime(600, now + 1.5);
clGain.gain.setValueAtTime(0.06, now);
clGain.gain.exponentialRampToValueAtTime(0.001, now + 0.2);
clOsc.start(now);
clOsc.stop(now + 0.2);
break;
}
}
// 존 기반 환경음 시스템
let lastAmbientTime = 0;
function updateAmbientSounds() {
if (!audioCtx) return;
const now = Date.now();
if (now - lastAmbientTime < 3000) return; // 3초마다
lastAmbientTime = now;
const zone = getCurrentZone();
// 존별 환경음
if (zone >= 4 && zone <= 7 && Math.random() < 0.3) {
playSFX('danger_ambient');
}
if (zone >= 2 && zone <= 5 && Math.random() < 0.2) {
playSFX('rain');
}
if (zone >= 6 && Math.random() < 0.25) {
playSFX('heartbeat');
}
}
function updateBGM() {
if (!audioCtx) return;
const zone = getCurrentZone();
if (zone === lastMusicZone) return;
lastMusicZone = zone;
// Stop existing oscillators gracefully
if (currentZoneMusic) {
currentZoneMusic.forEach(osc => {
try { osc.stop(); } catch(e) {}
});
}
currentZoneMusic = [];
const now = audioCtx.currentTime;
if (zone <= 1) {
// Calm ambient - C minor
const notes = [130.81, 155.56, 196]; // C3, Eb3, G3
notes.forEach(freq => {
const osc = audioCtx.createOscillator();
const gain = audioCtx.createGain();
osc.type = 'sine';
osc.frequency.value = freq;
osc.connect(gain);
gain.connect(bgmGainNode);
gain.gain.setValueAtTime(0.05, now);
osc.start(now);
currentZoneMusic.push(osc);
});
} else if (zone <= 3) {
// Unsettling - dissonant
const notes = [110, 130.81, 148]; // A2, C3, D3
notes.forEach((freq, idx) => {
const osc = audioCtx.createOscillator();
const gain = audioCtx.createGain();
osc.type = 'triangle';
osc.frequency.value = freq;
osc.connect(gain);
gain.connect(bgmGainNode);
gain.gain.setValueAtTime(0.03, now);
osc.start(now);
currentZoneMusic.push(osc);
});
} else if (zone <= 5) {
// Tense - deep bass drone
const osc = audioCtx.createOscillator();
const gain = audioCtx.createGain();
osc.type = 'sine';
osc.frequency.value = 55; // A1
osc.connect(gain);
gain.connect(bgmGainNode);
gain.gain.setValueAtTime(0.04, now);
osc.start(now);
currentZoneMusic.push(osc);
// High whisper
const whisper = audioCtx.createOscillator();
const whisperGain = audioCtx.createGain();
whisper.type = 'sawtooth';
whisper.frequency.value = 880;
whisper.connect(whisperGain);
whisperGain.connect(bgmGainNode);
whisperGain.gain.setValueAtTime(0.01, now);
whisper.start(now);
currentZoneMusic.push(whisper);
} else if (zone <= 7) {
// Horror - very low rumble
const osc = audioCtx.createOscillator();
const gain = audioCtx.createGain();
osc.type = 'sine';
osc.frequency.value = 27.5; // A0
osc.connect(gain);
gain.connect(bgmGainNode);
gain.gain.setValueAtTime(0.05, now);
osc.start(now);
currentZoneMusic.push(osc);
} else if (zone === 8) {
// Surreal - otherworldly chords
const notes = [261.63, 277.18, 329.63]; // C4, C#4, E4
notes.forEach(freq => {
const osc = audioCtx.createOscillator();
const gain = audioCtx.createGain();
osc.type = 'sine';
osc.frequency.value = freq * 0.5;
osc.connect(gain);
gain.connect(bgmGainNode);
gain.gain.setValueAtTime(0.04, now);
osc.start(now);
currentZoneMusic.push(osc);
});
} else {
// Hopeful - C major
const notes = [261.63, 329.63, 392]; // C4, E4, G4
notes.forEach(freq => {
const osc = audioCtx.createOscillator();
const gain = audioCtx.createGain();
osc.type = 'sine';
osc.frequency.value = freq;
osc.connect(gain);
gain.connect(bgmGainNode);
gain.gain.setValueAtTime(0.06, now);
osc.start(now);
currentZoneMusic.push(osc);
});
}
}
// ===== SYSTEM 2: PHYSICS ANIMATIONS =====
function updatePhysicsAnimation() {
// Update breathing phase when idle
if (player.isOnGround && !player.isCharging) {
player.breathePhase += 0.03;
player.squashStretch = 1.0 + Math.sin(player.breathePhase) * 0.02; // Subtle breathing
}
// Squash on landing
if (player.isOnGround && player.landingImpact > 0) {
player.squashStretch = 0.8 + (player.landingImpact * 0.2); // Squash effect
player.landingImpact = Math.max(0, player.landingImpact - 0.05);
}
// Stretch while jumping
if (!player.isOnGround && player.velocityY < 0) {
player.squashStretch = 1.0 + (Math.abs(player.velocityY) / MAX_JUMP_POWER) * 0.25; // Stretch
} else if (!player.isOnGround) {
player.squashStretch = Math.max(0.95, player.squashStretch - 0.02); // Return to normal
}
// Add motion trail particles
if (!player.isOnGround && (Math.abs(player.velocityX) > 2 || Math.abs(player.velocityY) > 2)) {
player.trailParticles.push({
x: player.x + player.width / 2,
y: player.y + player.height / 2,
life: 1,
maxLife: 0.6
});
}
// Update trail particles
for (let i = player.trailParticles.length - 1; i >= 0; i--) {
player.trailParticles[i].life -= 0.1;
if (player.trailParticles[i].life <= 0) {
player.trailParticles.splice(i, 1);
}
}
// Keep squashStretch within bounds
player.squashStretch = Math.max(0.7, Math.min(1.3, player.squashStretch));
// Eye blinking
player.blinkTimer++;
if (!player.isBlinking && player.blinkTimer > 120 + Math.random() * 180) {
player.isBlinking = true;
player.blinkDuration = 0;
player.blinkTimer = 0;
}
if (player.isBlinking) {
player.blinkDuration++;
if (player.blinkDuration > 8) {
player.isBlinking = false;
}
}
}
function drawMotionTrail() {
for (const particle of player.trailParticles) {
const alpha = (particle.life / particle.maxLife) * 0.3;
ctx.globalAlpha = alpha;
// Draw a faded copy of the player
const size = 2;
const trailY = particle.y + cameraY;
// Simple trail visualization
ctx.fillStyle = '#3a5858';
ctx.fillRect(particle.x - 3, trailY - 5, 6, 10);
}
ctx.globalAlpha = 1;
}
// ===== SYSTEM 3: DYNAMIC LIGHTING =====
let lightSources = [];
function updateLighting() {
lightSources = [];
const zone = getCurrentZone();
// Player light - changes with zone
let playerLightColor = '#3a6868'; // Default muted teal
if (zone <= 1) playerLightColor = '#3a6868';
else if (zone <= 3) playerLightColor = '#7a6a3a';
else if (zone <= 7) playerLightColor = '#6a3030';
else if (zone === 8) playerLightColor = '#7a6a4a';
else playerLightColor = '#4a6a4a';
lightSources.push({
x: player.x + player.width / 2,
y: player.y + cameraY + player.height / 2,
radius: 80 + player.jumpPower * 2,
color: playerLightColor,
intensity: 0.6
});
// Moving block lights — 화면 안의 블록만 처리
const sinVal = Math.sin(Date.now() * 0.005);
for (const block of blocks) {
if (block.type !== 'moving' || block.disappeared) continue;
const blockScreenY = block.y + cameraY;
// 화면 밖 블록은 스킵 (성능 최적화)
if (blockScreenY < -100 || blockScreenY > canvas.height + 100) continue;
lightSources.push({
x: block.x + block.moveOffset + block.width / 2,
y: blockScreenY + block.height / 2,
radius: 40 + sinVal * 10,
color: '#7a6a3a',
intensity: 0.3
});
}
// Zone-specific lights
if (zone === 8) {
// Floating dim amber orbs
for (let i = 0; i < 3; i++) {
lightSources.push({
x: (Math.sin(Date.now() * 0.0005 + i) * 100 + canvas.width / 2),
y: (Math.cos(Date.now() * 0.0005 + i) * 100 + canvas.height / 2),
radius: 60,
color: '#6a5a3a',
intensity: 0.25
});
}
}
}
function drawLighting() {
const zone = getCurrentZone();
// Dark overlay based on zone darkness
let overlayOpacity = 0;
if (zone <= 1) overlayOpacity = 0;
else if (zone <= 3) overlayOpacity = 0.2;
else if (zone <= 5) overlayOpacity = 0.4;
else if (zone <= 7) overlayOpacity = 0.6;
else if (zone === 8) overlayOpacity = 0.3;
else overlayOpacity = 0;
// Draw dark overlay
if (overlayOpacity > 0) {
ctx.fillStyle = `rgba(0, 0, 0, ${overlayOpacity})`;
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
// Draw light sources
ctx.globalCompositeOperation = 'lighten';
for (const light of lightSources) {
const gradient = ctx.createRadialGradient(light.x, light.y, 0, light.x, light.y, light.radius);
// Parse color for gradient
const rgb = light.color.substring(1);
const r = parseInt(rgb.substring(0, 2), 16);
const g = parseInt(rgb.substring(2, 4), 16);
const b = parseInt(rgb.substring(4, 6), 16);
gradient.addColorStop(0, `rgba(${r}, ${g}, ${b}, ${light.intensity})`);
gradient.addColorStop(1, `rgba(${r}, ${g}, ${b}, 0)`);
ctx.fillStyle = gradient;
ctx.fillRect(light.x - light.radius, light.y - light.radius, light.radius * 2, light.radius * 2);
}
ctx.globalCompositeOperation = 'source-over';
}
// ===== EXPANDED STORY SYSTEM =====
const storyMilestones = {
// === Zone 0: Entry (0-50m) - 버려진 도시의 지하 시설 ===
0: "여긴... 버려진 타워의 입구야. 아이를 찾으려면 올라가야 해.",
10: "비상등이 깜빡인다. 이 시설은... 오래전에 폐쇄된 것 같다.",
25: "바닥에 먼지가 두껍게 쌓여있다. 하지만 작은 발자국이... 최근 것이다.",
40: "벽에 긁힌 자국. '출구는 위에'라고 적혀 있다.",
// === Zone 1: Unease (50-100m) - 불안감의 시작 ===
50: "벽에 누군가의 메시지가 있다... '올라가지 마라. 위에는 아무것도 없다.'",
60: "환기구에서 차가운 바람이 불어온다. 뭔가... 살아있는 것 같다.",
75: "깨진 유리 파편 사이에서 아이의 운동화 한 짝을 발견했다.",
90: "보안 카메라가 아직 작동하고 있다. 누군가 지켜보고 있는 걸까?",
// === Zone 2: Deeper (100-150m) - 과거 연구시설의 흔적 ===
100: "점점 어두워진다. 하지만 아이의 인형이 여기 있었어... 맞는 방향이야.",
110: "실험실 문이 열려있다. 안에는 깨진 시험관과... 이상한 액체가.",
125: "벽에 붙은 연구 보고서. '프로젝트 바벨탑 - 3단계 승인'이라고 적혀있다.",
140: "여기서 무슨 실험을 했던 거지? 벽의 스크래치 자국이 사람 것이 아니다.",
// === Zone 3: Rust (150-200m) - 공포의 시작 ===
150: "다른 생존자의 흔적... 이미 오래전 일이다. 마른 핏자국이 보인다.",
165: "라디오에서 잡음이 들린다. 가끔... 아이의 목소리 같은 것이 섞여있다.",
180: "여기 일기장이 있다. '7일째, 위에서 내려오는 소리가 점점 커진다...'",
195: "복도가 갈라진다. 한쪽에는 '돌아가라'는 경고문. 다른 쪽에는 아이의 그림.",
// === Zone 4: Danger (200-250m) - 위험 구역 ===
200: "이상한 소리가 들린다. 위에서... 뭔가가 움직이고 있어.",
215: "비상 방송 시스템이 갑자기 켜졌다. '모든 인원은 즉시 대피하십시오.'",
230: "깨진 창문 너머로 도시가 보인다. 불빛이 하나도 없다... 모두 떠난 건가?",
245: "누군가 남긴 무전기. '...아이들이... 꼭대기에서... 빛을...' 잡음에 끊긴다.",
// === Zone 5: Deep Danger (250-300m) - 진실에 가까워짐 ===
250: "아이가 쓴 편지를 찾았다. '아빠, 무서워요. 위에서 기다릴게요.'",
265: "벽에 손톱자국이... 누군가 필사적으로 올라갔다.",
280: "연구원의 마지막 기록. '바벨탑 프로젝트의 본질을 이해했다. 이것은 실험이 아니라...'",
295: "공기가 차갑다. 숨을 쉴 때마다 하얀 김이 나온다.",
// === Zone 6: Core (300-400m) - 핵심 구역, 진실이 드러남 ===
300: "공기가 차갑다. 벽에 손톱자국이... 누군가 필사적으로 올라갔다.",
320: "이곳의 구조가 바뀌기 시작했다. 계단이 있어야 할 곳에 벽이, 벽이 있어야 할 곳에 공허가.",
340: "또 다른 일기장. '바벨탑은 물리적 구조물이 아니다. 이것은 의지의 시험이다.'",
360: "거울이 있다. 내 모습이... 이상하다. 피로한 것 이상의 무언가.",
380: "아이의 목소리가 들린다. 점점 선명해진다. '아빠, 거의 다 왔어요!'",
// === Zone 7: Abyss (400-500m) - 심연, 정신적 한계 ===
400: "시야가 흐려진다. 현실인지 환상인지... 아이의 목소리가 들리는 것 같다.",
420: "벽이 숨을 쉬고 있다. 아니... 내가 숨을 쉬는 것에 맞춰 벽이 움직이는 것인가?",
440: "과거의 기억이 스쳐 지나간다. 아이와 함께 공원에서 놀던 날...",
460: "다리가 떨린다. 하지만 포기할 수 없어. 아이가 기다리고 있으니까.",
480: "어둠 속에서 빛이 보인다. 환상인가... 아닌가.",
// === Zone 8: Anomaly (500-600m) - 초자연적 공간 ===
500: "거의 다 왔어... 빛이 보인다. 아이가... 거기 있는 거야?",
520: "공간이 뒤틀린다. 위와 아래의 구분이 사라지고 있다.",
540: "떠다니는 기억의 파편들. 아이의 웃음소리, 첫 걸음마, 생일 파티...",
560: "이 탑은... 올라가는 사람의 의지를 시험하는 것이었구나.",
580: "마지막 문이 보인다. 그 너머에서 따뜻한 빛이 새어 나온다.",
// === Zone 9: Surface (600m+) - 구원, 엔딩 ===
600: "정상에 도달했다. 아이는... 여기 있었구나. 이제 괜찮아.",
620: "햇빛이 눈부시다. 이 탑 위에서 바라본 세상은... 아직 아름답다.",
650: "아이가 웃고 있다. '아빠가 올 줄 알았어요.' 이 한마디에 모든 고통이 사라진다.",
700: "함께 내려가자. 이제 더 이상 무섭지 않아. 아빠가 여기 있으니까."
};
// 캐릭터별 추가 대사 시스템
const characterDialogues = {
human: {
50: "(주머니에서 아이의 사진을 꺼내본다...)",
200: "군인 시절의 훈련이 도움이 되고 있어. 하지만 이건 전쟁이 아니야.",
400: "다리가 후들거린다... 하지만 아빠니까. 아빠는 포기하면 안 돼.",
600: "(눈물을 참으며) 드디어... 찾았다."
},
skeleton: {
50: "...뼈만 남은 몸이지만, 기억은 아직 선명하다.",
200: "살아있을 때 하지 못한 일... 이제라도 해야지.",
400: "이 몸이 부서질 때까지... 올라간다.",
600: "...이 따뜻함은 뭐지? 잊고 있었던 감정이다."
},
dog: {
50: "(코를 킁킁거리며 아이의 냄새를 추적한다)",
200: "(불안하게 꼬리를 내린다. 하지만 냄새는 확실히 위에서 온다.)",
400: "(지치지만 충성스러운 눈빛으로 위를 바라본다)",
600: "(꼬리를 미친 듯이 흔들며 아이에게 달려간다!)"
},
cat: {
50: "(귀를 쫑긋 세우고 위를 향해 조용히 걷는다)",
200: "(어둠 속에서도 눈이 빛난다. 고양이의 야간 시력이 도움이 된다.)",
400: "(지쳐서 잠시 웅크린다... 하지만 이내 다시 일어선다.)",
600: "(조용히 아이 옆에 앉아 그르렁거린다)"
}
};
// 환경 스토리텔링 - 블록에 표시되는 시각적 단서
const environmentalClues = {
30: { type: 'footprint', desc: '작은 발자국' },
80: { type: 'toy', desc: '떨어진 인형 팔' },
130: { type: 'note', desc: '찢어진 메모' },
220: { type: 'photo', desc: '깨진 가족 사진' },
350: { type: 'drawing', desc: '아이의 크레용 그림' },
480: { type: 'light', desc: '희미한 빛' },
550: { type: 'warmth', desc: '따뜻한 공기' }
};
let shownStories = new Set();
// ===== FEATURE 2: HORROR ATMOSPHERE SYSTEM =====
let fogParticles = [];
let screenShakeIntensity = 0;
let glitchTimer = 0;
let heartbeatTime = 0;
// ===== 아이템/파워업 시스템 =====
// 아이템 오브젝트 배열 (월드에 떠 있는 아이템)
let items = [];
// 플레이어 파워업 상태
const powerups = {
doubleJump: { active: false, timer: 0, hasExtraJump: false }, // 이중 점프 (1회용 공중 점프 추가)
speedBoost: { active: false, timer: 0 }, // 속도 부스트 (수평속도 1.6배)
shield: { active: false, timer: 0, flicker: 0 }, // 실드 (추락 1회 방지)
slowMotion: { active: false, timer: 0 } // 슬로우 모션 (중력/속도 절반)
};
// 아이템 정의
const ITEM_TYPES = [
{ type: 'doubleJump', color: '#ffdd00', glyph: '2x', duration: 0 }, // 즉시 발동
{ type: 'speedBoost', color: '#ff6600', glyph: '▶▶', duration: 420 }, // 7초
{ type: 'shield', color: '#4488ff', glyph: '🛡', duration: 0 }, // 1회 사용
{ type: 'slowMotion', color: '#cc44ff', glyph: '⏳', duration: 300 } // 5초
];
// 포그 파티클 초기화
function initializeFogParticles() {
fogParticles = [];
const particleCount = Math.floor(maxHeight / 50);
for (let i = 0; i < particleCount; i++) {
fogParticles.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
opacity: Math.random() * 0.3 + 0.1,
speed: Math.random() * 0.3 + 0.1
});
}
}
// ===== SYSTEM 1: ENVIRONMENT PARTICLE SYSTEM =====
let envParticles = [];
let windStrength = 0;
let windDirection = 1;
// ===== FEATURE 1: LANDING DUST/IMPACT PARTICLES =====
let impactParticles = [];
function initEnvParticles() {
envParticles = [];
const zone = getCurrentZone();
const particleCount = Math.min(100, Math.floor(maxHeight / 50) + 20);
if (zone <= 1) {
// Zone 0-1: Digital rain (dim muted teal)
for (let i = 0; i < particleCount; i++) {
envParticles.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
vx: 0,
vy: Math.random() * 0.5 + 0.3,
size: Math.random() * 2 + 1,
color: '#3a6868',
opacity: Math.random() * 0.5 + 0.15,
life: 1,
maxLife: 1,
type: 'rain'
});
}
} else if (zone <= 3) {
// Zone 2-3: Dust motes and ash (gray-brown)
for (let i = 0; i < particleCount * 0.8; i++) {
envParticles.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
vx: Math.random() * 0.2 - 0.1,
vy: Math.random() * 0.3 + 0.05,
size: Math.random() * 2 + 0.5,
color: '#6a5a4a',
opacity: Math.random() * 0.35 + 0.1,
life: 1,
maxLife: 1,
type: 'dust'
});
}
} else if (zone <= 5) {
// Zone 4-5: Heavy rain (dark gray-blue)
for (let i = 0; i < particleCount; i++) {
envParticles.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
vx: Math.random() * 0.3 - 0.15,
vy: Math.random() * 2 + 1.5,
size: Math.random() * 2 + 0.5,
color: '#4a5a68',
opacity: Math.random() * 0.55 + 0.2,
life: 1,
maxLife: 1,
type: 'rain'
});
}
} else if (zone <= 7) {
// Zone 6-7: Dark orange-brown embers
for (let i = 0; i < particleCount * 0.9; i++) {
envParticles.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
vx: Math.random() * 0.4 - 0.2,
vy: Math.random() * -0.5 - 0.5,
size: Math.random() * 2 + 1,
color: Math.random() > 0.7 ? '#6a5a3a' : '#5a3a2a',
opacity: Math.random() * 0.5 + 0.3,
life: 1,
maxLife: 1,
type: 'ember'
});
}
} else if (zone === 8) {
// Zone 8: Dim amber orbs
for (let i = 0; i < particleCount * 0.6; i++) {
envParticles.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
vx: Math.random() * 0.2 - 0.1,
vy: Math.random() * 0.2 - 0.1,
size: Math.random() * 3 + 1,
color: '#7a6a4a',
opacity: Math.random() * 0.4 + 0.2,
life: 1,
maxLife: 1,
type: 'glow'
});
}
} else {
// Zone 9: Leaves and petals (dark brown/olive)
for (let i = 0; i < particleCount * 0.7; i++) {
envParticles.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
vx: Math.random() * 0.5 - 0.25,
vy: Math.random() * 0.4 + 0.2,
size: Math.random() * 3 + 1,
color: Math.random() > 0.5 ? '#4a6a5a' : '#5a4a3a',
opacity: Math.random() * 0.4 + 0.15,
life: 1,
maxLife: 1,
type: 'leaf'
});
}
}
}
function updateEnvParticles() {
const zone = getCurrentZone();
// Update particles and filter in single pass for performance
let survivingParticles = [];
for (let i = 0; i < envParticles.length; i++) {
const p = envParticles[i];
// Apply wind
p.vx += windStrength * windDirection * 0.02;
// Update position
p.x += p.vx;
p.y += p.vy;
// Keep particles that are still visible
if (!(p.y > canvas.height + 50 || p.x < -50 || p.x > canvas.width + 50)) {
survivingParticles.push(p);
}
}
envParticles = survivingParticles;
// 파티클이 부족하면 개별 추가 (전체 재생성 대신 점진적 보충)
if (envParticles.length < 80 && Math.random() < 0.3) {
const zone = getCurrentZone();
let p = null;
if (zone <= 1) {
p = { x: Math.random() * canvas.width, y: -5, vx: 0, vy: Math.random() * 0.5 + 0.3, size: Math.random() * 2 + 1, color: '#3a6868', opacity: Math.random() * 0.5 + 0.15, life: 1, maxLife: 1, type: 'rain' };
} else if (zone <= 3) {
p = { x: Math.random() * canvas.width, y: -5, vx: Math.random() * 0.2 - 0.1, vy: Math.random() * 0.3 + 0.05, size: Math.random() * 2 + 0.5, color: '#6a5a4a', opacity: Math.random() * 0.35 + 0.1, life: 1, maxLife: 1, type: 'dust' };
} else if (zone <= 5) {
p = { x: Math.random() * canvas.width, y: -5, vx: Math.random() * 0.3 - 0.15, vy: Math.random() * 2 + 1.5, size: Math.random() * 2 + 0.5, color: '#4a5a68', opacity: Math.random() * 0.55 + 0.2, life: 1, maxLife: 1, type: 'rain' };