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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Space Invaders</title>
|
| 7 |
+
<style>
|
| 8 |
+
body {
|
| 9 |
+
margin: 0;
|
| 10 |
+
padding: 0;
|
| 11 |
+
background: #000;
|
| 12 |
+
display: flex;
|
| 13 |
+
justify-content: center;
|
| 14 |
+
align-items: center;
|
| 15 |
+
min-height: 100vh;
|
| 16 |
+
font-family: 'Courier New', monospace;
|
| 17 |
+
color: #00ff00;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
#gameContainer {
|
| 21 |
+
text-align: center;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
canvas {
|
| 25 |
+
border: 2px solid #00ff00;
|
| 26 |
+
background: #000;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
#ui {
|
| 30 |
+
margin-top: 10px;
|
| 31 |
+
font-size: 18px;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
#instructions {
|
| 35 |
+
margin-top: 10px;
|
| 36 |
+
font-size: 14px;
|
| 37 |
+
opacity: 0.8;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
#gameOver {
|
| 41 |
+
position: absolute;
|
| 42 |
+
top: 50%;
|
| 43 |
+
left: 50%;
|
| 44 |
+
transform: translate(-50%, -50%);
|
| 45 |
+
font-size: 32px;
|
| 46 |
+
color: #ff0000;
|
| 47 |
+
display: none;
|
| 48 |
+
}
|
| 49 |
+
</style>
|
| 50 |
+
</head>
|
| 51 |
+
<body>
|
| 52 |
+
<div id="gameContainer">
|
| 53 |
+
<canvas id="gameCanvas" width="800" height="600"></canvas>
|
| 54 |
+
<div id="ui">
|
| 55 |
+
<span>Score: <span id="score">0</span></span>
|
| 56 |
+
<span style="margin-left: 50px;">Lives: <span id="lives">3</span></span>
|
| 57 |
+
</div>
|
| 58 |
+
<div id="instructions">
|
| 59 |
+
Use ARROW KEYS or WASD to move in all directions • SPACEBAR for auto-targeted shooting • R to restart
|
| 60 |
+
</div>
|
| 61 |
+
<div id="gameOver">
|
| 62 |
+
GAME OVER<br>
|
| 63 |
+
<span style="font-size: 16px;">Press R to restart</span>
|
| 64 |
+
</div>
|
| 65 |
+
</div>
|
| 66 |
+
|
| 67 |
+
<script>
|
| 68 |
+
const canvas = document.getElementById('gameCanvas');
|
| 69 |
+
const ctx = canvas.getContext('2d');
|
| 70 |
+
const scoreElement = document.getElementById('score');
|
| 71 |
+
const livesElement = document.getElementById('lives');
|
| 72 |
+
const gameOverElement = document.getElementById('gameOver');
|
| 73 |
+
|
| 74 |
+
// Game state
|
| 75 |
+
let gameState = {
|
| 76 |
+
score: 0,
|
| 77 |
+
lives: 3,
|
| 78 |
+
gameRunning: true,
|
| 79 |
+
keys: {}
|
| 80 |
+
};
|
| 81 |
+
|
| 82 |
+
// Player
|
| 83 |
+
const player = {
|
| 84 |
+
x: canvas.width / 2 - 20,
|
| 85 |
+
y: canvas.height - 60,
|
| 86 |
+
width: 40,
|
| 87 |
+
height: 30,
|
| 88 |
+
speed: 5
|
| 89 |
+
};
|
| 90 |
+
|
| 91 |
+
// Arrays for game objects
|
| 92 |
+
let bullets = [];
|
| 93 |
+
let invaders = [];
|
| 94 |
+
let invaderBullets = [];
|
| 95 |
+
|
| 96 |
+
// Game settings
|
| 97 |
+
const bulletSpeed = 7;
|
| 98 |
+
const invaderBulletSpeed = 3;
|
| 99 |
+
const invaderSpeed = 1;
|
| 100 |
+
let invaderDirection = 1;
|
| 101 |
+
let invaderDropDistance = 30;
|
| 102 |
+
|
| 103 |
+
// Initialize invaders
|
| 104 |
+
function createInvaders() {
|
| 105 |
+
invaders = [];
|
| 106 |
+
for (let row = 0; row < 5; row++) {
|
| 107 |
+
for (let col = 0; col < 10; col++) {
|
| 108 |
+
invaders.push({
|
| 109 |
+
x: col * 60 + 80,
|
| 110 |
+
y: row * 50 + 50,
|
| 111 |
+
width: 40,
|
| 112 |
+
height: 30,
|
| 113 |
+
alive: true
|
| 114 |
+
});
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
// Input handling
|
| 120 |
+
document.addEventListener('keydown', (e) => {
|
| 121 |
+
gameState.keys[e.code] = true;
|
| 122 |
+
|
| 123 |
+
if (e.code === 'Space') {
|
| 124 |
+
e.preventDefault();
|
| 125 |
+
shoot();
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
if (e.code === 'KeyR') {
|
| 129 |
+
restartGame();
|
| 130 |
+
}
|
| 131 |
+
});
|
| 132 |
+
|
| 133 |
+
document.addEventListener('keyup', (e) => {
|
| 134 |
+
gameState.keys[e.code] = false;
|
| 135 |
+
});
|
| 136 |
+
|
| 137 |
+
// Player movement
|
| 138 |
+
function updatePlayer() {
|
| 139 |
+
if (gameState.keys['ArrowLeft'] || gameState.keys['KeyA']) {
|
| 140 |
+
player.x = Math.max(0, player.x - player.speed);
|
| 141 |
+
}
|
| 142 |
+
if (gameState.keys['ArrowRight'] || gameState.keys['KeyD']) {
|
| 143 |
+
player.x = Math.min(canvas.width - player.width, player.x + player.speed);
|
| 144 |
+
}
|
| 145 |
+
if (gameState.keys['ArrowUp'] || gameState.keys['KeyW']) {
|
| 146 |
+
player.y = Math.max(0, player.y - player.speed);
|
| 147 |
+
}
|
| 148 |
+
if (gameState.keys['ArrowDown'] || gameState.keys['KeyS']) {
|
| 149 |
+
player.y = Math.min(canvas.height - player.height, player.y + player.speed);
|
| 150 |
+
}
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
// Shooting with auto-targeting
|
| 154 |
+
function shoot() {
|
| 155 |
+
if (!gameState.gameRunning) return;
|
| 156 |
+
|
| 157 |
+
// Find nearest alive invader
|
| 158 |
+
let nearestInvader = null;
|
| 159 |
+
let minDistance = Infinity;
|
| 160 |
+
|
| 161 |
+
for (let invader of invaders) {
|
| 162 |
+
if (invader.alive) {
|
| 163 |
+
const distance = Math.sqrt(
|
| 164 |
+
Math.pow(invader.x + invader.width/2 - (player.x + player.width/2), 2) +
|
| 165 |
+
Math.pow(invader.y + invader.height/2 - player.y, 2)
|
| 166 |
+
);
|
| 167 |
+
|
| 168 |
+
if (distance < minDistance) {
|
| 169 |
+
minDistance = distance;
|
| 170 |
+
nearestInvader = invader;
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
if (nearestInvader) {
|
| 176 |
+
// Calculate direction to target
|
| 177 |
+
const dx = (nearestInvader.x + nearestInvader.width/2) - (player.x + player.width/2);
|
| 178 |
+
const dy = (nearestInvader.y + nearestInvader.height/2) - player.y;
|
| 179 |
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
| 180 |
+
|
| 181 |
+
bullets.push({
|
| 182 |
+
x: player.x + player.width / 2 - 2,
|
| 183 |
+
y: player.y,
|
| 184 |
+
width: 4,
|
| 185 |
+
height: 10,
|
| 186 |
+
vx: (dx / distance) * bulletSpeed,
|
| 187 |
+
vy: (dy / distance) * bulletSpeed
|
| 188 |
+
});
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
// Update bullets
|
| 193 |
+
function updateBullets() {
|
| 194 |
+
bullets = bullets.filter(bullet => {
|
| 195 |
+
bullet.x += bullet.vx;
|
| 196 |
+
bullet.y += bullet.vy;
|
| 197 |
+
|
| 198 |
+
// Remove bullets that go off screen
|
| 199 |
+
return bullet.x > -bullet.width &&
|
| 200 |
+
bullet.x < canvas.width + bullet.width &&
|
| 201 |
+
bullet.y > -bullet.height &&
|
| 202 |
+
bullet.y < canvas.height + bullet.height;
|
| 203 |
+
});
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
// Update invader bullets
|
| 207 |
+
function updateInvaderBullets() {
|
| 208 |
+
invaderBullets = invaderBullets.filter(bullet => {
|
| 209 |
+
bullet.y += bullet.speed;
|
| 210 |
+
return bullet.y < canvas.height;
|
| 211 |
+
});
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
// Invader shooting
|
| 215 |
+
function invaderShoot() {
|
| 216 |
+
if (Math.random() < 0.002 && invaders.some(inv => inv.alive)) {
|
| 217 |
+
const aliveInvaders = invaders.filter(inv => inv.alive);
|
| 218 |
+
const shooter = aliveInvaders[Math.floor(Math.random() * aliveInvaders.length)];
|
| 219 |
+
|
| 220 |
+
invaderBullets.push({
|
| 221 |
+
x: shooter.x + shooter.width / 2 - 2,
|
| 222 |
+
y: shooter.y + shooter.height,
|
| 223 |
+
width: 4,
|
| 224 |
+
height: 10,
|
| 225 |
+
speed: invaderBulletSpeed
|
| 226 |
+
});
|
| 227 |
+
}
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
// Update invaders
|
| 231 |
+
function updateInvaders() {
|
| 232 |
+
let shouldDrop = false;
|
| 233 |
+
|
| 234 |
+
// Check if any invader hit the edge
|
| 235 |
+
for (let invader of invaders) {
|
| 236 |
+
if (!invader.alive) continue;
|
| 237 |
+
|
| 238 |
+
if ((invader.x <= 0 && invaderDirection === -1) ||
|
| 239 |
+
(invader.x + invader.width >= canvas.width && invaderDirection === 1)) {
|
| 240 |
+
shouldDrop = true;
|
| 241 |
+
break;
|
| 242 |
+
}
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
// Move invaders
|
| 246 |
+
for (let invader of invaders) {
|
| 247 |
+
if (!invader.alive) continue;
|
| 248 |
+
|
| 249 |
+
if (shouldDrop) {
|
| 250 |
+
invader.y += invaderDropDistance;
|
| 251 |
+
} else {
|
| 252 |
+
invader.x += invaderSpeed * invaderDirection;
|
| 253 |
+
}
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
if (shouldDrop) {
|
| 257 |
+
invaderDirection *= -1;
|
| 258 |
+
}
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
// Collision detection
|
| 262 |
+
function checkCollisions() {
|
| 263 |
+
// Bullet vs invaders
|
| 264 |
+
for (let i = bullets.length - 1; i >= 0; i--) {
|
| 265 |
+
const bullet = bullets[i];
|
| 266 |
+
|
| 267 |
+
for (let j = 0; j < invaders.length; j++) {
|
| 268 |
+
const invader = invaders[j];
|
| 269 |
+
|
| 270 |
+
if (invader.alive &&
|
| 271 |
+
bullet.x < invader.x + invader.width &&
|
| 272 |
+
bullet.x + bullet.width > invader.x &&
|
| 273 |
+
bullet.y < invader.y + invader.height &&
|
| 274 |
+
bullet.y + bullet.height > invader.y) {
|
| 275 |
+
|
| 276 |
+
invader.alive = false;
|
| 277 |
+
bullets.splice(i, 1);
|
| 278 |
+
gameState.score += 10;
|
| 279 |
+
break;
|
| 280 |
+
}
|
| 281 |
+
}
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
// Invader bullets vs player
|
| 285 |
+
for (let i = invaderBullets.length - 1; i >= 0; i--) {
|
| 286 |
+
const bullet = invaderBullets[i];
|
| 287 |
+
|
| 288 |
+
if (bullet.x < player.x + player.width &&
|
| 289 |
+
bullet.x + bullet.width > player.x &&
|
| 290 |
+
bullet.y < player.y + player.height &&
|
| 291 |
+
bullet.y + bullet.height > player.y) {
|
| 292 |
+
|
| 293 |
+
invaderBullets.splice(i, 1);
|
| 294 |
+
gameState.lives--;
|
| 295 |
+
|
| 296 |
+
if (gameState.lives <= 0) {
|
| 297 |
+
gameOver();
|
| 298 |
+
}
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
// Check if invaders reached player
|
| 303 |
+
for (let invader of invaders) {
|
| 304 |
+
if (invader.alive && invader.y + invader.height >= player.y) {
|
| 305 |
+
gameOver();
|
| 306 |
+
return;
|
| 307 |
+
}
|
| 308 |
+
}
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
// Game over
|
| 312 |
+
function gameOver() {
|
| 313 |
+
gameState.gameRunning = false;
|
| 314 |
+
gameOverElement.style.display = 'block';
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
// Restart game
|
| 318 |
+
function restartGame() {
|
| 319 |
+
gameState.score = 0;
|
| 320 |
+
gameState.lives = 3;
|
| 321 |
+
gameState.gameRunning = true;
|
| 322 |
+
bullets = [];
|
| 323 |
+
invaderBullets = [];
|
| 324 |
+
invaderDirection = 1;
|
| 325 |
+
player.x = canvas.width / 2 - 20;
|
| 326 |
+
createInvaders();
|
| 327 |
+
gameOverElement.style.display = 'none';
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
// Check win condition
|
| 331 |
+
function checkWin() {
|
| 332 |
+
if (invaders.every(inv => !inv.alive)) {
|
| 333 |
+
// Create new wave
|
| 334 |
+
createInvaders();
|
| 335 |
+
gameState.score += 100; // Bonus for clearing wave
|
| 336 |
+
}
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
// Drawing functions
|
| 340 |
+
function drawPlayer() {
|
| 341 |
+
ctx.fillStyle = '#00ff00';
|
| 342 |
+
ctx.fillRect(player.x, player.y, player.width, player.height);
|
| 343 |
+
|
| 344 |
+
// Simple ship design
|
| 345 |
+
ctx.fillStyle = '#ffffff';
|
| 346 |
+
ctx.fillRect(player.x + 15, player.y - 5, 10, 5);
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
function drawBullets() {
|
| 350 |
+
ctx.fillStyle = '#ffff00';
|
| 351 |
+
for (let bullet of bullets) {
|
| 352 |
+
ctx.fillRect(bullet.x, bullet.y, bullet.width, bullet.height);
|
| 353 |
+
}
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
function drawInvaderBullets() {
|
| 357 |
+
ctx.fillStyle = '#ff0000';
|
| 358 |
+
for (let bullet of invaderBullets) {
|
| 359 |
+
ctx.fillRect(bullet.x, bullet.y, bullet.width, bullet.height);
|
| 360 |
+
}
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
function drawInvaders() {
|
| 364 |
+
ctx.fillStyle = '#ff00ff';
|
| 365 |
+
for (let invader of invaders) {
|
| 366 |
+
if (invader.alive) {
|
| 367 |
+
ctx.fillRect(invader.x, invader.y, invader.width, invader.height);
|
| 368 |
+
|
| 369 |
+
// Simple invader design
|
| 370 |
+
ctx.fillStyle = '#ffffff';
|
| 371 |
+
ctx.fillRect(invader.x + 10, invader.y + 5, 5, 5);
|
| 372 |
+
ctx.fillRect(invader.x + 25, invader.y + 5, 5, 5);
|
| 373 |
+
ctx.fillRect(invader.x + 15, invader.y + 15, 10, 5);
|
| 374 |
+
ctx.fillStyle = '#ff00ff';
|
| 375 |
+
}
|
| 376 |
+
}
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
function drawUI() {
|
| 380 |
+
scoreElement.textContent = gameState.score;
|
| 381 |
+
livesElement.textContent = gameState.lives;
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
// Main game loop
|
| 385 |
+
function gameLoop() {
|
| 386 |
+
// Clear canvas
|
| 387 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
| 388 |
+
|
| 389 |
+
if (gameState.gameRunning) {
|
| 390 |
+
// Update
|
| 391 |
+
updatePlayer();
|
| 392 |
+
updateBullets();
|
| 393 |
+
updateInvaderBullets();
|
| 394 |
+
updateInvaders();
|
| 395 |
+
invaderShoot();
|
| 396 |
+
checkCollisions();
|
| 397 |
+
checkWin();
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
// Draw
|
| 401 |
+
drawPlayer();
|
| 402 |
+
drawBullets();
|
| 403 |
+
drawInvaderBullets();
|
| 404 |
+
drawInvaders();
|
| 405 |
+
drawUI();
|
| 406 |
+
|
| 407 |
+
requestAnimationFrame(gameLoop);
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
// Initialize game
|
| 411 |
+
createInvaders();
|
| 412 |
+
gameLoop();
|
| 413 |
+
</script>
|
| 414 |
+
</body>
|
| 415 |
+
</html>
|