Meta Description" name="description" />
<!DOCTYPE html>
<html lang="hi">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>Mobile Car Shooter</title>
<style>
body {
margin: 0;
background: #222;
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
color: white;
flex-direction: column;
overflow: hidden;
}
#gameCanvas {
background: #333;
border: 2px solid #fff;
max-width: 100%;
max-height: 70vh;
}
.controls {
display: flex;
justify-content: space-around;
width: 100%;
max-width: 400px;
margin-top: 15px;
}
.btn {
background: #555;
color: white;
padding: 15px 25px;
font-size: 20px;
border: 2px solid #fff;
border-radius: 10px;
user-select: none;
-webkit-user-select: none;
}
.shoot-btn {
background: red;
}
</style>
</head>
<body>
<h3 style="margin:5px;">कार शूटर गेम</h3>
<canvas id="gameCanvas" width="360" height="500"></canvas>
<!-- मोबाइल बटन्स -->
<div class="controls">
<div class="btn" id="leftBtn">◀️</div>
<div class="btn shoot-btn" id="shootBtn">🔥 SHOOT</div>
<div class="btn" id="rightBtn">▶️</div>
</div>
<script>
const canvas = document.getElementById("gameCanvas");
const ctx = canvas.getContext("2d");
const player = { x: 160, y: 400, width: 40, height: 70, speed: 6, color: "red" };
let bullets = [];
let enemies = [];
let score = 0;
let gameOver = false;
// टच इवेंट्स के लिए वेरिएबल्स
let moveLeft = false;
let moveRight = false;
// बटन्स कंट्रोल
const leftBtn = document.getElementById("leftBtn");
const rightBtn = document.getElementById("rightBtn");
const shootBtn = document.getElementById("shootBtn");
leftBtn.addEventListener("touchstart", () => moveLeft = true);
leftBtn.addEventListener("touchend", () => moveLeft = false);
rightBtn.addEventListener("touchstart", () => moveRight = true);
rightBtn.addEventListener("touchend", () => moveRight = false);
shootBtn.addEventListener("touchstart", () => {
if (!gameOver) {
bullets.push({ x: player.x + 17, y: player.y, width: 6, height: 15, speed: 8 });
} else {
// रीस्टार्ट
bullets = []; enemies = []; score = 0; player.x = 160; gameOver = false; update();
}
});
function spawnEnemy() {
if (Math.random() < 0.03 && !gameOver) {
let enemyX = Math.random() * (canvas.width - 40);
enemies.push({ x: enemyX, y: -70, width: 40, height: 70, speed: 4, color: "blue" });
}
}
function update() {
if (gameOver) {
ctx.fillStyle = "rgba(0,0,0,0.8)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "white";
ctx.font = "24px Arial";
ctx.fillText("गेम ओवर!", 130, 200);
ctx.font = "18px Arial";
ctx.fillText("स्कोर: " + score, 150, 240);
ctx.fillText("फिर खेलने के लिए SHOOT दबाएं", 60, 290);
return;
}
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (moveLeft && player.x > 0) player.x -= player.speed;
if (moveRight && player.x < canvas.width - player.width) player.x += player.speed;
ctx.fillStyle = player.color;
ctx.fillRect(player.x, player.y, player.width, player.height);
// गन डिजाइन
ctx.fillStyle = "silver";
ctx.fillRect(player.x + 18, player.y - 10, 4, 10);
// बुलेट्स
ctx.fillStyle = "yellow";
bullets.forEach((bullet, index) => {
bullet.y -= bullet.speed;
ctx.fillRect(bullet.x, bullet.y, bullet.width, bullet.height);
if (bullet.y < 0) bullets.splice(index, 1);
});
// दुश्मन
spawnEnemy();
enemies.forEach((enemy, eIndex) => {
enemy.y += enemy.speed;
ctx.fillStyle = enemy.color;
ctx.fillRect(enemy.x, enemy.y, enemy.width, enemy.height);
if (enemy.x < player.x + player.width && enemy.x + enemy.width > player.x &&
enemy.y < player.y + player.height && enemy.y + enemy.height > player.y) {
gameOver = true;
}
bullets.forEach((bullet, bIndex) => {
if (bullet.x < enemy.x + enemy.width && bullet.x + bullet.width > enemy.x &&
bullet.y < enemy.y + enemy.height && bullet.y + bullet.height > enemy.y) {
enemies.splice(eIndex, 1);
bullets.splice(bIndex, 1);
score += 10;
}
});
if (enemy.y > canvas.height) enemies.splice(eIndex, 1);
});
ctx.fillStyle = "white";
ctx.font = "18px Arial";
ctx.fillText("स्कोर: " + score, 15, 30);
requestAnimationFrame(update);
}
update();
</script>
</body>
</html>
1
1
6KB
6KB
140.0ms
188.0ms
140.0ms