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 - GTA Edition</title>
<style>
body { margin: 0; background: #000; overflow: hidden; font-family: 'Segoe UI', sans-serif; }
#game-ui { position: absolute; top: 10px; left: 10px; color: #0f0; z-index: 10; font-family: monospace; }
#controls { position: absolute; bottom: 20px; width: 100%; display: flex; justify-content: space-around; z-index: 20; }
.btn { width: 70px; height: 70px; background: rgba(255,255,255,0.1); border: 2px solid #fff; border-radius: 50%; color: white; display: flex; align-items: center; justify-content: center; font-weight: bold; touch-action: none; }
.gas { background: rgba(0, 255, 0, 0.3); border-color: #0f0; }
.brk { background: rgba(255, 0, 0, 0.3); border-color: #f00; }
canvas { display: block; }
</style>
</head>
<body>
<div id="game-ui">
SPEED: <span id="speedo">0</span> KM/H<br>
SCORE: <span id="score">0</span>
</div>
<div id="controls">
<div style="display:flex; gap:15px">
<div class="btn" id="lBtn">◀</div>
<div class="btn" id="rBtn">▶</div>
</div>
<div style="display:flex; gap:15px">
<div class="btn brk" id="bBtn">BRK</div>
<div class="btn gas" id="gBtn">GAS</div>
</div>
</div>
<canvas id="c"></canvas>
<script>
const canvas = document.getElementById('c');
const ctx = canvas.getContext('2d');
let w, h, speed = 0, carX = 0, pos = 0, score = 0;
let input = { l:0, r:0, g:0, b:0 };
let traffic = [], buildings = [];
function init() {
w = canvas.width = window.innerWidth;
h = canvas.height = window.innerHeight;
carX = w / 2;
// Create 3D Building Positions
for(let i=0; i<10; i++) {
buildings.push({ z: i * 400, side: i % 2 == 0 ? 1 : -1, h: 200 + Math.random() * 300 });
}
// Initial Traffic
for(let i=0; i<3; i++) spawnTraffic();
}
function spawnTraffic() {
traffic.push({ x: (Math.random() - 0.5) * 400, z: pos + 2000 + Math.random() * 1000, speed: 5 + Math.random() * 10 });
}
// Touch Handlers
const bind = (id, k) => {
const el = document.getElementById(id);
el.ontouchstart = (e) => { e.preventDefault(); input[k] = 1; };
el.ontouchend = (e) => { e.preventDefault(); input[k] = 0; };
};
bind('lBtn','l'); bind('rBtn','r'); bind('gBtn','g'); bind('bBtn','b');
function draw() {
// Dark City Background
ctx.fillStyle = "#050510";
ctx.fillRect(0, 0, w, h);
let horizon = h * 0.4;
// 3D Road Logic
pos += speed;
if(input.g) speed += 0.5;
if(input.b) speed -= 1.2;
speed *= 0.98;
if(speed < 0) speed = 0;
if(input.l) carX -= speed * 0.1;
if(input.r) carX += speed * 0.1;
// Draw Buildings
buildings.forEach(b => {
let relativeZ = b.z - (pos % 4000);
if(relativeZ < 0) relativeZ += 4000;
let scale = 400 / relativeZ;
if(scale > 0 && scale < 5) {
ctx.fillStyle = "#1a1a2e";
let bx = w/2 + (b.side * 200 * scale);
let bw = 150 * scale;
let bh = b.h * scale;
ctx.fillRect(bx - bw/2, horizon - bh, bw, bh);
// Windows
ctx.fillStyle = "rgba(255,255,0,0.3)";
ctx.fillRect(bx - bw/4, horizon - bh/2, bw/10, bh/10);
}
});
// Draw Road
ctx.fillStyle = "#222";
ctx.beginPath();
ctx.moveTo(w/2 - 20, horizon);
ctx.lineTo(w/2 + 20, horizon);
ctx.lineTo(w, h);
ctx.lineTo(0, h);
ctx.fill();
// Traffic Cars
traffic.forEach((t, i) => {
let relativeZ = t.z - pos;
if(relativeZ < 0) {
traffic.splice(i, 1);
spawnTraffic();
score += 10;
return;
}
let scale = 400 / relativeZ;
let tx = w/2 + (t.x * scale);
let ty = horizon + (400 * scale);
let tw = 60 * scale;
let th = 40 * scale;
if(scale > 0 && scale < 10) {
ctx.fillStyle = "red";
ctx.fillRect(tx - tw/2, ty - th, tw, th);
// Collision
if(relativeZ < 50 && Math.abs(carX - tx) < 40) {
speed = 0;
score = 0;
}
}
});
// Draw Player Defender
let pScale = 2;
ctx.fillStyle = "#4b5320"; // Army Green
ctx.fillRect(carX - 30, h - 140, 60, 40); // Body
ctx.fillStyle = "#add8e6"; // Window
ctx.fillRect(carX - 20, h - 135, 40, 15);
ctx.fillStyle = "black"; // Tires
ctx.fillRect(carX - 35, h - 110, 15, 10);
ctx.fillRect(carX + 20, h - 110, 15, 10);
document.getElementById('speedo').innerText = Math.floor(speed * 4);
document.getElementById('score').innerText = score;
requestAnimationFrame(draw);
}
init();
draw();
</script>
</body>
</html>1
1
6KB
6KB
119.0ms
124.0ms
119.0ms