GuangyuanSD commited on
Commit
fb0b71e
·
verified ·
1 Parent(s): ab19e66

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +164 -118
index.html CHANGED
@@ -182,7 +182,18 @@
182
  50% { opacity: 0.3; }
183
  100% { opacity: 1; }
184
  }
185
-
 
 
 
 
 
 
 
 
 
 
 
186
  .screen-flash {
187
  position: fixed;
188
  top: 0;
@@ -371,19 +382,32 @@
371
  projectiles: [],
372
  stars: [],
373
  currentWeapon: 'basic',
 
 
 
 
374
  weapons: {
375
  basic: { price: 0, fireRate: 500, projectileCount: 1, spread: 0, bouncy: false },
376
  rapid: { price: 50, fireRate: 250, projectileCount: 1, spread: 0, bouncy: false },
377
- double: { price: 150, fireRate: 500, projectileCount: 2, spread: 10, bouncy: false },
378
- shotgun: { price: 300, fireRate: 800, projectileCount: 5, spread: 20, bouncy: false },
379
- bouncy: { price: 500, fireRate: 400, projectileCount: 1, spread: 0, bouncy: true }
 
 
 
 
 
 
 
380
  },
381
  lastShot: 0,
382
  colors: ['#ff0000', '#00ff00', '#0000ff', '#ffff00', '#ff00ff', '#00ffff'],
383
  currentColorIndex: 0,
384
  targetSpeed: 2,
385
  targetCount: 1,
386
- gameOver: false
 
 
387
  };
388
 
389
  // DOM elements
@@ -526,41 +550,43 @@
526
  }
527
 
528
  function createTarget(index) {
529
- const target = document.createElement('div');
530
- target.className = 'target';
531
-
532
- // Use huggingface emoji as target
533
- target.style.backgroundImage = 'url("https://huggingface.co/front/assets/huggingface_logo-noborder.svg")';
534
-
535
- // Position randomly but ensure it's fully visible
536
- const maxX = window.innerWidth - 250;
537
- const maxY = window.innerHeight - 250;
538
-
539
- const x = Math.max(0, Math.min(maxX, Math.random() * maxX));
540
- const y = Math.max(0, Math.min(maxY, Math.random() * maxY));
541
-
542
- target.style.left = `${x}px`;
543
- target.style.top = `${y}px`;
544
-
545
- // Add hit effect
546
- const hitEffect = document.createElement('div');
547
- hitEffect.className = 'hit-effect';
548
- hitEffect.style.backgroundImage = 'url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 100 100\'><circle cx=\'50\' cy=\'50\' r=\'40\' fill=\'' + state.colors[state.currentColorIndex] + '\' opacity=\'0.7\'/></svg>")';
549
-
550
- target.appendChild(hitEffect);
551
- targetsContainer.appendChild(target);
552
-
553
- // Store target data
554
- state.targets.push({
555
- element: target,
556
- hitEffect: hitEffect,
557
- x: x,
558
- y: y,
559
- vx: (Math.random() - 0.5) * state.targetSpeed,
560
- vy: (Math.random() - 0.5) * state.targetSpeed,
561
- index: index
562
- });
563
- }
 
 
564
 
565
  // Update targets position
566
  function updateTargets() {
@@ -642,56 +668,63 @@
642
  }
643
 
644
  function createProjectile(mouseX, mouseY, index) {
645
- const projectile = document.createElement('div');
646
- projectile.className = 'projectile';
647
-
648
- // Calculate direction from center to mouse
649
- const centerX = window.innerWidth / 2;
650
- const centerY = window.innerHeight / 2;
651
-
652
- let dx = mouseX - centerX;
653
- let dy = mouseY - centerY;
654
-
655
- // Normalize direction vector
656
- const distance = Math.sqrt(dx * dx + dy * dy);
657
- dx /= distance;
658
- dy /= distance;
659
-
660
- // Apply weapon spread
661
- const weapon = state.weapons[state.currentWeapon];
662
- const spreadAngle = (index - (weapon.projectileCount - 1) / 2) * weapon.spread * (Math.PI / 180);
663
-
664
- // Rotate direction by spread angle
665
- const cos = Math.cos(spreadAngle);
666
- const sin = Math.sin(spreadAngle);
667
- const tx = dx * cos - dy * sin;
668
- const ty = dx * sin + dy * cos;
669
-
670
- dx = tx;
671
- dy = ty;
672
-
673
- // Set projectile color
674
- projectile.style.backgroundColor = state.colors[state.currentColorIndex];
675
-
676
- // Set initial position at center
677
- projectile.style.left = `${centerX}px`;
678
- projectile.style.top = `${centerY}px`;
679
-
680
- projectilesContainer.appendChild(projectile);
681
-
682
- // Store projectile data
683
- const projectileData = {
684
- element: projectile,
685
- x: centerX,
686
- y: centerY,
687
- vx: dx * 10,
688
- vy: dy * 10,
689
- bounces: 0,
690
- maxBounces: weapon.bouncy ? 3 : 0
691
- };
692
-
693
- state.projectiles.push(projectileData);
694
- }
 
 
 
 
 
 
 
