Meta Description" name="description" />
<!DOCTYPE html>
<html>
<head>
<title>Catch the Object</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body { margin: 0; text-align: center; background: #222; color: white; overflow: hidden; }
canvas { background: #333; display: block; margin: 20px auto; border: 2px solid #fff; }
</style>
</head>
<body>
<h3>स्कोर: <span id="score">0</span></h3>
<canvas id="gameCanvas"></canvas>
<script>
const canvas = document.getElementById("gameCanvas");
const ctx = canvas.getContext("2d");
const scoreElement = document.getElementById("score");
canvas.width = window.innerWidth * 0.9;
canvas.height = window.innerHeight * 0.7;
let score = 0;
let player = { x: canvas.width / 2 - 25, y: canvas.height - 30, w: 50, h: 10 };
let item = { x: Math.random() * canvas.width, y: 0, size: 20, speed: 3 };
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// प्लेयर (Basket)
ctx.fillStyle = "#00FF00";
ctx.fillRect(player.x, player.y, player.w, player.h);
// गिरती हुई चीज़ (Cake/Ball)
ctx.fillStyle = "#FF0000";
ctx.beginPath();
ctx.arc(item.x, item.y, item.size / 2, 0, Math.PI * 2);
ctx.fill();
item.y += item.speed;
// टक्कर की जाँच
if (item.y + item.size > player.y && item.x > player.x && item.x < player.x + player.w) {
score++;
scoreElement.innerHTML = score;
item.y = 0;
item.x = Math.random() * (canvas.width - 20);
item.speed += 0.2; // रफ़्तार बढ़ाना
}
if (item.y > canvas.height) {
alert("गेम ओवर! स्कोर: " + score);
score = 0;
scoreElement.innerHTML = score;
item.y = 0;
item.speed = 3;
}
requestAnimationFrame(draw);
}
// फोन टच कंट्रोल
canvas.addEventListener("touchmove", (e) => {
let touch = e.touches[0];
let rect = canvas.getBoundingClientRect();
player.x = touch.clientX - rect.left - player.w / 2;
});
draw();
</script>
</body>
</html>
1
1
3KB
3KB
129.0ms
184.0ms
130.0ms