Meta Description" name="description" />
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Aether Runner - Mini Game</title>
<style>
body {
margin: 0;
background: #111;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
font-family: sans-serif;
color: #eee;
}
canvas {
border: 2px solid #444;
background: #1a1a2e;
box-shadow: 0 0 20px rgba(0,0,0,0.8);
}
p { margin-top: 10px; font-size: 14px; color: #aaa; }
</style>
</head>
<body>
<canvas id="gameCanvas" width="600" height="400"></canvas>
<p>Controls: <b>W, A, S, D</b> ya <b>Arrow Keys</b> se move karein | <b>Spacebar</b> se shoot karein</p>
<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
let keys = {};
window.addEventListener('keydown', e => { keys[e.code] = true; });
window.addEventListener('keyup', e => { keys[e.code] = false; });
const player = {
x: 300,
y: 350,
w: 24,
h: 24,
speed: 4,
cooldown: 0
};
let bullets = [];
let enemies = [];
let score = 0;
let gameOver = false;
function spawnEnemy() {
if (gameOver) return;
enemies.push({
x: Math.random() * (canvas.width - 24),
y: -20,
w: 20,
h: 20,
speed: 1.5 + Math.random() * 2
});
}
setInterval(spawnEnemy, 900);
function update() {
if (gameOver) return;
// Player Movement
if ((keys['ArrowLeft'] || keys['KeyA']) && player.x > 0) player.x -= player.speed;
if ((keys['ArrowRight'] || keys['KeyD']) && player.x + player.w < canvas.width) player.x += player.speed;
if ((keys['ArrowUp'] || keys['KeyW']) && player.y > 0) player.y -= player.speed;
if ((keys['ArrowDown'] || keys['KeyS']) && player.y + player.h < canvas.height) player.y += player.speed;
// Shooting
if (player.cooldown > 0) player.cooldown--;
if (keys['Space'] && player.cooldown === 0) {
bullets.push({ x: player.x + player.w / 2 - 3, y: player.y, w: 6, h: 12, speed: 7 });
player.cooldown = 15;
}
// Update Bullets
for (let i = bullets.length - 1; i >= 0; i--) {
bullets[i].y -= bullets[i].speed;
if (bullets[i].y < -20) bullets.splice(i, 1);
}
// Update Enemies
for (let i = enemies.length - 1; i >= 0; i--) {
let e = enemies[i];
e.y += e.speed;
// Player Collision
if (
player.x < e.x + e.w &&
player.x + player.w > e.x &&
player.y < e.y + e.h &&
player.y + player.h > e.y
) {
gameOver = true;
}
// Bullet Collision
for (let j = bullets.length - 1; j >= 0; j--) {
let b = bullets[j];
if (
b.x < e.x + e.w &&
b.x + b.w > e.x &&
b.y < e.y + e.h &&
b.y + b.h > e.y
) {
enemies.splice(i, 1);
bullets.splice(j, 1);
score += 10;
break;
}
}
// Off-screen remove
if (e && e.y > canvas.height) {
enemies.splice(i, 1);
}
}
}
function draw() {
// Background Clear
ctx.fillStyle = '#16213e';
ctx.fillRect(0, 0, canvas.width, canvas.height);
if (gameOver) {
ctx.fillStyle = '#e94560';
ctx.font = '32px sans-serif';
ctx.textAlign = 'center';
ctx.fillText('GAME OVER', canvas.width / 2, canvas.height / 2 - 10);
ctx.fillStyle = '#fff';
ctx.font = '18px sans-serif';
ctx.fillText(`Final Score: ${score}`, canvas.width / 2, canvas.height / 2 + 25);
ctx.font = '14px sans-serif';
ctx.fillText('Restart karne ke liye page refresh karein', canvas.width / 2, canvas.height / 2 + 60);
return;
}
// Player Draw (Cyan Ship)
ctx.fillStyle = '#00fff5';
ctx.fillRect(player.x, player.y, player.w, player.h);
// Bullets Draw (Yellow)
ctx.fillStyle = '#ffe600';
bullets.forEach(b => ctx.fillRect(b.x, b.y, b.w, b.h));
// Enemies Draw (Red)
ctx.fillStyle = '#e94560';
enemies.forEach(e => ctx.fillRect(e.x, e.y, e.w, e.h));
// Score Draw
ctx.fillStyle = '#ffffff';
ctx.font = '16px sans-serif';
ctx.textAlign = 'left';
ctx.fillText(`Score: ${score}`, 15, 25);
}
function loop() {
update();
draw();
requestAnimationFrame(loop);
}
loop();
</script>
</body>
</html>
1
1
5KB
5KB
104.0ms
196.0ms
104.0ms