695
 
696
  // Update projectiles position
697
  function updateProjectiles() {
@@ -764,30 +797,40 @@
764
 
765
  // Check for collisions with center
766
  function checkCenterCollision() {
767
- if (state.gameOver) return;
768
-
769
- const centerX = window.innerWidth / 2;
770
- const centerY = window.innerHeight / 2;
771
- const centerRadius = 10;
772
-
773
- state.targets.forEach(target => {
774
- // Check if any part of target is within center radius
775
- const targetCenterX = target.x + 125;
776
- const targetCenterY = target.y + 125;
777
- const distance = Math.sqrt(
778
- Math.pow(targetCenterX - centerX, 2) +
779
- Math.pow(targetCenterY - centerY, 2)
780
- );
781
-
782
- if (distance < centerRadius + 125) {
783
- handleCenterHit();
784
- }
785
- });
786
- }
 
 
 
 
 
 
 
 
 
 
787
 
788
  // 修改handleCenterHit函数
789
  function handleHit(target, projectile) {
790
- // Play hit sound
791
  hitSound.currentTime = 0;
792
  hitSound.play();
793
 
@@ -797,14 +840,17 @@ function handleHit(target, projectile) {
797
  target.element.classList.remove('hit-flash');
798
  }, 300);
799
 
800
- // 其他原有代码保持不变...
801
- // Show hit effect
802
- target.hitEffect.classList.add('active');
803
- setTimeout(() => {
804
- target.hitEffect.classList.remove('active');
805
- }, 500);
 
 
 
806
 
807
- // ...其余原有代码
808
  }
809
 
810
  // 修改handleCenterHit函数,添加全屏红色闪烁
 
182
  50% { opacity: 0.3; }
183
  100% { opacity: 1; }
184
  }
185
+
186
+ /* 添加在CSS部分 */
187
+ @keyframes newTargetFlash {
188
+ 0% { transform: scale(0.5); opacity: 0; }
189
+ 50% { transform: scale(1.2); opacity: 1; }
190
+ 100% { transform: scale(1); opacity: 1; }
191
+ }
192
+
193
+ .new-target-flash {
194
+ animation: newTargetFlash 0.5s forwards;
195
+ }
196
+
197
  .screen-flash {
198
  position: fixed;
199
  top: 0;
 
382
  projectiles: [],
383
  stars: [],
384
  currentWeapon: 'basic',
385
+ // ...其他属性保持不变...
386
+ centerRadius: 300, // 中心区域半径
387
+ targetSpawnBuffer: 100 // 目标生成缓冲区域
388
+
389
  weapons: {
390
  basic: { price: 0, fireRate: 500, projectileCount: 1, spread: 0, bouncy: false },
391
  rapid: { price: 50, fireRate: 250, projectileCount: 1, spread: 0, bouncy: false },
392
+ double: { price: 150, fireRate: 250, projectileCount: 2, spread: 10, bouncy: false },
393
+ shotgun: { price: 500, fireRate: 500, projectileCount: 5, spread: 20, bouncy: false },
394
+ // ...其他武器保持不变...
395
+ bouncy: {
396
+ price: 1000,
397
+ fireRate: 250, // 加快发射速度,类似第二种武器
398
+ projectileCount: 12, // 8发子弹
399
+ spread: 360, // 360度全方向散射
400
+ bouncy: true
401
+ }
402
  },
403
  lastShot: 0,
404
  colors: ['#ff0000', '#00ff00', '#0000ff', '#ffff00', '#ff00ff', '#00ffff'],
405
  currentColorIndex: 0,
406
  targetSpeed: 2,
407
  targetCount: 1,
408
+ gameOver: false// 修
409
+
410
+ }
411
  };
412
 
413
  // DOM elements
 
550
  }
551
 
552
  function createTarget(index) {
553
+ const target = document.createElement('div');
554
+ target.className = 'target new-target-flash';
555
+
556
+ // 使用huggingface emoji作为目标
557
+ target.style.backgroundImage = 'url("https://huggingface.co/front/assets/huggingface_logo-noborder.svg")';
558
+
559
+ const centerX = window.innerWidth / 2;
560
+ const centerY = window.innerHeight / 2;
561
+
562
+ let x, y;
563
+ let attempts = 0;
564
+ const maxAttempts = 10;
565
+
566
+ // 确保目标不会生成在中心区域附近
567
+ do {
568
+ x = Math.random() * (window.innerWidth - 250);
569
+ y = Math.random() * (window.innerHeight - 250);
570
+ attempts++;
571
+
572
+ // 计算到中心的距离
573
+ const dx = x - centerX;
574
+ const dy = y - centerY;
575
+ const distance = Math.sqrt(dx * dx + dy * dy);
576
+
577
+ // 如果距离足够远或尝试次数过多,则退出循环
578
+ if (distance > state.centerRadius || attempts >= maxAttempts) {
579
+ break;
580
+ }
581
+ } while (true);
582
+
583
+ // 移除闪烁动画
584
+ setTimeout(() => {
585
+ target.classList.remove('new-target-flash');
586
+ }, 500);
587
+
588
+ // ...其余创建目标的代码保持不变...
589
+ }
590
 
