Meta Description" name="description" />
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hill Climb Racing</title>
<style>
body { margin: 0; overflow: hidden; background: linear-gradient(#87CEEB, #E0F6FF); font-family: 'Arial', sans-serif; }
#gameCanvas { display: block; }
.score { position: absolute; top: 10px; left: 10px; font-size: 30px; color: #333; font-weight: bold; }
.controls { position: absolute; bottom: 20px; width: 100%; text-align: center; color: #555; }
</style>
</head>
<body>
<div class="score">Dist: <span id="dist">0</span>m</div>
<div class="controls">TAP & HOLD to Drive! ππ¨</div>
<canvas id="gameCanvas"></canvas>
<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let car = { x: 100, y: 0, vY: 0, speed: 0, angle: 0 };
let terrain = [];
let offset = 0;
let isDriving = false;
// Pahaad banane ka logic
for (let i = 0; i < 5000; i++) {
terrain.push(canvas.height - 150 + Math.sin(i * 0.1) * 40 + Math.cos(i * 0.05) * 60);
}
// Input listeners (Mobile + PC)
const start = () => isDriving = true;
const end = () => isDriving = false;
window.addEventListener('mousedown', start);
window.addEventListener('mouseup', end);
window.addEventListener('touchstart', start);
window.addEventListener('touchend', end);
window.addEventListener('keydown', (e) => { if(e.code === 'Space') start(); });
window.addEventListener('keyup', (e) => { if(e.code === 'Space') end(); });
function gameLoop() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Physics
if (isDriving) car.speed += 0.25;
else car.speed *= 0.97; // Slow down
if (car.speed > 8) car.speed = 8;
offset += car.speed;
let index = Math.floor((car.x + offset) / 10);
let groundY = terrain[index] - 30;
if (car.y < groundY) {
car.vY += 0.6; // Gravity
} else {
car.vY = 0;
car.y = groundY;
// Angle adjustment
let nextY = terrain[index + 2] - 30;
car.angle = Math.atan2(nextY - car.y, 20);
}
car.y += car.vY;
document.getElementById('dist').innerText = Math.floor(offset/10);
// Draw Sky & Sun
ctx.fillStyle = "yellow";
ctx.beginPath(); ctx.arc(canvas.width - 80, 80, 40, 0, Math.PI*2); ctx.fill();
// Draw Ground (Pahaad)
ctx.fillStyle = "#45a049";
ctx.beginPath();
ctx.moveTo(0, canvas.height);
for (let i = 0; i < canvas.width / 10; i++) {
ctx.lineTo(i * 10, terrain[Math.floor(i + offset / 10)]);
}
ctx.lineTo(canvas.width, canvas.height);
ctx.fill();
// Draw Car Body
ctx.save();
ctx.translate(car.x, car.y);
ctx.rotate(car.angle);
ctx.fillStyle = "#e91e63"; // Pink/Red Car
ctx.fillRect(-30, -15, 60, 25);
ctx.fillStyle = "#333"; // Wheels
ctx.beginPath(); ctx.arc(-20, 15, 12, 0, Math.PI*2); ctx.fill();
ctx.beginPath(); ctx.arc(20, 15, 12, 0, Math.PI*2); ctx.fill();
ctx.restore();
requestAnimationFrame(gameLoop);
}
gameLoop();
</script>
</body>
</html>
1
1
4KB
4KB
127.0ms
204.0ms
127.0ms