Spaces:
Running
Running
Update index.html
Browse files- 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:
|
| 378 |
-
shotgun: { price:
|
| 379 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 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 |
// Update targets position
|
| 566 |
function updateTargets() {
|
|
@@ -642,56 +668,63 @@
|
|
| 642 |
}
|
| 643 |
|
| 644 |
function createProjectile(mouseX, mouseY, index) {
|
| 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 |
// Update projectiles position
|
| 697 |
function updateProjectiles() {
|
|
@@ -764,30 +797,40 @@
|
|
| 764 |
|
| 765 |
// Check for collisions with center
|
| 766 |
function checkCenterCollision() {
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 787 |
|
| 788 |
// 修改handleCenterHit函数
|
| 789 |
function handleHit(target, projectile) {
|
| 790 |
-
//
|
| 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 |
-
|
| 802 |
-
target.
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
|
|
|
|
|
|
|
|
|
|
| 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函数,添加全屏红色闪烁
|