Meta Description" name="description" />
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>ALTAMASH - OFFLINE COURT</title>
<style>
body { margin:0; overflow:hidden; background:black; font-family: Arial, sans-serif; }
canvas { display:block; }
#title {
position: absolute;
top: 15%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-size: 40px;
font-weight: bold;
letter-spacing: 10px;
pointer-events: none;
text-shadow: 0 0 20px #00ffff;
z-index: 10;
}
#ui {
position: absolute;
top: 10px;
left: 10px;
color: #00ffff;
font-size: 18px;
z-index: 10;
}
#controls {
position: absolute;
bottom: 20px;
width: 100%;
display: flex;
justify-content: space-between;
padding: 0 20px;
box-sizing: border-box;
z-index: 10;
}
.btn {
width: 80px;
height: 80px;
background: rgba(0,255,255,0.2);
border: 2px solid #00ffff;
border-radius: 50%;
color: white;
font-size: 30px;
display: flex;
align-items: center;
justify-content: center;
user-select: none;
}
.btn:active { background: rgba(0,255,255,0.6); }
#startScreen {
position: absolute;
inset: 0;
background: rgba(0,0,0,0.85);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 20;
color: white;
}
#startScreen button {
margin-top: 20px;
padding: 12px 35px;
font-size: 20px;
background: #00ffff;
border: none;
border-radius: 30px;
font-weight: bold;
box-shadow: 0 0 20px #00ffff;
}
</style>
</head>
<body>
<div id="title">ALTAMASH</div>
<div id="ui">SCORE: <span id="score">0</span><br>HIGH: <span id="high">0</span></div>
<div id="startScreen">
<h1 style="letter-spacing:8px; text-shadow:0 0 20px #00ffff;">ALTAMASH</h1>
<p>OFFLINE COURT RACING</p>
<button onclick="startGame()">PLAY OFFLINE</button>
</div>
<div id="controls">
<div class="btn" id="leftBtn">◀</div>
<div class="btn" id="rightBtn">▶</div>
</div>
<canvas id="c"></canvas>
<script>
let canvas = document.getElementById('c');
let ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let particles = [];
for(let i=0; i<80; i++){
particles.push({
x: Math.random()*canvas.width,
y: Math.random()*canvas.height,
vx: (Math.random()-0.5)*1.5,
vy: (Math.random()-0.5)*1.5,
r: Math.random()*2+1
});
}
let gameRunning = false;
let score = 0;
let highScore = localStorage.getItem('altamash_high') || 0;
document.getElementById('high').innerText = highScore;
let car = { x: canvas.width/2 - 25, y: canvas.height - 140, w: 50, h: 90, speed: 7 };
let roadWidth = 300;
let roadX = canvas.width/2 - roadWidth/2;
let enemies = [];
let keys = {};
let roadOffset = 0;
function startGame(){
document.getElementById('startScreen').style.display = 'none';
gameRunning = true;
score = 0;
enemies = [];
car.x = canvas.width/2 - 25;
animate();
}
function spawnEnemy(){
if(Math.random() < 0.04){
enemies.push({
x: roadX + Math.random()*(roadWidth-50),
y: -100,
w: 50, h: 90,
speed: 4 + Math.random()*3 + score/100
});
}
}
function drawRoad(){
roadOffset += 8;
if(roadOffset > 40) roadOffset = 0;
ctx.fillStyle = '#111';
ctx.fillRect(roadX, 0, roadWidth, canvas.height);
// border
ctx.fillStyle = '#00ffff';
ctx.fillRect(roadX - 5, 0, 5, canvas.height);
ctx.fillRect(roadX + roadWidth, 0, 5, canvas.height);
// center lines
ctx.fillStyle = 'white';
for(let y = -40 + roadOffset; y < canvas.height; y+=40){
ctx.fillRect(canvas.width/2 - 3, y, 6, 20);
}
}
function drawCar(c, color){
ctx.fillStyle = color;
ctx.fillRect(c.x, c.y, c.w, c.h);
ctx.fillStyle = '#000';
ctx.fillRect(c.x+5, c.y+10, c.w-10, 15);
ctx.fillRect(c.x+5, c.y+c.h-25, c.w-10, 15);
}
function checkCollision(a,b){
return a.x < b.x+b.w && a.x+a.w > b.x && a.y < b.y+b.h && a.y+a.h > b.y;
}
function animate(){
if(!gameRunning) return;
// fade bg
ctx.fillStyle = 'rgba(0,0,0,0.3)';
ctx.fillRect(0,0,canvas.width,canvas.height);
// particles (tumhara old code)
for(let p of particles){
p.x += p.vx;
p.y += p.vy;
if(p.x<0 || p.x>canvas.width) p.vx*=-1;
if(p.y<0 || p.y>canvas.height) p.vy*=-1;
ctx.beginPath();
ctx.arc(p.x,p.y,p.r,0,Math.PI*2);
ctx.fillStyle = 'rgba(0,255,255,0.4)';
ctx.fill();
}
drawRoad();
spawnEnemy();
// car move
if(keys['ArrowLeft'] || keys['a'] || leftPressed) car.x -= car.speed;
if(keys['ArrowRight'] || keys['d'] || rightPressed) car.x += car.speed;
if(car.x < roadX) car.x = roadX;
if(car.x + car.w > roadX + roadWidth) car.x = roadX + roadWidth - car.w;
drawCar(car, '#00ffff');
for(let i=enemies.length-1; i>=0; i--){
let e = enemies[i];
e.y += e.speed;
drawCar(e, '#ff0040');
if(checkCollision(car, e)){
gameRunning = false;
if(score > highScore){
highScore = score;
localStorage.setItem('altamash_high', highScore);
}
document.getElementById('startScreen').style.display = 'flex';
document.getElementById('startScreen').innerHTML = `<h1>GAME OVER</h1><p>Score: ${score}</p><button onclick="startGame()">PLAY AGAIN</button>`;
return;
}
if(e.y > canvas.height){
enemies.splice(i,1);
score += 10;
document.getElementById('score').innerText = score;
document.getElementById('high').innerText = highScore;
}
}
requestAnimationFrame(animate);
}
// Controls
window.addEventListener('keydown', e=> keys[e.key] = true);
window.addEventListener('keyup', e=> keys[e.key] = false);
let leftPressed = false, rightPressed = false;
document.getElementById('leftBtn').addEventListener('touchstart', e=>{ e.preventDefault(); leftPressed=true; });
document.getElementById('leftBtn').addEventListener('touchend', ()=> leftPressed=false);
document.getElementById('rightBtn').addEventListener('touchstart', e=>{ e.preventDefault(); rightPressed=true; });
document.getElementById('rightBtn').addEventListener('touchend', ()=> rightPressed=false);
// Mouse for PC test
document.getElementById('leftBtn').addEventListener('mousedown', ()=> leftPressed=true);
document.getElementById('leftBtn').addEventListener('mouseup', ()=> leftPressed=false);
document.getElementById('rightBtn').addEventListener('mousedown', ()=> rightPressed=true);
document.getElementById('rightBtn').addEventListener('mouseup', ()=> rightPressed=false);
window.onresize = () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
roadX = canvas.width/2 - roadWidth/2;
}
</script>
</body>
</html>1
1
7KB
7KB
111.0ms
188.0ms
111.0ms