-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontact.html
More file actions
906 lines (798 loc) · 39.4 KB
/
Copy pathcontact.html
File metadata and controls
906 lines (798 loc) · 39.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
<title>Contact Me!</title>
<link rel="icon" type="image/png" href="assets/images/indexbg/pixelboyhead.png">
<meta name="description" content="Get in touch with Tanish Vashisth — open to work, collaborations, and conversations.">
<link href="https://unpkg.com/nes.css@2.3.0/css/nes.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="assets/css/global.css?v=20260607g">
<link rel="stylesheet" href="assets/css/contact.css?v=20260608a">
<style>
body {
background-color: #63adff;
color: white;
margin: 0;
padding: 0;
height: 100%;
width: 100%;
position: relative;
overflow: hidden;
}
#contact-bird {
position: absolute;
transition: none;
image-rendering: pixelated;
image-rendering: crisp-edges;
z-index: 10;
backface-visibility: hidden;
contain: layout paint;
will-change: transform;
}
#contact-bird.fall {
transition: transform 1.2s ease-in;
}
#contact-dog {
image-rendering: pixelated;
image-rendering: crisp-edges;
width: 11rem;
height: 11rem;
left: 40%;
transform: translateX(-50%);
pointer-events: none;
user-select: none;
z-index: 19;
backface-visibility: hidden;
contain: layout paint;
will-change: transform;
}
</style>
</head>
<body>
<header class="w-full">
<nav class="navbar">
<div class="navbar-desktop items-center justify-between w-full">
<div class="flex items-center space-x-4">
<a class="nav-item" href="blog.html">Blog</a>
<a class="nav-item" href="project.html">Projects</a>
</div>
<a href="/index.html" class="flex items-center justify-center">
<img src="assets/images/indexbg/logo.png" alt="logo" class="h-8 img">
</a>
<div class="flex items-center space-x-4">
<a class="nav-item" href="about.html">About</a>
<a class="nav-item" href="contact.html">Contact</a>
</div>
</div>
<!-- Hamburger menu -->
<div class="md:hidden flex items-center justify-between w-full">
<a href="/index.html" class="flex items-center justify-start">
<img src="assets/images/indexbg/logo.png" alt="logo" class="h-8 img">
</a>
<button id="menu-toggle" class="flex items-center justify-end">
<svg class="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M4 6h16M4 12h16m-7 6h7"></path>
</svg>
</button>
</div>
<div id="mobile-menu" class="hidden absolute top-0 right-0 w-full mt-14 z-50 bg-black text-right">
<a class="block py-2 px-4 text-white" href="index.html">Home</a>
<a class="block py-2 px-4 text-white" href="project.html">Projects</a>
<a class="block py-2 px-4 text-white" href="blog.html">Blog</a>
<a class="block py-2 px-4 text-white" href="about.html">About</a>
<a class="block py-2 px-4 text-white" href="contact.html">Contact</a>
</div>
</nav>
</header>
<!-- Duck Hunt Game Gate -->
<div id="game-section" class="w-full">
<div id="game-container" class="relative w-full overflow-hidden" style="height: 100vh; height: 100dvh; background-color: #63adff; cursor: url('assets/images/contact/crosshair.png') 12 12, crosshair; touch-action: manipulation;">
<div id="duckhunt-bg" class="absolute inset-0 z-0" style="background-image: url('assets/images/contact/duckhuntbg.png'); background-repeat: repeat-x; background-size: auto 100%; image-rendering: pixelated; image-rendering: -moz-crisp-edges; image-rendering: crisp-edges;"></div>
<div class="game-foreground absolute inset-0 pointer-events-none z-20" style="background-image: url('assets/images/contact/removebg.png'); background-repeat: repeat-x; background-size: auto 100%; image-rendering: pixelated; image-rendering: -moz-crisp-edges; image-rendering: crisp-edges;"></div>
<img src="assets/images/contact/flyduck.gif" id="contact-bird" class="img hidden absolute w-24 h-24 md:w-32 md:h-32 z-10" style="cursor: url('assets/images/contact/crosshair.png') 12 12, crosshair; will-change: transform;" alt="Bird">
<img src="assets/images/contact/laughingdog.gif" id="contact-dog" class="hidden absolute z-10" alt="Dog">
<!-- Duck Hunt HUD -->
<div class="hud-container">
<!-- Left HUD Group -->
<div class="hud-left-group">
<!-- SHOT Box -->
<div class="boxxy-green shot-box">
<div class="bullet-container" id="bullet-container">
<div class="bullet"></div>
<div class="bullet"></div>
<div class="bullet"></div>
</div>
<div class="shot-label">SHOT</div>
</div>
</div>
<!-- HIT Box -->
<div class="boxxy-green hit-box flex-row px-4 gap-3" style="flex-direction: row; align-items: center; gap: 12px;">
<div class="hit-label">HIT</div>
<div class="hit-container" id="hit-container">
<!-- 10 NES duck hit markers -->
<div class="hit-icon"></div>
<div class="hit-icon"></div>
<div class="hit-icon"></div>
<div class="hit-icon"></div>
<div class="hit-icon"></div>
<div class="hit-icon"></div>
<div class="hit-icon"></div>
<div class="hit-icon"></div>
<div class="hit-icon"></div>
<div class="hit-icon"></div>
</div>
</div>
<!-- SCORE Box -->
<div class="boxxy-green score-box">
<div class="score-val" id="score-display">000000</div>
<div class="score-label">SCORE</div>
</div>
</div>
<div id="game-start-overlay" class="absolute inset-0 flex flex-col items-center justify-center bg-black bg-opacity-60 gap-4 z-30">
<p class="headingfont text-white text-center text-[10px] md:text-[14px] px-4">Shoot 3 birds to unlock<br>the contact form</p>
<div class="flex flex-col md:flex-row items-center justify-center gap-6 md:gap-6">
<button id="contact-start-btn" class="boxxy headingfont text-white w-48 md:w-auto px-6 py-2 text-[10px] md:text-[12px] text-center justify-center">START</button>
<button id="contact-message-btn" class="boxxy headingfont text-white w-48 md:w-auto px-6 py-2 text-[10px] md:text-[12px] text-center justify-center hidden">SEND MESSAGE</button>
</div>
</div>
<div id="shot-flash" class="hidden absolute inset-0 bg-white opacity-30 pointer-events-none z-40"></div>
<!-- Contact Form (hidden until 3 birds shot) -->
<div id="form-section" class="hidden absolute inset-0 flex flex-col justify-between overflow-y-auto bg-black bg-opacity-40 z-50 pt-14">
<div class="flex flex-col items-center justify-center flex-grow w-full py-8">
<div class="headingfont text-green-400 text-center text-[10px] md:text-[13px] mb-4 px-4" style="text-shadow: 2px 2px 0px #000;">✓ 3 birds down. Form unlocked.</div>
<form id="contact-form" class="boxxy px-4 md:px-8 pb-6 pt-4 w-11/12 max-w-2xl" style="background-color: rgba(0, 0, 0, 0.6) !important;">
<h2 class="headingfont text-[16px] md:text-[20px] font-bold mb-6 text-center text-white">Contact Me</h2>
<!-- Grid for Name and Email -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 md:gap-10 mb-4">
<div>
<label for="name" class="block text-white headingfont text-[9px] mb-1">Name</label>
<input type="text" id="name" name="name" class="boxxy w-full px-3 py-2 mt-1 text-white headingfont text-[10px]" required>
</div>
<div>
<label for="email" class="block text-white headingfont text-[9px] mb-1">Email</label>
<input type="email" id="email" name="email" class="boxxy w-full px-3 py-2 mt-1 text-white headingfont text-[10px]" required>
</div>
</div>
<!-- Subject -->
<div class="mb-4">
<label for="subject" class="block text-white headingfont text-[9px] mb-1">Subject</label>
<input type="text" id="subject" name="subject" class="boxxy w-full px-3 py-2 mt-1 text-white headingfont text-[10px]" required>
</div>
<!-- Message -->
<div class="mb-6">
<label for="message" class="block text-white headingfont text-[9px] mb-1">Message</label>
<textarea id="message" name="message" class="boxxy w-full px-3 py-2 mt-1 text-white headingfont text-[10px]" rows="5" required></textarea>
</div>
<button type="submit" class="boxxy-green w-full px-3 py-2 text-white headingfont text-[10px] hover:bg-gray-800" style="display: block; width: 100%; text-align: center;">Send</button>
<p class="headingfont text-[8px] text-gray-400 text-center mt-4">INSERT MESSAGE TO CONTINUE (THE DOG IS WATCHING...)</p>
</form>
</div>
<footer class="flex flex-col md:flex-row items-center justify-center bg-gray-950 bg-opacity-50 py-6 w-full gap-2 z-50">
<p class="text-white max-[320px]:text-[8px] text-[10px] lg:text-[16px]">Copyright © 2024 --</p>
<a href="mailto:tanishvashisth@gmail.com"
class="text-white max-[320px]:text-[8px] text-[10px] lg:text-[16px] underline">tanishvashisth@gmail.com</a>
</footer>
</div>
</div>
</div>
<!-- Hand Tracking Tutorial Modal -->
<div id="hand-tutorial-modal" class="hidden fixed inset-0 z-[100] flex items-center justify-center p-3" style="background: rgba(0,0,0,0.82); backdrop-filter: blur(4px);">
<div class="boxxy w-full max-w-3xl flex flex-col gap-4 relative tutorial-modal-inner" style="background-color: rgba(0,0,0,0.94) !important; padding: 32px 28px 24px; border: none !important;">
<!-- Close -->
<button id="close-tutorial-btn" class="headingfont text-white absolute" style="top:14px; right:16px; font-size:11px; background:none; border:none; cursor:pointer; letter-spacing:1px;">✕ CLOSE</button>
<!-- Title -->
<h3 class="headingfont text-center" style="font-size:13px; color:#8cd600; text-shadow:2px 2px 0 #000; margin:0; letter-spacing:2px;">HAND CONTROL TUTORIAL</h3>
<!-- Two-column steps (desktop) / row steps (mobile) -->
<div class="tutorial-steps-grid">
<!-- Step 1 – GIF -->
<div class="tutorial-step-row">
<div class="tutorial-media-box tutorial-media-box--sm" id="tutorial-gif-box">
<img src="assets/images/contact/hand_tutorial.gif" alt="Hand aiming tutorial" style="image-rendering: pixelated;">
</div>
<p class="tutorial-step-label tutorial-step-label--row">
<strong style="text-transform: lowercase; color: #8cd600;">how to shoot?</strong><br>
point your index finger at the screen.<br>
snap thumb down to middle finger to shoot.
</p>
</div>
<!-- Step 2 – Image -->
<div class="tutorial-step-row">
<div class="tutorial-media-box tutorial-media-box--sm" id="tutorial-img-box">
<img src="assets/images/contact/point_towards_camera.png" alt="Hand shooting tutorial" style="image-rendering: pixelated;">
</div>
<p class="tutorial-step-label tutorial-step-label--row">
<strong style="text-transform: lowercase; color: #8cd600;">always point towards the camera</strong><br>
point your finger towards the camera for the gun to work.
</p>
</div>
</div>
<!-- Play -->
<div class="flex justify-center">
<button id="tutorial-play-btn" class="boxxy-green headingfont text-white" style="padding:12px 40px; font-size:11px; letter-spacing:2px;">▶ PLAY</button>
</div>
</div>
</div>
<script src="assets/js/constants.js"></script>
<script src="https://cdn.emailjs.com/dist/email.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js"></script>
<script>
(function () { emailjs.init('MAUBFHodMOevpbI-P'); })();
document.getElementById('menu-toggle').addEventListener('click', function () {
document.getElementById('mobile-menu').classList.toggle('hidden');
});
// --- Duck Hunt Gate ---
const BIRDS_NEEDED = DUCKHUNT_BIRDS_NEEDED;
const CONTACT_FORM_UNLOCKED_KEY = 'contactFormUnlocked';
let birdsShot = 0;
let animationFrameId = null;
let resizeFrameId = null;
let gameActive = false;
let bullets = 3;
const bird = document.getElementById('contact-bird');
const dog = document.getElementById('contact-dog');
const gameContainer = document.getElementById('game-container');
const startOverlay = document.getElementById('game-start-overlay');
const startOverlayMessage = startOverlay ? startOverlay.querySelector('p') : null;
const startButton = document.getElementById('contact-start-btn');
const messageButton = document.getElementById('contact-message-btn');
const scoreDisplay = document.getElementById('score-display');
const shotFlash = document.getElementById('shot-flash');
const bulletContainer = document.getElementById('bullet-container');
const hitContainer = document.getElementById('hit-container');
const hud = document.querySelector('.hud-container');
const formSection = document.getElementById('form-section');
const hitIcons = hitContainer ? Array.from(hitContainer.querySelectorAll('.hit-icon')) : [];
let bulletEls = bulletContainer ? Array.from(bulletContainer.children) : [];
let lastRenderedBullets = null;
let lastRenderedScore = null;
let lastRenderedHitCount = null;
const flySound = new Audio(DUCKHUNT_SOUNDS.wingFlap);
const shotSound = new Audio(DUCKHUNT_SOUNDS.shot);
const fallSound = new Audio(DUCKHUNT_SOUNDS.fall);
const missSound = new Audio(DUCKHUNT_SOUNDS.shot);
const duckInitSound = new Audio(DUCKHUNT_SOUNDS.duckinit);
const dogLaughingSound = new Audio(DUCKHUNT_SOUNDS.dogLaughing);
const highScoreSound = new Audio(DUCKHUNT_SOUNDS.highScore);
const pauseSound = new Audio(DUCKHUNT_SOUNDS.pause);
// Lower volume
flySound.volume = DUCKHUNT_VOLUME_LEVEL;
shotSound.volume = DUCKHUNT_VOLUME_LEVEL;
fallSound.volume = DUCKHUNT_VOLUME_LEVEL;
missSound.volume = DUCKHUNT_VOLUME_LEVEL;
duckInitSound.volume = DUCKHUNT_VOLUME_LEVEL;
dogLaughingSound.volume = DUCKHUNT_VOLUME_LEVEL;
highScoreSound.volume = DUCKHUNT_VOLUME_LEVEL;
pauseSound.volume = DUCKHUNT_VOLUME_LEVEL;
flySound.loop = true;
const defaultBirdSrc = DUCKHUNT_IMAGES.defaultBird;
const shotBirdSrc = DUCKHUNT_IMAGES.shotBird;
const deadBirdSrc = DUCKHUNT_IMAGES.deadBird;
function ensureHUDBullets() {
if (!bulletContainer || bulletContainer.childElementCount === 3) return;
const fragment = document.createDocumentFragment();
for (let i = 0; i < 3; i++) {
const b = document.createElement('div');
b.classList.add('bullet');
fragment.appendChild(b);
}
bulletContainer.replaceChildren(fragment);
bulletEls = Array.from(bulletContainer.children);
}
function updateHUD() {
if (bulletContainer) {
ensureHUDBullets();
if (lastRenderedBullets !== bullets) {
bulletEls.forEach((bulletEl, index) => {
bulletEl.classList.toggle('spent', index >= bullets);
});
lastRenderedBullets = bullets;
}
}
const score = birdsShot * 10000;
if (scoreDisplay && lastRenderedScore !== score) {
scoreDisplay.textContent = score.toString().padStart(6, '0');
lastRenderedScore = score;
}
const activeIndex = birdsShot % 10;
const activeHitCount = activeIndex === 0 && birdsShot > 0 ? 10 : activeIndex;
if (lastRenderedHitCount !== activeHitCount) {
hitIcons.forEach((icon, index) => {
icon.classList.toggle('active', index < activeHitCount);
});
lastRenderedHitCount = activeHitCount;
}
}
let currentBirdColor = 'black';
let birdX = 0;
let birdY = 0;
let vx = 0;
let vy = 0;
let isShot = false;
let isEscaping = false;
let difficultyRound = 1;
let gameUnlockedPermanently = localStorage.getItem(CONTACT_FORM_UNLOCKED_KEY) === 'true';
let misses = 0;
let lastBirdFrameAt = 0;
let birdWidth = 112;
let birdHeight = 112;
let containerWidth = 0;
let containerHeight = 0;
let containerLeft = 0;
let containerTop = 0;
let playfieldMaxX = 0;
let playfieldMinY = 72;
let playfieldMaxY = 72;
let currentBirdFlightMode = '';
let lastShotAttempt = {
x: null,
y: null,
at: 0
};
function syncGameMetrics() {
const rect = gameContainer.getBoundingClientRect();
containerWidth = gameContainer.clientWidth;
containerHeight = gameContainer.clientHeight;
containerLeft = rect.left;
containerTop = rect.top;
birdWidth = bird.offsetWidth || birdWidth;
birdHeight = bird.offsetHeight || birdHeight;
playfieldMaxX = Math.max(0, containerWidth - birdWidth);
playfieldMinY = Math.max(72, containerHeight * 0.1);
playfieldMaxY = Math.max(playfieldMinY, (containerHeight * 0.70) - birdHeight);
}
function renderBirdPosition() {
const facing = vx < 0 ? -1 : 1;
bird.style.transform = `translate3d(${birdX}px, ${birdY}px, 0) scaleX(${facing})`;
}
function isBirdHit(clientX, clientY) {
if (bird.classList.contains('hidden')) return false;
const localX = clientX - containerLeft;
const localY = clientY - containerTop;
return localX >= birdX &&
localX <= birdX + birdWidth &&
localY >= birdY &&
localY <= birdY + birdHeight;
}
function isDuplicateShotAttempt(clientX, clientY) {
const now = performance.now();
const duplicate = lastShotAttempt.x === clientX &&
lastShotAttempt.y === clientY &&
(now - lastShotAttempt.at) < 80;
lastShotAttempt = {
x: clientX,
y: clientY,
at: now
};
return duplicate;
}
function handleShotAttempt(event) {
if (!gameActive || isShot || isEscaping) return;
if (event.target === startButton || event.target === messageButton) return;
if (event.target && event.target.closest('#form-section, #hand-tutorial-modal, .hand-tracking-controls, .hand-tracking-overlay-toggle, .hand-tracking-hud-toggle, button, input, textarea, label, a')) {
return;
}
const { clientX, clientY } = event;
if (typeof clientX !== 'number' || typeof clientY !== 'number') return;
if (isDuplicateShotAttempt(clientX, clientY)) return;
if (isBirdHit(clientX, clientY)) {
event.stopPropagation();
onBirdShot();
return;
}
if (bullets <= 0) return;
bullets--;
misses++;
updateHUD();
missSound.currentTime = 0;
missSound.play();
flashScreen();
if (bullets === 0) {
isEscaping = true;
stopBirdLoop();
flySound.pause();
bird.style.pointerEvents = 'none';
let escapeY = birdY;
const animateEscape = () => {
escapeY -= 8;
birdY = escapeY;
renderBirdPosition();
if (escapeY < -120) {
bird.classList.add('hidden');
showDogAnimation(false, () => {
spawnBird();
});
return;
}
requestAnimationFrame(animateEscape);
};
requestAnimationFrame(animateEscape);
}
}
function handleHandTrackingFire(event) {
if (!event || !event.detail) return;
handleShotAttempt({
target: gameContainer,
clientX: event.detail.clientX,
clientY: event.detail.clientY,
stopPropagation() {}
});
}
function stopBirdLoop() {
if (animationFrameId) {
cancelAnimationFrame(animationFrameId);
animationFrameId = null;
}
lastBirdFrameAt = 0;
}
function queueMetricsRefresh() {
if (resizeFrameId) return;
resizeFrameId = requestAnimationFrame(() => {
resizeFrameId = null;
syncGameMetrics();
if (bird.classList.contains('hidden')) return;
birdX = Math.min(Math.max(birdX, 0), playfieldMaxX);
birdY = Math.min(Math.max(birdY, playfieldMinY), playfieldMaxY);
renderBirdPosition();
});
}
ensureHUDBullets();
syncGameMetrics();
window.addEventListener('resize', queueMetricsRefresh, { passive: true });
function showDogAnimation(isPerfect, callback) {
if (!dog) {
if (callback) callback();
return;
}
dog.src = isPerfect ? DUCKHUNT_IMAGES.perfectDog : DUCKHUNT_IMAGES.laughingDog;
if (isPerfect) {
dog.style.width = '14rem';
dog.style.height = '14rem';
dog.style.left = '35%';
if (highScoreSound) {
highScoreSound.currentTime = 0;
highScoreSound.play();
}
} else {
dog.style.width = '';
dog.style.height = '';
dog.style.left = '40%';
if (dogLaughingSound) {
dogLaughingSound.currentTime = 0;
dogLaughingSound.play();
}
}
const curH = containerHeight || gameContainer.clientHeight;
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
const dogHeight = (isPerfect ? 14 : 11) * rootFontSize;
const grassLineY = curH * 0.69;
const visibleBodyRatio = isPerfect ? 0.82 : 0.92;
// Start position (hidden under the grass/dirt)
let dogY = curH * 0.88;
// Peak position keeps the dog's lower body inside the grass strip.
const targetY = grassLineY - (dogHeight * visibleBodyRatio);
dog.style.top = '0';
dog.style.transform = `translate3d(-50%, ${dogY}px, 0)`;
dog.classList.remove('hidden');
const slideUp = () => {
dogY -= 4;
dog.style.transform = `translate3d(-50%, ${dogY}px, 0)`;
if (dogY <= targetY) {
const delay = isPerfect ? 2000 : 1300;
setTimeout(() => {
const slideDown = () => {
dogY += 4;
dog.style.transform = `translate3d(-50%, ${dogY}px, 0)`;
if (dogY >= curH * 0.88) {
dog.classList.add('hidden');
dog.style.transform = 'translateX(-50%)';
dog.style.width = '';
dog.style.height = '';
if (callback) callback();
return;
}
requestAnimationFrame(slideDown);
};
requestAnimationFrame(slideDown);
}, delay);
return;
}
requestAnimationFrame(slideUp);
};
requestAnimationFrame(slideUp);
}
function persistUnlockState(isUnlocked) {
gameUnlockedPermanently = isUnlocked;
localStorage.setItem(CONTACT_FORM_UNLOCKED_KEY, isUnlocked ? 'true' : 'false');
syncStartOverlay();
}
function openFormOverlay() {
gameActive = false;
stopBirdLoop();
flySound.pause();
bird.classList.add('hidden');
if (hud) hud.classList.add('hidden');
if (formSection) {
formSection.classList.remove('hidden');
formSection.classList.add('flex');
}
startOverlay.classList.add('hidden');
if (pauseSound) {
pauseSound.currentTime = 0;
pauseSound.play();
}
}
function syncStartOverlay() {
if (!startOverlayMessage || !startButton || !messageButton) return;
if (gameUnlockedPermanently) {
startOverlayMessage.innerHTML = 'Contact form already unlocked.<br>Choose what you want to do';
startButton.textContent = 'CONTINUE';
messageButton.classList.remove('hidden');
} else {
startOverlayMessage.innerHTML = 'Shoot 3 birds to unlock<br>the contact form';
startButton.textContent = 'START';
messageButton.classList.add('hidden');
}
}
function spawnBird() {
if (!gameActive) return;
bullets = 3;
isShot = false;
isEscaping = false;
bird.style.pointerEvents = 'auto';
updateHUD();
syncGameMetrics();
// Choose random color
const colors = ['black', 'red', 'blue'];
currentBirdColor = colors[Math.floor(Math.random() * colors.length)];
// Start near the grass line at the bottom
birdX = Math.random() * playfieldMaxX;
birdY = containerHeight * 0.65;
bird.style.left = '0';
bird.style.top = '0';
// Velocities: get progressively faster as difficultyRound and birdsShot increase (5% per duck shot)
const totalDucksShot = birdsShot + (difficultyRound - 1) * 3;
const speedMultiplier = 1 + (totalDucksShot * 0.05);
vx = (Math.random() > 0.5 ? 1 : -1) * (4 + Math.random() * 3) * speedMultiplier;
vy = -(3 + Math.random() * 3) * speedMultiplier; // start by flying up diagonally
bird.src = `assets/images/contact/duck_${currentBirdColor}_fly_diag.gif`;
currentBirdFlightMode = 'diag';
bird.classList.remove('hidden', 'fall');
renderBirdPosition();
flySound.currentTime = 0;
flySound.play();
stopBirdLoop();
const animateBird = (now) => {
if (!gameActive || isShot || isEscaping) {
stopBirdLoop();
return;
}
if (!lastBirdFrameAt) {
lastBirdFrameAt = now;
}
const step = Math.min(2, (now - lastBirdFrameAt) / 30 || 1);
lastBirdFrameAt = now;
birdX += vx * step;
birdY += vy * step;
// Bounce horizontal walls
if (birdX <= 0) {
birdX = 0;
vx = -vx;
} else if (birdX >= playfieldMaxX) {
birdX = playfieldMaxX;
vx = -vx;
}
// Bounce vertical walls (top limit 100px to clear navbar, bottom limit 0.70 of screen height)
if (birdY <= playfieldMinY) {
birdY = playfieldMinY;
vy = -vy;
} else if (birdY >= playfieldMaxY) {
birdY = playfieldMaxY;
vy = -vy;
}
renderBirdPosition();
// Update GIF animation based on vertical velocity
if (Math.abs(vy) > 0.5) {
if (currentBirdFlightMode !== 'diag') {
bird.src = `assets/images/contact/duck_${currentBirdColor}_fly_diag.gif`;
currentBirdFlightMode = 'diag';
}
} else {
if (currentBirdFlightMode !== 'horiz') {
bird.src = `assets/images/contact/duck_${currentBirdColor}_fly_horiz.gif`;
currentBirdFlightMode = 'horiz';
}
}
// 1.5% chance to change direction mid-air
if (Math.random() < (0.015 * step)) {
vx = (vx > 0 ? 1 : -1) * (4 + Math.random() * 3) * speedMultiplier;
if (Math.random() < 0.3) {
vy = 0;
} else {
vy = (Math.random() > 0.5 ? 1 : -1) * (3 + Math.random() * 3) * speedMultiplier;
}
}
animationFrameId = requestAnimationFrame(animateBird);
};
animationFrameId = requestAnimationFrame(animateBird);
}
function flashScreen() {
if (shotFlash) {
shotFlash.classList.remove('hidden');
setTimeout(() => shotFlash.classList.add('hidden'), 80);
}
}
function onBirdShot() {
if (!gameActive || isShot || isEscaping || bullets <= 0) return;
isShot = true;
stopBirdLoop();
flySound.pause();
bird.style.pointerEvents = 'none';
bullets--;
updateHUD();
flashScreen();
bird.src = `assets/images/contact/duck_${currentBirdColor}_shot.png`;
shotSound.currentTime = 0;
shotSound.play();
setTimeout(() => {
bird.src = `assets/images/contact/duck_${currentBirdColor}_dead.gif`;
fallSound.currentTime = 0;
fallSound.play();
syncGameMetrics();
const targetY = containerHeight * 0.75;
let fallY = birdY;
const animateFall = () => {
fallY += 6;
birdY = fallY;
renderBirdPosition();
if (fallY >= targetY) {
bird.classList.add('hidden');
birdsShot++;
updateHUD();
// Show dog animation when the 10-bird hit meter becomes fully filled
if (birdsShot === 10) {
showDogAnimation(true, () => {
difficultyRound++;
birdsShot = 0;
misses = 0;
updateHUD();
setTimeout(spawnBird, 600);
});
} else if (birdsShot >= BIRDS_NEEDED && !gameUnlockedPermanently) {
gameActive = false;
flySound.pause();
setTimeout(unlockForm, 400);
} else {
setTimeout(spawnBird, 600);
}
return;
}
requestAnimationFrame(animateFall);
};
requestAnimationFrame(animateFall);
}, 800);
}
function unlockForm() {
openFormOverlay();
}
gameContainer.addEventListener('pointerdown', handleShotAttempt);
gameContainer.addEventListener('mousedown', handleShotAttempt);
gameContainer.addEventListener('handtracking:fire', handleHandTrackingFire);
syncStartOverlay();
startButton.addEventListener('click', () => {
startOverlay.classList.add('hidden');
if (hud) hud.classList.remove('hidden');
if (formSection) formSection.classList.add('hidden');
gameActive = true;
if (!gameUnlockedPermanently) {
birdsShot = 0;
}
misses = 0;
bullets = 3;
updateHUD();
spawnBird();
});
messageButton.addEventListener('click', () => {
openFormOverlay();
});
function showToast(message, isError = false) {
const toast = document.createElement('div');
toast.className = 'boxxy-green headingfont fixed bottom-6 right-6 px-6 py-3 z-50 text-[12px] opacity-0 transition-opacity duration-300';
toast.style.pointerEvents = 'none';
toast.style.textShadow = '2px 2px 0px #000';
if (isError) {
toast.style.boxShadow = '0 -4px #000, 0 -8px #ff2a2a, 4px 0 #000, 4px -4px #ff2a2a, 8px 0 #ff2a2a, 0 4px #000, 0 8px #ff2a2a, -4px 0 #000, -4px 4px #ff2a2a, -8px 0 #ff2a2a, -4px -4px #ff2a2a, 4px 4px #ff2a2a';
toast.style.color = '#ff6b6b';
} else {
toast.style.color = '#8cd600';
}
toast.textContent = message;
document.body.appendChild(toast);
setTimeout(() => {
toast.classList.remove('opacity-0');
toast.classList.add('opacity-100');
}, 50);
setTimeout(() => {
toast.classList.remove('opacity-100');
toast.classList.add('opacity-0');
setTimeout(() => {
toast.remove();
}, 300);
}, 3000);
}
// --- Contact Form ---
document.getElementById('contact-form').addEventListener('submit', function (event) {
event.preventDefault();
const serviceID = 'service_uh2awsk';
const templateID = 'template_5o5412n';
emailjs.sendForm(serviceID, templateID, this)
.then(() => {
showToast('✓ Message Sent Successfully!');
this.reset();
// Hide contact form overlay
if (formSection) {
formSection.classList.add('hidden');
formSection.classList.remove('flex');
}
// Show game HUD again
if (hud) hud.classList.remove('hidden');
// Allow continue playing by resetting the game, unlocking permanently, and advancing the difficulty round
persistUnlockState(true);
difficultyRound++;
birdsShot = 0;
misses = 0;
bullets = 3;
updateHUD();
gameActive = true;
spawnBird();
}, (error) => {
showToast('✗ Failed to send message!', true);
console.error('Error:', error);
});
});
</script>
<script src="assets/js/handTracking.js?v=20260608e"></script>
<script>
(function () {
const tutorialModal = document.getElementById('hand-tutorial-modal');
const closeTutorialBtn = document.getElementById('close-tutorial-btn');
const tutorialPlayBtn = document.getElementById('tutorial-play-btn');
let tutorialShown = false;
function openTutorial() {
tutorialModal.classList.remove('hidden');
}
function closeTutorial() {
tutorialModal.classList.add('hidden');
}
// Close (X) — dismiss tutorial AND disable hand tracking
closeTutorialBtn.addEventListener('click', function () {
closeTutorial();
if (window.contactHandTracking && window.contactHandTracking.enabled) {
window.contactHandTracking.disable();
}
tutorialShown = false; // allow re-showing if user re-enables
});
// PLAY — dismiss tutorial, hand tracking stays on
tutorialPlayBtn.addEventListener('click', function () {
closeTutorial();
});
// Listen for hand tracking toggle events
const gameContainer = document.getElementById('game-container');
if (gameContainer) {
gameContainer.addEventListener('handtracking:toggle', function (e) {
if (e.detail && e.detail.enabled && !tutorialShown) {
tutorialShown = true;
openTutorial();
}
});
}
window.contactHandTracking = initHandTracking({ target: '#game-container', shootCooldown: 400 });
}());
</script>
</body>
</html>