591
  // Update targets position
592
  function updateTargets() {
 
668
  }
669
 
670
  function createProjectile(mouseX, mouseY, index) {
671
+ const projectile = document.createElement('div');
672
+ projectile.className = 'projectile';
673
+
674
+ const centerX = window.innerWidth / 2;
675
+ const centerY = window.innerHeight / 2;
676
+
677
+ let dx, dy;
678
+ const weapon = state.weapons[state.currentWeapon];
679
+
680
+ if (state.currentWeapon === 'bouncy') {
681
+ // 第五种武器特殊处理 - 全方向随机散射
682
+ const angle = (index / weapon.projectileCount) * Math.PI * 2;
683
+ dx = Math.cos(angle);
684
+ dy = Math.sin(angle);
685
+ } else {
686
+ // 其他武器保持原有逻辑
687
+ dx = mouseX - centerX;
688
+ dy = mouseY - centerY;
689
+
690
+ // 标准化方向向量
691
+ const distance = Math.sqrt(dx * dx + dy * dy);
692
+ dx /= distance;
693
+ dy /= distance;
694
+
695
+ // 应用武器散射
696
+ const spreadAngle = (index - (weapon.projectileCount - 1) / 2) * weapon.spread * (Math.PI / 180);
697
+ const cos = Math.cos(spreadAngle);
698
+ const sin = Math.sin(spreadAngle);
699
+ const tx = dx * cos - dy * sin;
700
+ const ty = dx * sin + dy * cos;
701
+
702
+ dx = tx;
703
+ dy = ty;
704
+ }
705
+
706
+ // 设置子弹颜色
707
+ projectile.style.backgroundColor = state.colors[state.currentColorIndex];
708
+
709
+ // 设置初始位置在中心
710
+ projectile.style.left = `${centerX}px`;
711
+ projectile.style.top = `${centerY}px`;
712
+
713
+ projectilesContainer.appendChild(projectile);
714
+
715
+ // 存储子弹数据
716
+ const projectileData = {
717
+ element: projectile,
718
+ x: centerX,
719
+ y: centerY,
720
+ vx: dx * 15, // 加快子弹速度
721
+ vy: dy * 15,
722
+ bounces: 0,
723
+ maxBounces: weapon.bouncy ? 3 : 0
724
+ };
725
+
726
+ state.projectiles.push(projectileData);
727
+ }
728
 
729
  // Update projectiles position
730
  function updateProjectiles() {
 
797
 
798
  // Check for collisions with center
799
  function checkCenterCollision() {
800
+ const centerX = window.innerWidth / 2;
801
+ const centerY = window.innerHeight / 2;
802
+ const centerRadius = 50; // 中心区域半径
803
+
804
+ state.targets.forEach(target => {
805
+ const targetCenterX = target.x + 125; // 目标中心X
806
+ const targetCenterY = target.y + 125; // 目标中心Y
807
+
808
+ // 计算到中心的距离
809
+ const dx = targetCenterX - centerX;
810
+ const dy = targetCenterY - centerY;
811
+ const distance = Math.sqrt(dx * dx + dy * dy);
812
+
813
+ if (distance < centerRadius) {
814
+ handleCenterHit();
815
+
816
+ // 添加红色全屏闪烁
817
+ const screenFlash = document.createElement('div');
818
+ screenFlash.className = 'screen-flash';
819
+ gameContainer.appendChild(screenFlash);
820
+
821
+ setTimeout(() => {
822
+ screenFlash.classList.add('active');
823
+ setTimeout(() => {
824
+ screenFlash.remove();
825
+ }, 500);
826
+ }, 0);
827
+ }
828
+ });
829
+ }
830
 
831
  // 修改handleCenterHit函数
832
  function handleHit(target, projectile) {
833
+ // 播放击中音效
834
  hitSound.currentTime = 0;
835
  hitSound.play();
836
 
 
840
  target.element.classList.remove('hit-flash');
841
  }, 300);
842
 
843
+ // 增强击退效果 - 计算从子弹到目标的方向
844
+ const dx = target.x - projectile.x;
845
+ const dy = target.y - projectile.y;
846
+ const distance = Math.sqrt(dx * dx + dy * dy);
847
+
848
+ // 标准化方向向量并放大击退力度
849
+ const force = 15; // 增加击退力度
850
+ target.vx = (dx / distance) * force;
851
+ target.vy = (dy / distance) * force;
852
 
853
+ // ...其余击中处理代码保持不变...
854
  }
855
 
856
  // 修改handleCenterHit函数,添加全屏红色闪烁