-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
841 lines (715 loc) · 27.8 KB
/
script.js
File metadata and controls
841 lines (715 loc) · 27.8 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
// ==================== DEVICE DETECTION ====================
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || window.innerWidth <= 768;
const isTablet = /iPad|Android/i.test(navigator.userAgent) && window.innerWidth > 768 && window.innerWidth <= 1024;
// ==================== LOCOMOTIVE SCROLL - ULTRA OPTIMIZED ====================
let locoScroll;
function initLocomotiveScroll() {
locoScroll = new LocomotiveScroll({
el: document.querySelector('[data-scroll-container]'),
smooth: true,
multiplier: isMobile ? 1.2 : 1.5,
lerp: isMobile ? 0.1 : 0.15,
class: 'is-reveal',
reloadOnContextChange: true,
touchMultiplier: 2.5,
smoothMobile: true,
smartphone: {
smooth: true,
multiplier: 1.8
},
tablet: {
smooth: true,
multiplier: 1.6
}
});
locoScroll.on('scroll', ScrollTrigger.update);
ScrollTrigger.scrollerProxy('[data-scroll-container]', {
scrollTop(value) {
return arguments.length
? locoScroll.scrollTo(value, 0, 0)
: locoScroll.scroll.instance.scroll.y;
},
getBoundingClientRect() {
return {
top: 0,
left: 0,
width: window.innerWidth,
height: window.innerHeight
};
},
pinType: document.querySelector('[data-scroll-container]').style.transform
? 'transform'
: 'fixed'
});
ScrollTrigger.addEventListener('refresh', () => locoScroll.update());
ScrollTrigger.defaults({ scroller: '[data-scroll-container]' });
locoScroll.update();
ScrollTrigger.refresh();
setTimeout(() => {
locoScroll.update();
ScrollTrigger.refresh();
}, 100);
setupSmoothNavigation();
locoScroll.on('scroll', (args) => {
if (window.threeScene) {
window.threeScene.scrollY = args.scroll.y;
}
const nav = document.querySelector('#nav');
if (args.scroll.y > 100) {
nav.classList.add('scrolled');
} else {
nav.classList.remove('scrolled');
}
});
}
// ==================== CUSTOM CURSOR - DESKTOP ONLY ====================
class CustomCursor {
constructor() {
// Only initialize on desktop
if (isMobile || isTablet) {
return;
}
this.dot = document.querySelector('.cursor-dot');
this.outline = document.querySelector('.cursor-outline');
this.trail = document.querySelector('.cursor-trail');
this.mouseX = 0;
this.mouseY = 0;
this.dotX = 0;
this.dotY = 0;
this.outlineX = 0;
this.outlineY = 0;
this.trailX = 0;
this.trailY = 0;
this.init();
}
init() {
document.addEventListener('mousemove', (e) => {
this.mouseX = e.clientX;
this.mouseY = e.clientY;
});
this.animate();
document.querySelectorAll('a, button, .game-card, .service-card').forEach(elem => {
elem.addEventListener('mouseenter', () => {
this.dot.style.transform = 'translate(-50%, -50%) scale(2)';
this.outline.style.transform = 'translate(-50%, -50%) scale(1.5)';
});
elem.addEventListener('mouseleave', () => {
this.dot.style.transform = 'translate(-50%, -50%) scale(1)';
this.outline.style.transform = 'translate(-50%, -50%) scale(1)';
});
});
}
animate() {
this.dotX += (this.mouseX - this.dotX) * 0.8;
this.dotY += (this.mouseY - this.dotY) * 0.8;
this.outlineX += (this.mouseX - this.outlineX) * 0.15;
this.outlineY += (this.mouseY - this.outlineY) * 0.15;
this.trailX += (this.mouseX - this.trailX) * 0.1;
this.trailY += (this.mouseY - this.trailY) * 0.1;
this.dot.style.left = this.dotX + 'px';
this.dot.style.top = this.dotY + 'px';
this.outline.style.left = this.outlineX + 'px';
this.outline.style.top = this.outlineY + 'px';
this.trail.style.left = this.trailX + 'px';
this.trail.style.top = this.trailY + 'px';
requestAnimationFrame(() => this.animate());
}
}
// ==================== LOADING SCREEN ====================
class LoadingScreen {
constructor() {
this.screen = document.querySelector('.loading-screen');
this.progress = document.querySelector('.loading-progress');
this.percent = document.querySelector('.loading-percent');
this.status = document.querySelector('.loading-status');
this.currentProgress = 0;
this.targetProgress = 0;
this.statusMessages = [
'INITIALIZING SYSTEMS...',
'LOADING GAME ENGINE...',
'COMPILING SHADERS...',
'RENDERING 3D ASSETS...',
'OPTIMIZING PERFORMANCE...',
'READY TO PLAY!'
];
this.init();
}
init() {
this.simulate();
}
simulate() {
const interval = setInterval(() => {
this.targetProgress += Math.random() * 25;
if (this.targetProgress > 100) this.targetProgress = 100;
const statusIndex = Math.floor((this.targetProgress / 100) * (this.statusMessages.length - 1));
this.status.textContent = this.statusMessages[statusIndex];
if (this.targetProgress === 100) {
clearInterval(interval);
setTimeout(() => this.complete(), 200);
}
}, 120);
this.animateProgress();
}
animateProgress() {
this.currentProgress += (this.targetProgress - this.currentProgress) * 0.2;
this.progress.style.width = this.currentProgress + '%';
this.percent.textContent = Math.floor(this.currentProgress) + '%';
if (this.currentProgress < 99.9) {
requestAnimationFrame(() => this.animateProgress());
}
}
complete() {
this.screen.classList.add('hidden');
document.body.style.overflow = '';
setTimeout(() => {
initLocomotiveScroll();
initAnimations();
}, 200);
}
}
// ==================== THREE.JS 3D HELMET SCENE - MOBILE OPTIMIZED ====================
class ThreeScene {
constructor() {
this.scene = null;
this.camera = null;
this.renderer = null;
this.helmet = null;
this.particles = [];
this.scrollY = 0;
this.mouse = { x: 0, y: 0 };
this.targetMouse = { x: 0, y: 0 };
// Always initialize, but with different settings for mobile
this.init();
window.threeScene = this;
}
init() {
// Scene setup
this.scene = new THREE.Scene();
this.scene.fog = new THREE.Fog(0x0a0a0f, 10, 50);
// Camera setup - adjusted for mobile
const fov = isMobile ? 60 : 50;
this.camera = new THREE.PerspectiveCamera(
fov,
window.innerWidth / window.innerHeight,
0.1,
1000
);
// Adjust camera position for mobile
if (isMobile) {
this.camera.position.set(0, 2, 12);
} else {
this.camera.position.set(8, 2, 10);
}
this.camera.lookAt(0, 0, 0);
// Renderer setup - optimized for mobile
const canvas = document.getElementById('three-canvas');
this.renderer = new THREE.WebGLRenderer({
canvas: canvas,
alpha: true,
antialias: !isMobile, // Disable antialiasing on mobile for performance
powerPreference: isMobile ? "default" : "high-performance"
});
// Lower pixel ratio on mobile for better performance
const pixelRatio = isMobile ? 1 : Math.min(window.devicePixelRatio, 1.5);
this.renderer.setPixelRatio(pixelRatio);
this.renderer.setSize(window.innerWidth, window.innerHeight);
this.renderer.setClearColor(0x0a0a0f, 0);
// Lights
this.setupLights();
// Load helmet
this.loadHelmet();
// Create particles - fewer on mobile
this.createParticles();
// Event listeners
this.addEventListeners();
// Start animation
this.animate();
}
setupLights() {
const ambientLight = new THREE.AmbientLight(0xffffff, 0.4);
this.scene.add(ambientLight);
const light1 = new THREE.PointLight(0x00f0ff, isMobile ? 2 : 2.5, 50);
light1.position.set(5, 5, 5);
this.scene.add(light1);
const light2 = new THREE.PointLight(0xff0080, isMobile ? 1.5 : 2, 50);
light2.position.set(-5, 3, -5);
this.scene.add(light2);
const light3 = new THREE.PointLight(0xb000ff, isMobile ? 1 : 1.5, 30);
light3.position.set(0, -2, 5);
this.scene.add(light3);
const dirLight = new THREE.DirectionalLight(0xffffff, 0.5);
dirLight.position.set(0, 10, 5);
this.scene.add(dirLight);
}
loadHelmet() {
// Check if GLTFLoader exists
if (typeof THREE.GLTFLoader === 'undefined') {
console.log('GLTFLoader not available, using fallback');
this.createFallbackHelmet();
return;
}
const loader = new THREE.GLTFLoader();
loader.load(
'https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/DamagedHelmet/glTF/DamagedHelmet.gltf',
(gltf) => {
console.log('Helmet loaded successfully!');
this.helmet = gltf.scene;
this.setupHelmet();
},
(progress) => {
console.log('Loading helmet:', (progress.loaded / progress.total * 100) + '%');
},
(error) => {
console.error('Error loading helmet:', error);
this.createFallbackHelmet();
}
);
}
setupHelmet() {
const box = new THREE.Box3().setFromObject(this.helmet);
const center = box.getCenter(new THREE.Vector3());
const size = box.getSize(new THREE.Vector3());
const maxDim = Math.max(size.x, size.y, size.z);
const scale = isMobile ? 3 / maxDim : 4 / maxDim; // Smaller on mobile
this.helmet.scale.setScalar(scale);
this.helmet.position.sub(center.multiplyScalar(scale));
// Center the helmet on mobile
if (isMobile) {
this.helmet.position.set(0, 0, 0);
} else {
this.helmet.position.set(4, 0, 0);
}
this.helmet.traverse((child) => {
if (child.isMesh) {
child.material.emissive = new THREE.Color(0x00f0ff);
child.material.emissiveIntensity = 0.2;
child.material.metalness = 0.9;
child.material.roughness = 0.3;
}
});
this.helmet.userData.baseScale = scale;
this.scene.add(this.helmet);
console.log('Helmet added to scene');
}
createFallbackHelmet() {
console.log('Creating fallback helmet');
const helmetGroup = new THREE.Group();
// Main helmet dome
const domeGeometry = new THREE.SphereGeometry(1.2, 32, 32, 0, Math.PI * 2, 0, Math.PI / 1.5);
const domeMaterial = new THREE.MeshStandardMaterial({
color: 0x00f0ff,
metalness: 0.9,
roughness: 0.2,
emissive: 0x00f0ff,
emissiveIntensity: 0.3
});
const dome = new THREE.Mesh(domeGeometry, domeMaterial);
dome.position.y = 0.5;
helmetGroup.add(dome);
// Visor
const visorGeometry = new THREE.BoxGeometry(1.8, 0.4, 1.4);
const visorMaterial = new THREE.MeshStandardMaterial({
color: 0xff0080,
metalness: 1,
roughness: 0.1,
emissive: 0xff0080,
emissiveIntensity: 0.4,
transparent: true,
opacity: 0.8
});
const visor = new THREE.Mesh(visorGeometry, visorMaterial);
visor.position.set(0, 0.3, 0.6);
helmetGroup.add(visor);
// Side panels
const panelGeometry = new THREE.BoxGeometry(0.3, 0.8, 1.2);
const panelMaterial = new THREE.MeshStandardMaterial({
color: 0xb000ff,
metalness: 0.8,
roughness: 0.3,
emissive: 0xb000ff,
emissiveIntensity: 0.2
});
const leftPanel = new THREE.Mesh(panelGeometry, panelMaterial);
leftPanel.position.set(-1, 0.2, 0);
helmetGroup.add(leftPanel);
const rightPanel = new THREE.Mesh(panelGeometry, panelMaterial);
rightPanel.position.set(1, 0.2, 0);
helmetGroup.add(rightPanel);
// Top vent
const ventGeometry = new THREE.CylinderGeometry(0.15, 0.15, 0.6, 8);
const ventMaterial = new THREE.MeshStandardMaterial({
color: 0x00ff88,
metalness: 0.9,
roughness: 0.2,
emissive: 0x00ff88,
emissiveIntensity: 0.3
});
const vent = new THREE.Mesh(ventGeometry, ventMaterial);
vent.position.y = 1.2;
vent.rotation.z = Math.PI / 2;
helmetGroup.add(vent);
// Position for mobile vs desktop
if (isMobile) {
helmetGroup.position.set(0, 0, 0);
helmetGroup.scale.set(1.2, 1.2, 1.2);
} else {
helmetGroup.position.set(4, 0, 0);
helmetGroup.scale.set(1.5, 1.5, 1.5);
}
this.helmet = helmetGroup;
this.helmet.userData.baseScale = isMobile ? 1.2 : 1.5;
this.scene.add(this.helmet);
console.log('Fallback helmet created');
}
createParticles() {
// Fewer particles on mobile for better performance
const particleCount = isMobile ? 150 : 400;
const positions = new Float32Array(particleCount * 3);
const colors = new Float32Array(particleCount * 3);
const color1 = new THREE.Color(0x00f0ff);
const color2 = new THREE.Color(0xff0080);
const color3 = new THREE.Color(0xb000ff);
for (let i = 0; i < particleCount; i++) {
const i3 = i * 3;
positions[i3] = (Math.random() - 0.5) * 50;
positions[i3 + 1] = (Math.random() - 0.5) * 50;
positions[i3 + 2] = (Math.random() - 0.5) * 50;
const randomColor = Math.random();
let mixedColor;
if (randomColor < 0.33) {
mixedColor = color1;
} else if (randomColor < 0.66) {
mixedColor = color2;
} else {
mixedColor = color3;
}
colors[i3] = mixedColor.r;
colors[i3 + 1] = mixedColor.g;
colors[i3 + 2] = mixedColor.b;
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3));
const material = new THREE.PointsMaterial({
size: isMobile ? 0.08 : 0.06,
vertexColors: true,
transparent: true,
opacity: 0.6,
blending: THREE.AdditiveBlending
});
this.particleSystem = new THREE.Points(geometry, material);
this.scene.add(this.particleSystem);
}
addEventListeners() {
// Mouse/touch events
if (isMobile) {
// Use touch events on mobile
window.addEventListener('touchmove', (e) => {
if (e.touches.length > 0) {
this.targetMouse.x = (e.touches[0].clientX / window.innerWidth) * 2 - 1;
this.targetMouse.y = -(e.touches[0].clientY / window.innerHeight) * 2 + 1;
}
});
} else {
window.addEventListener('mousemove', (e) => {
this.targetMouse.x = (e.clientX / window.innerWidth) * 2 - 1;
this.targetMouse.y = -(e.clientY / window.innerHeight) * 2 + 1;
});
}
window.addEventListener('resize', () => {
this.camera.aspect = window.innerWidth / window.innerHeight;
this.camera.updateProjectionMatrix();
this.renderer.setSize(window.innerWidth, window.innerHeight);
if (locoScroll) {
locoScroll.update();
}
});
}
animate() {
requestAnimationFrame(() => this.animate());
// Smooth mouse tracking
this.mouse.x += (this.targetMouse.x - this.mouse.x) * 0.1;
this.mouse.y += (this.targetMouse.y - this.mouse.y) * 0.1;
// Animate helmet
if (this.helmet) {
const scrollProgress = Math.min(this.scrollY / (document.body.scrollHeight - window.innerHeight), 1);
// Reduced rotation on mobile
const rotationMultiplier = isMobile ? 0.2 : 0.4;
this.helmet.rotation.y = this.mouse.x * Math.PI * rotationMultiplier;
this.helmet.rotation.x = this.mouse.y * Math.PI * (rotationMultiplier * 0.625);
this.helmet.rotation.z = this.mouse.x * Math.PI * (rotationMultiplier * 0.375);
// Position based on scroll
this.helmet.position.y = Math.sin(scrollProgress * Math.PI * 4) * 2;
this.helmet.position.z = -scrollProgress * 10;
// Floating animation
this.helmet.position.y += Math.sin(Date.now() * 0.001) * 0.3;
// Scale pulse
const scale = 1 + Math.sin(Date.now() * 0.002) * 0.08;
const baseScale = this.helmet.userData.baseScale || 1;
this.helmet.scale.set(scale * baseScale, scale * baseScale, scale * baseScale);
// Tilt based on mouse - adjusted for mobile
if (!isMobile) {
const tiltX = this.mouse.y * 0.08;
const tiltY = this.mouse.x * 0.08;
this.helmet.position.x = 4 + tiltY * 2.5;
this.helmet.position.y += tiltX * 2.5;
}
}
// Animate particles
if (this.particleSystem) {
this.particleSystem.rotation.y += isMobile ? 0.0003 : 0.0005;
this.particleSystem.rotation.x = this.mouse.y * 0.1;
this.particleSystem.rotation.z = this.mouse.x * 0.05;
}
// Camera movement - adjusted for mobile
if (isMobile) {
this.camera.position.x = this.mouse.x * 1.5;
this.camera.position.y = 2 + this.mouse.y * 1.5;
} else {
this.camera.position.x = 8 + this.mouse.x * 3;
this.camera.position.y = 2 + this.mouse.y * 3;
}
this.camera.lookAt(this.helmet ? this.helmet.position : new THREE.Vector3(0, 0, 0));
this.renderer.render(this.scene, this.camera);
}
}
// ==================== GSAP ANIMATIONS - OPTIMIZED ====================
function initAnimations() {
gsap.registerPlugin(ScrollTrigger);
gsap.from('.hero-label', {
y: 40,
opacity: 0,
duration: 0.6,
delay: 0.2,
ease: 'power3.out'
});
gsap.from('.title-line .word', {
y: 120,
opacity: 0,
rotationX: -90,
stagger: 0.08,
duration: 0.8,
delay: 0.4,
ease: 'power4.out'
});
gsap.from('.hero-description', {
y: 25,
opacity: 0,
duration: 0.6,
delay: 0.8,
ease: 'power3.out'
});
gsap.from('.hero-cta', {
y: 25,
opacity: 0,
duration: 0.6,
delay: 1,
ease: 'power3.out'
});
gsap.from('.stat-box', {
y: 40,
opacity: 0,
stagger: 0.12,
duration: 0.7,
delay: 1.2,
ease: 'power3.out'
});
gsap.utils.toArray('.section-header').forEach((header) => {
gsap.from(header, {
scrollTrigger: {
trigger: header,
start: 'top 85%',
scroller: '[data-scroll-container]'
},
y: 50,
opacity: 0,
duration: 0.7,
ease: 'power3.out'
});
});
gsap.utils.toArray('.service-card').forEach((card, i) => {
gsap.from(card, {
scrollTrigger: {
trigger: card,
start: 'top 88%',
scroller: '[data-scroll-container]'
},
y: 70,
opacity: 0,
rotation: 5,
duration: 0.7,
delay: i * 0.12,
ease: 'power3.out'
});
});
gsap.utils.toArray('.game-card').forEach((card, i) => {
gsap.from(card, {
scrollTrigger: {
trigger: card,
start: 'top 88%',
scroller: '[data-scroll-container]'
},
y: 80,
opacity: 0,
scale: 0.92,
duration: 0.8,
delay: i * 0.12,
ease: 'power3.out'
});
});
gsap.utils.toArray('.tech-card').forEach((card, i) => {
gsap.from(card, {
scrollTrigger: {
trigger: card,
start: 'top 88%',
scroller: '[data-scroll-container]'
},
y: 40,
opacity: 0,
duration: 0.5,
delay: i * 0.06,
ease: 'power3.out'
});
});
gsap.from('.contact-title .line', {
scrollTrigger: {
trigger: '.contact-title',
start: 'top 85%',
scroller: '[data-scroll-container]'
},
y: 70,
opacity: 0,
stagger: 0.1,
duration: 0.9,
ease: 'power4.out'
});
const statNumbers = document.querySelectorAll('.stat-number');
statNumbers.forEach((stat) => {
const target = parseInt(stat.getAttribute('data-target'));
stat.innerHTML = '0';
ScrollTrigger.create({
trigger: stat,
start: 'top 85%',
scroller: '[data-scroll-container]',
onEnter: () => {
gsap.to(stat, {
innerHTML: target,
duration: 1.8,
snap: { innerHTML: 1 },
ease: 'power2.out',
onUpdate: function() {
const current = Math.floor(this.targets()[0].innerHTML);
const parent = stat.closest('.stat-box');
const label = parent.querySelector('.stat-label').textContent;
if (label.includes('PLAYERS')) {
stat.innerHTML = current + 'M+';
} else {
stat.innerHTML = current + '+';
}
},
onComplete: function() {
const parent = stat.closest('.stat-box');
const label = parent.querySelector('.stat-label').textContent;
if (label.includes('PLAYERS')) {
stat.innerHTML = target + 'M+';
} else {
stat.innerHTML = target + '+';
}
}
});
}
});
});
}
// ==================== NAVIGATION ====================
function setupSmoothNavigation() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const target = document.querySelector(targetId);
if (target && locoScroll) {
locoScroll.scrollTo(target, {
offset: -100,
duration: 1000,
easing: [0.25, 0.0, 0.35, 1.0]
});
} else if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
}
// ==================== MOBILE MENU ====================
const menuToggle = document.querySelector('.menu-toggle');
const mobileMenuOverlay = document.querySelector('.mobile-menu-overlay');
const mobileMenuClose = document.querySelector('.mobile-menu-close');
const mobileNavLinks = document.querySelectorAll('.mobile-nav-link');
menuToggle.addEventListener('click', () => {
mobileMenuOverlay.classList.add('active');
document.body.style.overflow = 'hidden';
// Ensure all items are visible first
gsap.set('.mobile-nav-link', { opacity: 1 });
// Then animate them in
gsap.from('.mobile-nav-link', {
x: -100,
opacity: 0,
stagger: 0.06,
duration: 0.4,
ease: 'power3.out',
clearProps: 'all' // Clear all GSAP properties after animation
});
});
mobileMenuClose.addEventListener('click', () => {
closeMobileMenu();
});
mobileNavLinks.forEach(link => {
link.addEventListener('click', () => {
closeMobileMenu();
});
});
function closeMobileMenu() {
mobileMenuOverlay.classList.remove('active');
document.body.style.overflow = '';
}
// ==================== GLITCH EFFECT ====================
function addGlitchEffect() {
const glitchElements = document.querySelectorAll('.glitch');
glitchElements.forEach(elem => {
setInterval(() => {
if (Math.random() > 0.95) {
elem.style.textShadow = `
${Math.random() * 10 - 5}px ${Math.random() * 10 - 5}px 0 #00f0ff,
${Math.random() * 10 - 5}px ${Math.random() * 10 - 5}px 0 #ff0080
`;
setTimeout(() => {
elem.style.textShadow = '0 0 20px var(--cyber-blue)';
}, 50);
}
}, 100);
});
}
// ==================== INITIALIZATION ====================
window.addEventListener('load', () => {
document.body.style.overflow = 'hidden';
// Only initialize custom cursor on desktop
if (!isMobile && !isTablet) {
new CustomCursor();
}
new LoadingScreen();
new ThreeScene();
addGlitchEffect();
let resizeTimer;
window.addEventListener('resize', () => {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(() => {
if (locoScroll) {
locoScroll.update();
}
ScrollTrigger.refresh();
}, 400);
});
});