Meta Description" name="description" />
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<style>
body { margin: 0; overflow: hidden; background: #1a1a1a; font-family: sans-serif; }
canvas { display: block; touch-action: none; }
</style>
</head>
<body>
<canvas id="game"></canvas>
<script>
const canvas = document.getElementById('game');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
const player = { x: canvas.width / 2 - 25, y: canvas.height - 80, w: 50, h: 50 };
const bullets = [], enemies = [];
let score = 0;
// Touch Handling
window.addEventListener('touchstart', e => {
const touchX = e.touches[0].clientX;
player.x = touchX < canvas.width / 2 ? player.x - 40 : player.x + 40;
});
function spawn() { enemies.push({ x: Math.random() * (canvas.width - 40), y: -40, w: 40, h: 40 }); }
setInterval(spawn, 800);
setInterval(() => bullets.push({ x: player.x + 20, y: player.y, w: 10, h: 20 }), 300);
function loop() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = '#00ffcc';
ctx.fillRect(player.x, player.y, player.w, player.h);
bullets.forEach((b, i) => {
b.y -= 10;
ctx.fillStyle = 'white';
ctx.fillRect(b.x, b.y, b.w, b.h);
if (b.y < 0) bullets.splice(i, 1);
});
enemies.forEach((e, ei) => {
e.y += 4;
ctx.fillStyle = '#ff4444';
ctx.fillRect(e.x, e.y, e.w, e.h);
bullets.forEach((b, bi) => {
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(ei, 1);
bullets.splice(bi, 1);
score++;
}
});
if (e.y > canvas.height) { alert("Score: " + score); location.reload(); }
});
ctx.fillStyle = "white";
ctx.font = "20px Arial";
ctx.fillText("Score: " + score, 20, 40);
requestAnimationFrame(loop);
}
loop();
</script>
</body>
</html>
1
1
2KB
2KB
188.0ms
208.0ms
188.0ms