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TF-8" />
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
6 |
+
<title>Desert Road Runner</title>
|
7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
9 |
+
<style>
|
10 |
+
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');
|
11 |
+
body {
|
12 |
+
margin: 0;
|
13 |
+
padding: 0;
|
14 |
+
overflow: hidden;
|
15 |
+
font-family: 'Press Start 2P', cursive;
|
16 |
+
background-color: #f7f7f7;
|
17 |
+
}
|
18 |
+
#game-container {
|
19 |
+
position: relative;
|
20 |
+
width: 100vw;
|
21 |
+
height: 100vh;
|
22 |
+
background: linear-gradient(to bottom, #87CEEB 0%, #E6E6FA 50%, #F5DEB3 100%);
|
23 |
+
overflow: hidden;
|
24 |
+
}
|
25 |
+
#road {
|
26 |
+
position: absolute;
|
27 |
+
bottom: 0;
|
28 |
+
width: 100%;
|
29 |
+
height: 120px;
|
30 |
+
background-color: #333;
|
31 |
+
z-index: 5;
|
32 |
+
}
|
33 |
+
.road-marking {
|
34 |
+
position: absolute;
|
35 |
+
bottom: 45px;
|
36 |
+
width: 50px;
|
37 |
+
height: 10px;
|
38 |
+
background-color: #fff;
|
39 |
+
z-index: 6;
|
40 |
+
}
|
41 |
+
#car {
|
42 |
+
position: absolute;
|
43 |
+
bottom: 0px;
|
44 |
+
left: 40px;
|
45 |
+
width: 200px;
|
46 |
+
height: 200px;
|
47 |
+
background-image: url('https://www.chennaipainter.in/wp-content/uploads/2025/04/car-1024x434.png');
|
48 |
+
background-size: contain;
|
49 |
+
background-repeat: no-repeat;
|
50 |
+
z-index: 15;
|
51 |
+
transform: scale(0.7);
|
52 |
+
}
|
53 |
+
.obstacle {
|
54 |
+
position: absolute;
|
55 |
+
bottom: 80px;
|
56 |
+
width: 80px;
|
57 |
+
height: 70px;
|
58 |
+
background-image: url('https://www.chennaipainter.in/wp-content/uploads/2025/04/obstacle-150x150.png');
|
59 |
+
background-size: contain;
|
60 |
+
background-repeat: no-repeat;
|
61 |
+
z-index: 5;
|
62 |
+
}
|
63 |
+
.cloud {
|
64 |
+
position: absolute;
|
65 |
+
width: 100px;
|
66 |
+
height: 60px;
|
67 |
+
background-image: url('https://www.chennaipainter.in/wp-content/uploads/2025/04/cloud-300x300.png');
|
68 |
+
background-size: contain;
|
69 |
+
background-repeat: no-repeat;
|
70 |
+
opacity: 0.8;
|
71 |
+
z-index: 2;
|
72 |
+
}
|
73 |
+
|
74 |
+
.cactus {
|
75 |
+
position: absolute;
|
76 |
+
bottom: 118px;
|
77 |
+
width: 200px;
|
78 |
+
height: 500px;
|
79 |
+
background-image: url('https://www.chennaipainter.in/wp-content/uploads/2025/04/tree-150x150.png');
|
80 |
+
background-size: contain;
|
81 |
+
background-repeat: no-repeat;
|
82 |
+
z-index: 4;
|
83 |
+
}
|
84 |
+
#score {
|
85 |
+
position: absolute;
|
86 |
+
top: 20px;
|
87 |
+
right: 20px;
|
88 |
+
font-size: 20px;
|
89 |
+
color: #333;
|
90 |
+
z-index: 20;
|
91 |
+
background-color: rgba(255, 255, 255, 0.7);
|
92 |
+
padding: 10px 15px;
|
93 |
+
border-radius: 10px;
|
94 |
+
}
|
95 |
+
#game-over {
|
96 |
+
position: absolute;
|
97 |
+
top: 50%;
|
98 |
+
left: 50%;
|
99 |
+
transform: translate(-50%, -50%);
|
100 |
+
font-size: 40px;
|
101 |
+
color: #ff3333;
|
102 |
+
text-align: center;
|
103 |
+
display: none;
|
104 |
+
z-index: 20;
|
105 |
+
background-color: rgba(255, 255, 255, 0.8);
|
106 |
+
padding: 30px;
|
107 |
+
border-radius: 20px;
|
108 |
+
box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
|
109 |
+
}
|
110 |
+
#start-screen {
|
111 |
+
position: absolute;
|
112 |
+
top: 0;
|
113 |
+
left: 0;
|
114 |
+
width: 100%;
|
115 |
+
height: 100%;
|
116 |
+
background-color: rgba(240, 230, 210, 0.9);
|
117 |
+
display: flex;
|
118 |
+
flex-direction: column;
|
119 |
+
justify-content: center;
|
120 |
+
align-items: center;
|
121 |
+
z-index: 30;
|
122 |
+
text-align: center;
|
123 |
+
}
|
124 |
+
#start-button {
|
125 |
+
margin-top: 20px;
|
126 |
+
padding: 15px 40px;
|
127 |
+
font-size: 20px;
|
128 |
+
background-color: #4CAF50;
|
129 |
+
color: white;
|
130 |
+
border: none;
|
131 |
+
border-radius: 10px;
|
132 |
+
cursor: pointer;
|
133 |
+
font-family: 'Press Start 2P', cursive;
|
134 |
+
transition: all 0.3s;
|
135 |
+
box-shadow: 0 5px 0 #2E7D32;
|
136 |
+
}
|
137 |
+
#start-button:hover {
|
138 |
+
background-color: #45a049;
|
139 |
+
transform: translateY(-2px);
|
140 |
+
}
|
141 |
+
#start-button:active {
|
142 |
+
transform: translateY(3px);
|
143 |
+
box-shadow: 0 2px 0 #2E7D32;
|
144 |
+
}
|
145 |
+
.controls {
|
146 |
+
margin-top: 30px;
|
147 |
+
display: flex;
|
148 |
+
gap: 20px;
|
149 |
+
}
|
150 |
+
.control-key {
|
151 |
+
background-color: #333;
|
152 |
+
color: white;
|
153 |
+
padding: 10px 15px;
|
154 |
+
border-radius: 5px;
|
155 |
+
font-size: 16px;
|
156 |
+
}
|
157 |
+
.sun {
|
158 |
+
position: absolute;
|
159 |
+
width: 80px;
|
160 |
+
height: 80px;
|
161 |
+
background: radial-gradient(circle, #FFD700 30%, #FFA500 70%);
|
162 |
+
border-radius: 50%;
|
163 |
+
box-shadow: 0 0 40px #FFD700;
|
164 |
+
z-index: 1;
|
165 |
+
}
|
166 |
+
@keyframes birdFly {
|
167 |
+
0% { transform: translateX(0) translateY(0); }
|
168 |
+
50% { transform: translateX(0) translateY(-10px); }
|
169 |
+
100% { transform: translateX(0) translateY(0); }
|
170 |
+
}
|
171 |
+
.bird {
|
172 |
+
animation: birdFly 1s infinite ease-in-out;
|
173 |
+
}
|
174 |
+
</style>
|
175 |
+
</head>
|
176 |
+
<body>
|
177 |
+
<div id="game-container">
|
178 |
+
<div class="sun" style="top: 50px; right: 100px;"></div>
|
179 |
+
<div id="road"></div>
|
180 |
+
<div id="score">0</div>
|
181 |
+
<div id="game-over">
|
182 |
+
GAME OVER<br>
|
183 |
+
<span id="final-score">0</span><br>
|
184 |
+
<div class="mt-4 text-xl">Press Space to Restart</div>
|
185 |
+
<div class="mt-4 text-sm">Or tap the screen on mobile</div>
|
186 |
+
</div>
|
187 |
+
<div id="start-screen">
|
188 |
+
<h1 class="text-4xl md:text-6xl mb-6 text-orange-600">DESERT ROAD RUNNER</h1>
|
189 |
+
<p class="mb-8 text-lg md:text-xl max-w-2xl px-4">Avoid the obstacles and survive as long as you can in this endless desert adventure!</p>
|
190 |
+
<button id="start-button">START GAME</button>
|
191 |
+
<div class="controls mt-8">
|
192 |
+
<div class="control-key"><i class="fas fa-arrow-up"></i> JUMP</div>
|
193 |
+
</div>
|
194 |
+
<div class="mt-8 text-sm text-gray-600">
|
195 |
+
<i class="fas fa-mobile-alt"></i> Tap the screen to jump on mobile
|
196 |
+
</div>
|
197 |
+
</div>
|
198 |
+
<div id="car"></div>
|
199 |
+
</div>
|
200 |
+
|
201 |
+
<script>
|
202 |
+
const gameContainer = document.getElementById('game-container');
|
203 |
+
const car = document.getElementById('car');
|
204 |
+
const scoreEl = document.getElementById('score');
|
205 |
+
const gameOverEl = document.getElementById('game-over');
|
206 |
+
const finalScoreEl = document.getElementById('final-score');
|
207 |
+
const startScreen = document.getElementById('start-screen');
|
208 |
+
const startButton = document.getElementById('start-button');
|
209 |
+
let gameSpeed = 5;
|
210 |
+
let score = 0;
|
211 |
+
let isJumping = false;
|
212 |
+
let isGameOver = false;
|
213 |
+
let gameStarted = false;
|
214 |
+
let jumpStart = 0;
|
215 |
+
let animationId;
|
216 |
+
const obstacles = [];
|
217 |
+
const clouds = [];
|
218 |
+
const birds = [];
|
219 |
+
const cacti = [];
|
220 |
+
const mountains = [];
|
221 |
+
const roadMarkings = [];
|
222 |
+
// Create initial road markings
|
223 |
+
for (let i = 0; i < 10; i++) {
|
224 |
+
const mark = document.createElement('div');
|
225 |
+
mark.className = 'road-marking';
|
226 |
+
mark.style.left = (i * 200) + 'px';
|
227 |
+
gameContainer.appendChild(mark);
|
228 |
+
roadMarkings.push({ el: mark, x: i * 200 });
|
229 |
+
}
|
230 |
+
// Create initial clouds
|
231 |
+
for (let i = 0; i < 5; i++) {
|
232 |
+
createCloud(Math.random() * window.innerWidth, Math.random() * 200);
|
233 |
+
}
|
234 |
+
// Create initial desert scenery
|
235 |
+
for (let i = 0; i < 3; i++) {
|
236 |
+
createCactus(window.innerWidth + (i * 400), Math.random() * 50 + 50);
|
237 |
+
}
|
238 |
+
for (let i = 0; i < 2; i++) {
|
239 |
+
createMountain(window.innerWidth + (i * 600), Math.random() * 100);
|
240 |
+
}
|
241 |
+
function startGame() {
|
242 |
+
gameStarted = true;
|
243 |
+
isGameOver = false;
|
244 |
+
score = 0;
|
245 |
+
gameSpeed = 5;
|
246 |
+
scoreEl.textContent = '0';
|
247 |
+
startScreen.style.display = 'none';
|
248 |
+
gameOverEl.style.display = 'none';
|
249 |
+
// Clear all game elements
|
250 |
+
obstacles.forEach(o => o.el.remove());
|
251 |
+
clouds.forEach(c => c.el.remove());
|
252 |
+
birds.forEach(b => b.el.remove());
|
253 |
+
cacti.forEach(c => c.el.remove());
|
254 |
+
mountains.forEach(m => m.el.remove());
|
255 |
+
obstacles.length = clouds.length = birds.length = cacti.length = mountains.length = 0;
|
256 |
+
// Create initial elements
|
257 |
+
for (let i = 0; i < 5; i++) {
|
258 |
+
createCloud(Math.random() * window.innerWidth, Math.random() * 200);
|
259 |
+
}
|
260 |
+
for (let i = 0; i < 3; i++) {
|
261 |
+
createCactus(window.innerWidth + (i * 400), Math.random() * 50 + 50);
|
262 |
+
}
|
263 |
+
for (let i = 0; i < 2; i++) {
|
264 |
+
createMountain(window.innerWidth + (i * 600), Math.random() * 100);
|
265 |
+
}
|
266 |
+
animationId = requestAnimationFrame(gameLoop);
|
267 |
+
}
|
268 |
+
function gameLoop() {
|
269 |
+
if (isGameOver) return cancelAnimationFrame(animationId);
|
270 |
+
score += 0.1;
|
271 |
+
scoreEl.textContent = Math.floor(score);
|
272 |
+
if (Math.floor(score) % 500 === 0) gameSpeed += 0.5;
|
273 |
+
updateCarPosition();
|
274 |
+
updateObstacles();
|
275 |
+
updateClouds();
|
276 |
+
updateBirds();
|
277 |
+
updateCacti();
|
278 |
+
updateMountains();
|
279 |
+
updateRoadMarks();
|
280 |
+
detectCollisions();
|
281 |
+
animationId = requestAnimationFrame(gameLoop);
|
282 |
+
}
|
283 |
+
function updateCarPosition() {
|
284 |
+
if (!isJumping) return;
|
285 |
+
const jumpDuration = 700;
|
286 |
+
const t = (Date.now() - jumpStart) / jumpDuration;
|
287 |
+
if (t >= 1) {
|
288 |
+
car.style.bottom = '0px';
|
289 |
+
isJumping = false;
|
290 |
+
} else {
|
291 |
+
const height = Math.round(220 * Math.sin(Math.PI * t));
|
292 |
+
car.style.bottom = height + 'px';
|
293 |
+
}
|
294 |
+
}
|
295 |
+
function updateObstacles() {
|
296 |
+
if (Math.random() < 0.0025 * gameSpeed) {
|
297 |
+
if (obstacles.length === 0 || obstacles[obstacles.length - 1].x < window.innerWidth - 400) {
|
298 |
+
createObstacle();
|
299 |
+
}
|
300 |
+
}
|
301 |
+
obstacles.forEach((obj, idx) => {
|
302 |
+
obj.x -= gameSpeed;
|
303 |
+
obj.el.style.left = obj.x + 'px';
|
304 |
+
if (obj.x < -200) {
|
305 |
+
obj.el.remove();
|
306 |
+
obstacles.splice(idx, 1);
|
307 |
+
}
|
308 |
+
});
|
309 |
+
}
|
310 |
+
function updateClouds() {
|
311 |
+
if (Math.random() < 0.002) createCloud(window.innerWidth, Math.random() * 200);
|
312 |
+
clouds.forEach((c, idx) => {
|
313 |
+
c.x -= gameSpeed * 0.5;
|
314 |
+
c.el.style.left = c.x + 'px';
|
315 |
+
if (c.x < -100) {
|
316 |
+
c.el.remove();
|
317 |
+
clouds.splice(idx, 1);
|
318 |
+
}
|
319 |
+
});
|
320 |
+
}
|
321 |
+
function updateBirds() {
|
322 |
+
if (Math.random() < 0.0005 * gameSpeed) createBird(window.innerWidth, Math.random() * 150 + 50);
|
323 |
+
birds.forEach((b, idx) => {
|
324 |
+
b.x -= gameSpeed * 0.8;
|
325 |
+
b.el.style.left = b.x + 'px';
|
326 |
+
if (b.x < -100) {
|
327 |
+
b.el.remove();
|
328 |
+
birds.splice(idx, 1);
|
329 |
+
}
|
330 |
+
});
|
331 |
+
}
|
332 |
+
function updateCacti() {
|
333 |
+
if (Math.random() < 0.0008 * gameSpeed) createCactus(window.innerWidth, Math.random() * 50 + 50);
|
334 |
+
cacti.forEach((c, idx) => {
|
335 |
+
c.x -= gameSpeed * 0.3;
|
336 |
+
c.el.style.left = c.x + 'px';
|
337 |
+
if (c.x < -100) {
|
338 |
+
c.el.remove();
|
339 |
+
cacti.splice(idx, 1);
|
340 |
+
}
|
341 |
+
});
|
342 |
+
}
|
343 |
+
function updateMountains() {
|
344 |
+
if (mountains.length < 2 || mountains[mountains.length - 1].x < window.innerWidth - 400) {
|
345 |
+
createMountain(window.innerWidth, Math.random() * 100);
|
346 |
+
}
|
347 |
+
mountains.forEach((m, idx) => {
|
348 |
+
m.x -= gameSpeed * 0.2;
|
349 |
+
m.el.style.left = m.x + 'px';
|
350 |
+
if (m.x < -300) {
|
351 |
+
m.el.remove();
|
352 |
+
mountains.splice(idx, 1);
|
353 |
+
}
|
354 |
+
});
|
355 |
+
}
|
356 |
+
function updateRoadMarks() {
|
357 |
+
roadMarkings.forEach(mark => {
|
358 |
+
mark.x -= gameSpeed;
|
359 |
+
if (mark.x < -50) mark.x = window.innerWidth;
|
360 |
+
mark.el.style.left = mark.x + 'px';
|
361 |
+
});
|
362 |
+
}
|
363 |
+
function detectCollisions() {
|
364 |
+
const carRect = car.getBoundingClientRect();
|
365 |
+
// Fine-tuned shrink values
|
366 |
+
const shrinkLeft = 30;
|
367 |
+
const shrinkRight = 30;
|
368 |
+
const shrinkTop = 10;
|
369 |
+
const shrinkBottom = 10;
|
370 |
+
const carBox = {
|
371 |
+
left: carRect.left + shrinkLeft,
|
372 |
+
right: carRect.right - shrinkRight,
|
373 |
+
top: carRect.top + shrinkTop,
|
374 |
+
bottom: carRect.bottom - shrinkBottom,
|
375 |
+
};
|
376 |
+
for (let obj of obstacles) {
|
377 |
+
const r = obj.el.getBoundingClientRect();
|
378 |
+
const obstacleBox = {
|
379 |
+
left: r.left + 20,
|
380 |
+
right: r.right - 20,
|
381 |
+
top: r.top + 20,
|
382 |
+
bottom: r.bottom - 20,
|
383 |
+
};
|
384 |
+
if (
|
385 |
+
carBox.left < obstacleBox.right &&
|
386 |
+
carBox.right > obstacleBox.left &&
|
387 |
+
carBox.top < obstacleBox.bottom &&
|
388 |
+
carBox.bottom > obstacleBox.top
|
389 |
+
) {
|
390 |
+
return triggerGameOver();
|
391 |
+
}
|
392 |
+
}
|
393 |
+
}
|
394 |
+
function triggerGameOver() {
|
395 |
+
isGameOver = true;
|
396 |
+
finalScoreEl.textContent = Math.floor(score);
|
397 |
+
gameOverEl.style.display = 'block';
|
398 |
+
}
|
399 |
+
function createObstacle() {
|
400 |
+
const el = document.createElement('div');
|
401 |
+
el.className = 'obstacle';
|
402 |
+
el.style.left = window.innerWidth + 'px';
|
403 |
+
gameContainer.appendChild(el);
|
404 |
+
obstacles.push({ el, x: window.innerWidth });
|
405 |
+
}
|
406 |
+
function createCloud(x, y) {
|
407 |
+
const el = document.createElement('div');
|
408 |
+
el.className = 'cloud';
|
409 |
+
el.style.left = x + 'px';
|
410 |
+
el.style.top = y + 'px';
|
411 |
+
gameContainer.appendChild(el);
|
412 |
+
clouds.push({ el, x });
|
413 |
+
}
|
414 |
+
function createBird(x, y) {
|
415 |
+
const el = document.createElement('div');
|
416 |
+
el.className = 'bird';
|
417 |
+
el.style.left = x + 'px';
|
418 |
+
el.style.top = y + 'px';
|
419 |
+
gameContainer.appendChild(el);
|
420 |
+
birds.push({ el, x });
|
421 |
+
}
|
422 |
+
function createCactus(x, height) {
|
423 |
+
const el = document.createElement('div');
|
424 |
+
el.className = 'cactus';
|
425 |
+
el.style.left = x + 'px';
|
426 |
+
el.style.height = height + 'px';
|
427 |
+
gameContainer.appendChild(el);
|
428 |
+
cacti.push({ el, x });
|
429 |
+
}
|
430 |
+
function createMountain(x, height) {
|
431 |
+
const el = document.createElement('div');
|
432 |
+
el.className = 'mountain';
|
433 |
+
el.style.left = x + 'px';
|
434 |
+
el.style.height = (150 + height) + 'px';
|
435 |
+
gameContainer.appendChild(el);
|
436 |
+
mountains.push({ el, x });
|
437 |
+
}
|
438 |
+
function jump() {
|
439 |
+
if (!gameStarted || isGameOver || isJumping) return;
|
440 |
+
isJumping = true;
|
441 |
+
jumpStart = Date.now();
|
442 |
+
}
|
443 |
+
document.addEventListener('keydown', e => {
|
444 |
+
if ((e.code === 'Space' || e.key === 'ArrowUp') && !gameStarted) return startGame();
|
445 |
+
if ((e.code === 'Space' || e.key === 'ArrowUp') && isGameOver) return startGame();
|
446 |
+
if ((e.code === 'Space' || e.key === 'ArrowUp')) return jump();
|
447 |
+
});
|
448 |
+
startButton.addEventListener('click', startGame);
|
449 |
+
document.addEventListener('touchstart', (e) => {
|
450 |
+
e.preventDefault();
|
451 |
+
if (!gameStarted || isGameOver) return startGame();
|
452 |
+
jump();
|
453 |
+
});
|
454 |
+
// Prevent scrolling on mobile when touching the game area
|
455 |
+
document.addEventListener('touchmove', (e) => {
|
456 |
+
if (gameStarted) e.preventDefault();
|
457 |
+
}, { passive: false });
|
458 |
+
</script>
|
459 |
+
</body>
|
460 |
+
</html>
|