Meta Description" name="description" />
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>Indian Defender 3D</title>
<style>
body { margin: 0; background: #87CEEB; overflow: hidden; font-family: sans-serif; }
#game-container { position: relative; width: 100vw; height: 100vh; }
/* Speedometer */
#ui-top { position: absolute; top: 20px; left: 20px; color: white; text-shadow: 2px 2px 5px black; z-index: 10; }
/* Mobile Controls Like PS5/GTA */
#controls { position: absolute; bottom: 30px; width: 100%; display: flex; justify-content: space-between; padding: 0 20px; box-sizing: border-box; z-index: 20; }
.btn { width: 80px; height: 80px; background: rgba(0,0,0,0.5); border: 3px solid white; border-radius: 50%; color: white; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 20px; user-select: none; -webkit-tap-highlight-color: transparent; }
.btn:active { background: white; color: black; }
canvas { display: block; width: 100%; height: 100%; }
</style>
</head>
<body>
<div id="game-container">
<div id="ui-top">
<h2 style="margin:0">DEFENDER 3D</h2>
<div id="speed">Speed: 0 KM/H</div>
</div>
<div id="controls">
<div style="display:flex; gap:10px;">
<div class="btn" id="left">L</div>
<div class="btn" id="right">R</div>
</div>
<div style="display:flex; gap:10px;">
<div class="btn" style="background:rgba(255,0,0,0.6)" id="brake">BRK</div>
<div class="btn" style="background:rgba(0,255,0,0.6)" id="gas">GAS</div>
</div>
</div>
<canvas id="c"></canvas>
</div>
<script>
const canvas = document.getElementById('c');
const ctx = canvas.getContext('2d');
let w, h, speed = 0, carX = 0, roadOffset = 0;
let input = { left: false, right: false, gas: false, brake: false };
function resize() {
w = canvas.width = window.innerWidth;
h = canvas.height = window.innerHeight;
carX = w / 2;
}
window.onresize = resize;
resize();
// Touch Event Listeners for Mobile
function setupBtn(id, key) {
const el = document.getElementById(id);
el.addEventListener('touchstart', (e) => { e.preventDefault(); input[key] = true; });
el.addEventListener('touchend', (e) => { e.preventDefault(); input[key] = false; });
}
setupBtn('left', 'left'); setupBtn('right', 'right');
setupBtn('gas', 'gas'); setupBtn('brake', 'brake');
function draw() {
// 1. Sky & Background
ctx.fillStyle = "#87CEEB"; // Sky
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = "#228B22"; // Grass
ctx.fillRect(0, h * 0.4, w, h * 0.6);
// 2. 3D Road Perspective (GTA Style)
ctx.fillStyle = "#333";
ctx.beginPath();
ctx.moveTo(w * 0.45, h * 0.4); // Top of road
ctx.lineTo(w * 0.55, h * 0.4);
ctx.lineTo(w * 1.2, h); // Bottom Right
ctx.lineTo(w * -0.2, h); // Bottom Left
ctx.fill();
// Road Lines (Animated)
ctx.strokeStyle = "white";
ctx.lineWidth = 5;
ctx.setLineDash([20, 40]);
ctx.lineDashOffset = -roadOffset;
ctx.beginPath();
ctx.moveTo(w / 2, h * 0.4);
ctx.lineTo(w / 2, h);
ctx.stroke();
// 3. Buildings (Simple Parallax)
ctx.fillStyle = "#555";
for(let i=0; i<5; i++) {
let by = ((i * 200 + roadOffset) % h);
ctx.fillRect(w * 0.1, by, 50, 100); // Left Buildings
ctx.fillRect(w * 0.8, by, 50, 100); // Right Buildings
}
// 4. Car Physics (Unlimited Speed)
if(input.gas) speed += 0.5;
if(input.brake) speed -= 1.0;
speed *= 0.98; // Friction
if(speed < 0) speed = 0;
if(input.left) carX -= speed * 0.15;
if(input.right) carX += speed * 0.15;
roadOffset += speed;
document.getElementById('speed').innerText = `Speed: ${Math.floor(speed * 5)} KM/H`;
// 5. Draw Indian Defender Car (Back View)
let scale = 1.5;
ctx.fillStyle = "#4b5320"; // Army Green
ctx.fillRect(carX - 30 * scale, h - 150, 60 * scale, 50 * scale); // Main Body
ctx.fillStyle = "#333"; // Roof
ctx.fillRect(carX - 25 * scale, h - 145, 50 * scale, 30 * scale);
ctx.fillStyle = "black"; // Spare Tire
ctx.fillRect(carX - 10 * scale, h - 105, 20 * scale, 10 * scale);
requestAnimationFrame(draw);
}
draw();
</script>
</body>
</html>1
1
5KB
5KB
192.0ms
216.0ms
193.0ms