Spaces:
Running
Running
File size: 35,264 Bytes
76eaf9e |
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 |
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cosmic Defender PRO</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.05); }
}
.pulse { animation: pulse 1.5s infinite; }
.star {
position: absolute;
background: white;
border-radius: 50%;
animation: twinkle var(--duration) infinite ease-in-out;
}
@keyframes twinkle {
0%, 100% { opacity: 0.2; }
50% { opacity: 1; }
}
#gameCanvas {
box-shadow: 0 0 30px rgba(0, 100, 255, 0.5);
border-radius: 10px;
}
.explosion {
position: absolute;
width: 40px;
height: 40px;
background: radial-gradient(circle, yellow, orange, red);
border-radius: 50%;
opacity: 0;
transform: scale(0);
animation: explode 0.5s forwards;
}
@keyframes explode {
0% { transform: scale(0); opacity: 1; }
100% { transform: scale(3); opacity: 0; }
}
.powerup {
position: absolute;
width: 20px;
height: 20px;
background: radial-gradient(circle, #10b981, #047857);
border-radius: 50%;
animation: float 2s infinite ease-in-out;
}
@keyframes float {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-10px); }
}
.shield {
position: absolute;
width: 60px;
height: 60px;
border: 2px dashed rgba(59, 130, 246, 0.7);
border-radius: 50%;
animation: shieldPulse 2s infinite;
}
@keyframes shieldPulse {
0%, 100% { transform: scale(1); opacity: 0.7; }
50% { transform: scale(1.1); opacity: 0.4; }
}
.boss-health {
height: 20px;
background: linear-gradient(to right, #ef4444, #f59e0b);
border-radius: 10px;
transition: width 0.3s;
}
</style>
</head>
<body class="bg-gray-900 text-white flex flex-col items-center justify-center min-h-screen p-4 overflow-hidden">
<!-- Background Elements -->
<div class="absolute inset-0 overflow-hidden">
<div id="stars"></div>
</div>
<!-- Game UI -->
<div class="z-10 w-full max-w-4xl">
<!-- Header -->
<header class="flex justify-between items-center mb-4">
<div class="text-2xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-blue-400 to-purple-600">
COSMIC DEFENDER <span class="text-xs bg-blue-600 text-white px-2 py-1 rounded">PRO</span>
</div>
<div class="flex space-x-6">
<div class="text-lg font-mono">
<i class="fas fa-star text-yellow-400 mr-1"></i> <span id="score">0</span>
</div>
<div class="text-lg font-mono">
<i class="fas fa-heart text-red-500 mr-1"></i> <span id="lives">3</span>
</div>
<div class="text-lg font-mono">
<i class="fas fa-bolt text-yellow-400 mr-1"></i> <span id="level">1</span>
</div>
</div>
</header>
<!-- Game Container -->
<div class="relative">
<canvas id="gameCanvas" width="800" height="600" class="w-full border-2 border-blue-500"></canvas>
<!-- Start Screen -->
<div id="startScreen" class="absolute inset-0 flex flex-col items-center justify-center bg-black bg-opacity-90 rounded-lg p-6 text-center">
<h2 class="text-5xl font-bold mb-2 bg-clip-text text-transparent bg-gradient-to-r from-blue-400 to-purple-600">
COSMIC DEFENDER PRO
</h2>
<p class="text-xl mb-8 text-gray-300">Defend the galaxy from alien invasion!</p>
<div class="grid grid-cols-2 gap-8 mb-8">
<div class="bg-gray-800 p-4 rounded-lg">
<h3 class="text-blue-400 font-semibold mb-2"><i class="fas fa-gamepad mr-2"></i>Controls</h3>
<ul class="text-left space-y-2">
<li><i class="fas fa-arrow-left mr-2 text-blue-400"></i> Move Left</li>
<li><i class="fas fa-arrow-right mr-2 text-blue-400"></i> Move Right</li>
<li><i class="fas fa-space-shuttle mr-2 text-blue-400"></i> Shoot (Space)</li>
<li><i class="fas fa-bolt mr-2 text-blue-400"></i> Special (Shift)</li>
</ul>
</div>
<div class="bg-gray-800 p-4 rounded-lg">
<h3 class="text-purple-400 font-semibold mb-2"><i class="fas fa-trophy mr-2"></i>Powerups</h3>
<ul class="text-left space-y-2">
<li><span class="w-3 h-3 bg-green-500 rounded-full inline-block mr-2"></span> Health</li>
<li><span class="w-3 h-3 bg-blue-500 rounded-full inline-block mr-2"></span> Shield</li>
<li><span class="w-3 h-3 bg-yellow-500 rounded-full inline-block mr-2"></span> Rapid Fire</li>
<li><span class="w-3 h-3 bg-red-500 rounded-full inline-block mr-2"></span> Nuke</li>
</ul>
</div>
</div>
<div class="flex space-x-4">
<button id="startBtn" class="px-8 py-3 bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700 rounded-lg text-xl font-semibold transition-all pulse">
<i class="fas fa-play mr-2"></i>Start Mission
</button>
<button id="settingsBtn" class="px-8 py-3 bg-gray-700 hover:bg-gray-600 rounded-lg text-xl font-semibold transition-all">
<i class="fas fa-cog mr-2"></i>Settings
</button>
</div>
</div>
<!-- Game Over Screen -->
<div id="gameOver" class="hidden absolute inset-0 flex flex-col items-center justify-center bg-black bg-opacity-90 rounded-lg p-6">
<h2 class="text-5xl font-bold text-red-500 mb-4">MISSION FAILED</h2>
<div class="bg-gray-800 p-6 rounded-lg mb-6 w-64">
<div class="text-2xl font-mono mb-2">Score: <span id="finalScore">0</span></div>
<div class="text-lg mb-4">Level Reached: <span id="finalLevel">1</span></div>
<div class="text-lg">Enemies Defeated: <span id="enemiesDefeated">0</span></div>
</div>
<div class="flex space-x-4">
<button id="restartBtn" class="px-6 py-2 bg-blue-600 hover:bg-blue-700 rounded-lg text-lg font-semibold transition-all">
<i class="fas fa-redo mr-2"></i>Retry
</button>
<button id="menuBtn" class="px-6 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg text-lg font-semibold transition-all">
<i class="fas fa-home mr-2"></i>Main Menu
</button>
</div>
</div>
<!-- Pause Screen -->
<div id="pauseScreen" class="hidden absolute inset-0 flex flex-col items-center justify-center bg-black bg-opacity-90 rounded-lg">
<h2 class="text-4xl font-bold text-yellow-400 mb-6">MISSION PAUSED</h2>
<button id="resumeBtn" class="px-8 py-3 bg-green-600 hover:bg-green-700 rounded-lg text-xl font-semibold transition-all mb-4">
<i class="fas fa-play mr-2"></i>Resume
</button>
<button id="quitBtn" class="px-8 py-3 bg-gray-700 hover:bg-gray-600 rounded-lg text-xl font-semibold transition-all">
<i class="fas fa-sign-out-alt mr-2"></i>Quit Mission
</button>
</div>
<!-- Boss Health Bar -->
<div id="bossHealthContainer" class="hidden absolute top-4 left-1/2 transform -translate-x-1/2 w-64 bg-gray-800 rounded-lg p-2">
<div class="text-center text-yellow-400 font-bold mb-1">BOSS</div>
<div class="boss-health" id="bossHealthBar"></div>
</div>
</div>
<!-- Footer -->
<footer class="mt-4 text-center text-gray-500 text-sm">
<p>Use arrow keys to move, SPACE to shoot, SHIFT for special attack | P to pause</p>
<p class="mt-1">© 2023 Cosmic Defender PRO | All rights reserved</p>
</footer>
</div>
<script>
// =============================================
// GAME INITIALIZATION
// =============================================
// Create stars background
const starsContainer = document.getElementById('stars');
for (let i = 0; i < 200; i++) {
const star = document.createElement('div');
star.className = 'star';
star.style.left = `${Math.random() * 100}%`;
star.style.top = `${Math.random() * 100}%`;
star.style.width = `${Math.random() * 3}px`;
star.style.height = star.style.width;
star.style.setProperty('--duration', `${2 + Math.random() * 3}s`);
starsContainer.appendChild(star);
}
// Game canvas setup
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
canvas.width = 800;
canvas.height = 600;
// UI Elements
const scoreDisplay = document.getElementById('score');
const finalScoreDisplay = document.getElementById('finalScore');
const livesDisplay = document.getElementById('lives');
const levelDisplay = document.getElementById('level');
const finalLevelDisplay = document.getElementById('finalLevel');
const enemiesDefeatedDisplay = document.getElementById('enemiesDefeated');
const gameOverScreen = document.getElementById('gameOver');
const startScreen = document.getElementById('startScreen');
const pauseScreen = document.getElementById('pauseScreen');
const bossHealthContainer = document.getElementById('bossHealthContainer');
const bossHealthBar = document.getElementById('bossHealthBar');
// Buttons
const startBtn = document.getElementById('startBtn');
const restartBtn = document.getElementById('restartBtn');
const menuBtn = document.getElementById('menuBtn');
const resumeBtn = document.getElementById('resumeBtn');
const quitBtn = document.getElementById('quitBtn');
const settingsBtn = document.getElementById('settingsBtn');
// =============================================
// GAME STATE
// =============================================
// Player
let player = {
x: canvas.width / 2 - 25,
y: canvas.height - 80,
w: 50,
h: 60,
speed: 5,
fireRate: 300, // ms between shots
lastShot: 0,
specialCharge: 0,
maxSpecial: 100,
hasShield: false,
shieldTimer: 0,
rapidFire: false,
rapidFireTimer: 0
};
// Game objects
let shots = [];
let enemies = [];
let powerups = [];
let explosions = [];
let particles = [];
let boss = null;
// Game state
let score = 0;
let lives = 3;
let level = 1;
let enemiesDefeated = 0;
let gameOver = false;
let gameStarted = false;
let gamePaused = false;
let keys = {};
let enemySpawnRate = 1500; // ms
let enemySpeed = 2;
let lastEnemySpawn = 0;
let lastPowerupSpawn = 0;
let powerupSpawnRate = 10000; // ms
let backgroundOffset = 0;
let parallaxStars = [];
// Create parallax stars
for (let i = 0; i < 100; i++) {
parallaxStars.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
size: Math.random() * 3,
speed: 0.5 + Math.random() * 2,
alpha: 0.2 + Math.random() * 0.8
});
}
// =============================================
// EVENT LISTENERS
// =============================================
document.addEventListener('keydown', (e) => {
keys[e.key] = true;
// Start game with space if not started
if (e.key === ' ' && !gameStarted && !gameOver) {
startGame();
}
// Pause game
if (e.key === 'p' && gameStarted && !gameOver) {
togglePause();
}
});
document.addEventListener('keyup', (e) => {
keys[e.key] = false;
});
// Button event listeners
startBtn.addEventListener('click', startGame);
restartBtn.addEventListener('click', restartGame);
menuBtn.addEventListener('click', returnToMenu);
resumeBtn.addEventListener('click', togglePause);
quitBtn.addEventListener('click', returnToMenu);
settingsBtn.addEventListener('click', () => {
alert('Settings will be available in the next update!');
});
// =============================================
// GAME FUNCTIONS
// =============================================
function startGame() {
gameStarted = true;
gameOver = false;
startScreen.classList.add('hidden');
resetGame();
gameLoop();
}
function restartGame() {
gameOver = false;
gameOverScreen.classList.add('hidden');
resetGame();
gameLoop();
}
function returnToMenu() {
gameOver = false;
gamePaused = false;
gameOverScreen.classList.add('hidden');
pauseScreen.classList.add('hidden');
startScreen.classList.remove('hidden');
}
function togglePause() {
gamePaused = !gamePaused;
if (gamePaused) {
pauseScreen.classList.remove('hidden');
} else {
pauseScreen.classList.add('hidden');
}
}
function resetGame() {
// Reset player
player = {
x: canvas.width / 2 - 25,
y: canvas.height - 80,
w: 50,
h: 60,
speed: 5,
fireRate: 300,
lastShot: 0,
specialCharge: 0,
maxSpecial: 100,
hasShield: false,
shieldTimer: 0,
rapidFire: false,
rapidFireTimer: 0
};
// Reset game objects
shots = [];
enemies = [];
powerups = [];
explosions = [];
particles = [];
boss = null;
bossHealthContainer.classList.add('hidden');
// Reset game state
score = 0;
lives = 3;
level = 1;
enemiesDefeated = 0;
enemySpawnRate = 1500;
enemySpeed = 2;
lastEnemySpawn = 0;
lastPowerupSpawn = 0;
powerupSpawnRate = 10000;
// Update UI
updateUI();
}
function updateUI() {
scoreDisplay.textContent = score;
livesDisplay.textContent = lives;
levelDisplay.textContent = level;
finalScoreDisplay.textContent = score;
finalLevelDisplay.textContent = level;
enemiesDefeatedDisplay.textContent = enemiesDefeated;
}
function createExplosion(x, y, size = 1) {
// Create visual explosion
const explosion = document.createElement('div');
explosion.className = 'explosion';
explosion.style.left = `${x - 20}px`;
explosion.style.top = `${y - 20}px`;
explosion.style.transform = `scale(${size})`;
document.body.appendChild(explosion);
// Remove after animation
setTimeout(() => {
explosion.remove();
}, 500);
// Create particles
for (let i = 0; i < 15 * size; i++) {
particles.push({
x: x,
y: y,
size: 2 + Math.random() * 3 * size,
color: `hsl(${Math.random() * 30 + 10}, 100%, 50%)`,
speedX: -5 + Math.random() * 10,
speedY: -5 + Math.random() * 10,
life: 30 + Math.random() * 30
});
}
}
function spawnEnemy() {
const now = Date.now();
if (now - lastEnemySpawn < enemySpawnRate || gameOver || gamePaused) return;
lastEnemySpawn = now;
// Every 5 levels, spawn a boss
if (level % 5 === 0 && !boss) {
spawnBoss();
return;
}
// Regular enemies
const colors = ['#ef4444', '#f97316', '#ec4899', '#8b5cf6'];
const types = ['basic', 'fast', 'tank', 'shooter'];
const type = types[Math.floor(Math.random() * types.length)];
let enemy = {
x: Math.random() * (canvas.width - 40),
y: -40,
w: 40,
h: 40,
color: colors[Math.floor(Math.random() * colors.length)],
type: type,
health: type === 'tank' ? 3 : 1,
speed: enemySpeed * (type === 'fast' ? 1.5 : 1),
lastShot: 0,
canShoot: type === 'shooter'
};
enemies.push(enemy);
}
function spawnBoss() {
boss = {
x: canvas.width / 2 - 100,
y: -150,
w: 200,
h: 150,
color: '#dc2626',
health: 10 + level * 2,
maxHealth: 10 + level * 2,
speed: enemySpeed * 0.7,
phase: 1,
lastShot: 0,
pattern: 'down',
moveTimer: 0
};
bossHealthContainer.classList.remove('hidden');
updateBossHealth();
}
function updateBossHealth() {
const percent = (boss.health / boss.maxHealth) * 100;
bossHealthBar.style.width = `${percent}%`;
}
function spawnPowerup() {
const now = Date.now();
if (now - lastPowerupSpawn < powerupSpawnRate || gameOver || gamePaused) return;
lastPowerupSpawn = now;
const types = ['health', 'shield', 'rapidfire', 'nuke'];
const type = types[Math.floor(Math.random() * types.length)];
powerups.push({
x: Math.random() * (canvas.width - 20),
y: -20,
w: 20,
h: 20,
type: type,
color: type === 'health' ? '#10b981' :
type === 'shield' ? '#3b82f6' :
type === 'rapidfire' ? '#f59e0b' : '#ef4444',
speed: 2
});
}
function activatePowerup(powerup) {
switch(powerup.type) {
case 'health':
lives = Math.min(5, lives + 1);
createExplosion(powerup.x + powerup.w/2, powerup.y + powerup.h/2, 0.5);
break;
case 'shield':
player.hasShield = true;
player.shieldTimer = 10000; // 10 seconds
createExplosion(powerup.x + powerup.w/2, powerup.y + powerup.h/2, 0.5);
break;
case 'rapidfire':
player.rapidFire = true;
player.rapidFireTimer = 8000; // 8 seconds
player.fireRate = 100;
createExplosion(powerup.x + powerup.w/2, powerup.y + powerup.h/2, 0.5);
break;
case 'nuke':
// Destroy all enemies
enemies.forEach(enemy => {
createExplosion(enemy.x + enemy.w/2, enemy.y + enemy.h/2, 1.5);
score += 10 * level;
enemiesDefeated++;
});
enemies = [];
if (boss) {
boss.health -= 5;
updateBossHealth();
createExplosion(boss.x + boss.w/2, boss.y + boss.h/2, 3);
if (boss.health <= 0) {
defeatBoss();
}
}
break;
}
updateUI();
}
function defeatBoss() {
createExplosion(boss.x + boss.w/2, boss.y + boss.h/2, 4);
score += 500 * level;
enemiesDefeated++;
boss = null;
bossHealthContainer.classList.add('hidden');
level++;
enemySpawnRate = Math.max(500, enemySpawnRate - 100);
enemySpeed = Math.min(6, enemySpeed + 0.3);
updateUI();
}
function shoot() {
const now = Date.now();
if (now - player.lastShot < player.fireRate) return;
player.lastShot = now;
// Main shot
shots.push({
x: player.x + player.w/2 - 2,
y: player.y,
w: 4,
h: 15,
color: '#10b981',
speed: 8,
damage: 1
});
// Side shots when special is charged
if (player.specialCharge >= player.maxSpecial) {
player.specialCharge = 0;
// Left shot
shots.push({
x: player.x + 10,
y: player.y + 20,
w: 6,
h: 20,
color: '#3b82f6',
speed: 10,
damage: 2,
angle: -0.2
});
// Right shot
shots.push({
x: player.x + player.w - 16,
y: player.y + 20,
w: 6,
h: 20,
color: '#3b82f6',
speed: 10,
damage: 2,
angle: 0.2
});
}
}
function specialAttack() {
if (player.specialCharge < player.maxSpecial) return;
player.specialCharge = 0;
// Create a powerful wave attack
for (let i = 0; i < 10; i++) {
shots.push({
x: player.x + player.w/2 - 3 + (i * 6) - 27,
y: player.y,
w: 6,
h: 25,
color: '#ec4899',
speed: 12,
damage: 3
});
}
}
function enemyShoot(enemy) {
const now = Date.now();
if (now - enemy.lastShot < 2000 || !enemy.canShoot) return;
enemy.lastShot = now;
shots.push({
x: enemy.x + enemy.w/2 - 3,
y: enemy.y + enemy.h,
w: 6,
h: 15,
color: '#ef4444',
speed: -5,
damage: 1,
isEnemy: true
});
}
function bossShoot() {
const now = Date.now();
if (now - boss.lastShot < 1000) return;
boss.lastShot = now;
// Pattern based on boss phase
if (boss.phase === 1) {
// Single shot
shots.push({
x: boss.x + boss.w/2 - 5,
y: boss.y + boss.h,
w: 10,
h: 25,
color: '#ef4444',
speed: -4,
damage: 2,
isEnemy: true
});
} else if (boss.phase === 2) {
// Triple shot
for (let i = 0; i < 3; i++) {
shots.push({
x: boss.x + boss.w/2 - 5 + (i * 15) - 15,
y: boss.y + boss.h,
w: 10,
h: 25,
color: '#ef4444',
speed: -4,
damage: 2,
isEnemy: true,
angle: (i - 1) * 0.2
});
}
} else {
// Spread shot
for (let i = 0; i < 5; i++) {
shots.push({
x: boss.x + boss.w/2 - 5 + (i * 15) - 30,
y: boss.y + boss.h,
w: 10,
h: 25,
color: '#ef4444',
speed: -4,
damage: 2,
isEnemy: true,
angle: (i - 2) * 0.15
});
}
}
}
function checkCollisions() {
// Player with enemies
enemies.forEach((enemy, i) => {
if (collision(player, enemy)) {
if (player.hasShield) {
player.hasShield = false;
player.shieldTimer = 0;
} else {
lives--;
if (lives <= 0) {
gameOver = true;
}
}
createExplosion(enemy.x + enemy.w/2, enemy.y + enemy.h/2);
enemies.splice(i, 1);
updateUI();
}
});
// Player with boss
if (boss && collision(player, boss)) {
if (player.hasShield) {
player.hasShield = false;
player.shieldTimer = 0;
} else {
lives -= 2;
if (lives <= 0) {
gameOver = true;
}
}
createExplosion(boss.x + boss.w/2, boss.y + boss.h/2, 2);
updateUI();
}
// Player with enemy shots
shots.forEach((shot, i) => {
if (shot.isEnemy && collision(player, shot)) {
if (player.hasShield) {
player.hasShield = false;
player.shieldTimer = 0;
} else {
lives--;
if (lives <= 0) {
gameOver = true;
}
}
shots.splice(i, 1);
updateUI();
}
});
// Player with powerups
powerups.forEach((powerup, i) => {
if (collision(player, powerup)) {
activatePowerup(powerup);
powerups.splice(i, 1);
}
});
// Player shots with enemies
shots.forEach((shot, i) => {
if (!shot.isEnemy) {
enemies.forEach((enemy, j) => {
if (collision(shot, enemy)) {
enemy.health -= shot.damage;
shots.splice(i, 1);
if (enemy.health <= 0) {
createExplosion(enemy.x + enemy.w/2, enemy.y + enemy.h/2);
enemies.splice(j, 1);
score += 10 * level;
enemiesDefeated++;
// Chance to drop powerup
if (Math.random() < 0.1) {
spawnPowerup();
}
}
updateUI();
}
});
// Player shots with boss
if (boss && collision(shot, boss)) {
boss.health -= shot.damage;
shots.splice(i, 1);
updateBossHealth();
// Boss phase changes
if (boss.health <= boss.maxHealth * 0.66 && boss.phase === 1) {
boss.phase = 2;
boss.speed *= 1.2;
} else if (boss.health <= boss.maxHealth * 0.33 && boss.phase === 2) {
boss.phase = 3;
boss.speed *= 1.2;
} else if (boss.health <= 0) {
defeatBoss();
}
}
}
});
}
function collision(a, b) {
return a.x < b.x + b.w &&
a.x + a.w > b.x &&
a.y < b.y + b.h &&
a.y + a.h > b.y;
}
function updateGameObjects() {
// Update player
if (keys['ArrowLeft'] || keys['a']) player.x -= player.speed;
if (keys['ArrowRight'] || keys['d']) player.x += player.speed;
if (keys[' ']) shoot();
if (keys['Shift']) specialAttack();
// Keep player in bounds
player.x = Math.max(0, Math.min(canvas.width - player.w, player.x));
// Update special charge
if (player.specialCharge < player.maxSpecial) {
player.specialCharge += 0.2;
}
// Update shield timer
if (player.hasShield) {
player.shieldTimer -= 16; // Assuming 60fps
if (player.shieldTimer <= 0) {
player.hasShield = false;
}
}
// Update rapid fire timer
if (player.rapidFire) {
player.rapidFireTimer -= 16;
if (player.rapidFireTimer <= 0) {
player.rapidFire = false;
player.fireRate = 300;
}
}
// Update shots
shots.forEach((shot, i) => {
// Apply angle if exists
if (shot.angle) {
shot.x += Math.sin(shot.angle) * 3;
}
shot.y -= shot.speed;
// Remove if out of bounds
if (shot.y < -shot.h || shot.y > canvas.height) {
shots.splice(i, 1);
}
});
// Update enemies
enemies.forEach((enemy, i) => {
enemy.y += enemy.speed;
// Enemy shooting
if (enemy.canShoot && Math.random() < 0.02) {
enemyShoot(enemy);
}
// Remove if out of bounds
if (enemy.y > canvas.height + enemy.h) {
enemies.splice(i, 1);
}
});
// Update boss
if (boss) {
// Boss movement pattern
boss.moveTimer += 1;
if (boss.pattern === 'down') {
boss.y += boss.speed;
if (boss.y > 50) {
boss.pattern = 'left';
boss.moveTimer = 0;
}
} else if (boss.pattern === 'left') {
boss.x -= boss.speed;
if (boss.moveTimer > 120 || boss.x < 50) {
boss.pattern = 'right';
boss.moveTimer = 0;
}
} else if (boss.pattern === 'right') {
boss.x += boss.speed;
if (boss.moveTimer > 120 || boss.x > canvas.width - boss.w - 50) {
boss.pattern = 'left';
boss.moveTimer = 0;
}
}
// Boss shooting
if (Math.random() < 0.03) {
bossShoot();
}
}
// Update powerups
powerups.forEach((powerup, i) => {
powerup.y += powerup.speed;
// Remove if out of bounds
if (powerup.y > canvas.height + powerup.h) {
powerups.splice(i, 1);
}
});
// Update particles
particles.forEach((particle, i) => {
particle.x += particle.speedX;
particle.y += particle.speedY;
particle.life--;
if (particle.life <= 0) {
particles.splice(i, 1);
}
});
}
function drawBackground() {
// Dark space background
ctx.fillStyle = 'rgba(10, 10, 20, 0.8)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Draw parallax stars
ctx.fillStyle = 'white';
parallaxStars.forEach(star => {
ctx.globalAlpha = star.alpha;
star.y += star.speed;
if (star.y > canvas.height) {
star.y = 0;
star.x = Math.random() * canvas.width;
}
ctx.fillRect(star.x, star.y, star.size, star.size);
});
ctx.globalAlpha = 1;
}
function drawPlayer() {
// Draw ship body
ctx.fillStyle = '#3b82f6';
ctx.beginPath();
ctx.moveTo(player.x + player.w / 2, player.y);
ctx.lineTo(player.x + player.w, player.y + player.h);
ctx.lineTo(player.x, player.y + player.h);
ctx.closePath();
ctx.fill();
// Draw ship details
ctx.fillStyle = '#93c5fd';
ctx.fillRect(player.x + player.w / 2 - 5, player.y + 15, 10, 15);
// Draw engine glow
if (keys['ArrowLeft'] || keys['ArrowRight'] || keys['a'] || keys['d']) {
ctx.fillStyle = '#f59e0b';
ctx.beginPath();
ctx.moveTo(player.x + player.w / 2 - 10, player.y + player.h);
ctx.lineTo(player.x + player.w / 2 + 10, player.y + player.h);
ctx.lineTo(player.x + player.w / 2, player.y + player.h + 15);
ctx.closePath();
ctx.fill();
}
// Draw shield if active
if (player.hasShield) {
ctx.strokeStyle = 'rgba(59, 130, 246, 0.7)';
ctx.lineWidth = 2;
ctx.setLineDash([5, 5]);
ctx.beginPath();
ctx.arc(player.x + player.w/2, player.y + player.h/2, player.w + 10, 0, Math.PI * 2);
ctx.stroke();
ctx.setLineDash([]);
}
}
function drawShots() {
shots.forEach(shot => {
ctx.fillStyle = shot.color;
ctx.fillRect(shot.x, shot.y, shot.w, shot.h);
// Add glow to special shots
if (shot.damage > 1) {
ctx.shadowColor = shot.color;
ctx.shadowBlur = 10;
ctx.fillRect(shot.x, shot.y, shot.w, shot.h);
ctx.shadowBlur = 0;
}
});
}
function drawEnemies() {
enemies.forEach(enemy => {
ctx.fillStyle = enemy.color;
ctx.beginPath();
ctx.moveTo(enemy.x + enemy.w / 2, enemy.y);
ctx.lineTo(enemy.x + enemy.w, enemy.y + enemy.h);
ctx.lineTo(enemy.x, enemy.y + enemy.h);
ctx.closePath();
ctx.fill();
// Draw health for tank enemies
if (enemy.type === 'tank' && enemy.health > 1) {
ctx.fillStyle = 'white';
ctx.font = '10px Arial';
ctx.fillText(`${enemy.health}`, enemy.x + enemy.w/2 - 5, enemy.y + enemy.h/2 + 3);
}
});
// Draw boss
if (boss) {
ctx.fillStyle = boss.color;
ctx.beginPath();
ctx.moveTo(boss.x + boss.w / 2, boss.y);
ctx.lineTo(boss.x + boss.w, boss.y + boss.h);
ctx.lineTo(boss.x, boss.y + boss.h);
ctx.closePath();
ctx.fill();
// Draw boss details
ctx.fillStyle = '#fca5a5';
ctx.fillRect(boss.x + boss.w/2 - 20, boss.y + 30, 40, 10);
ctx.fillRect(boss.x + boss.w/2 - 15, boss.y + 50, 30, 20);
}
}
function drawPowerups() {
powerups.forEach(powerup => {
ctx.fillStyle = powerup.color;
ctx.beginPath();
ctx.arc(powerup.x + powerup.w/2, powerup.y + powerup.h/2, powerup.w/2, 0, Math.PI * 2);
ctx.fill();
// Add icon based on type
ctx.fillStyle = 'white';
ctx.font = '12px Arial';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
if (powerup.type === 'health') {
ctx.fillText('+', powerup.x + powerup.w/2, powerup.y + powerup.h/2 + 1);
} else if (powerup.type === 'shield') {
ctx.fillText('⛉', powerup.x + powerup.w/2, powerup.y + powerup.h/2 + 1);
} else if (powerup.type === 'rapidfire') {
ctx.fillText('»', powerup.x + powerup.w/2, powerup.y + powerup.h/2 + 1);
} else {
ctx.fillText('!', powerup.x + powerup.w/2, powerup.y + powerup.h/2 + 1);
}
});
}
function drawParticles() {
particles.forEach(particle => {
ctx.globalAlpha = particle.life / 60;
ctx.fillStyle = particle.color;
ctx.fillRect(particle.x, particle.y, particle.size, particle.size);
});
ctx.globalAlpha = 1;
}
function drawUI() {
// Draw special charge bar
const chargeWidth = (player.specialCharge / player.maxSpecial) * 100;
ctx.fillStyle = '#3b82f6';
ctx.fillRect(canvas.width - 110, 10, chargeWidth, 10);
ctx.strokeStyle = 'white';
ctx.strokeRect(canvas.width - 110, 10, 100, 10);
// Draw special charge text
ctx.fillStyle = 'white';
ctx.font = '12px Arial';
ctx.fillText('SPECIAL', canvas.width - 105, 20);
// Draw rapid fire indicator
if (player.rapidFire) {
ctx.fillStyle = 'rgba(245, 158, 11, 0.3)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
}
// =============================================
// GAME LOOP
// =============================================
function gameLoop() {
if (gameOver) {
gameOverScreen.classList.remove('hidden');
return;
}
if (gamePaused) {
requestAnimationFrame(gameLoop);
return;
}
// Clear canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Update game state
spawnEnemy();
spawnPowerup();
updateGameObjects();
checkCollisions();
// Draw everything
drawBackground();
drawParticles();
drawEnemies();
drawShots();
drawPowerups();
drawPlayer();
drawUI();
// Continue the loop
requestAnimationFrame(gameLoop);
}
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Xacodavt/19-de-mar-o-de-2025" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |