Spaces:
Running
Running
File size: 12,071 Bytes
c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 054b578 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a 5b76f58 c96693a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>F1 Racing Simulator</title>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<style>
body {
background-color: #15151E;
color: #F4F4F4;
overflow: hidden;
font-family: 'Arial', sans-serif;
}
.track {
position: relative;
height: 100vh;
width: 100%;
background-color: #333;
overflow: hidden;
}
.road {
position: absolute;
width: 400px;
height: 200%;
background-color: #555;
left: 50%;
transform: translateX(-50%);
border-left: 5px dashed #ccc;
border-right: 5px dashed #ccc;
background-image: linear-gradient(#777 1px, transparent 1px);
background-size: 100% 40px;
}
.car {
position: absolute;
width: 80px;
height: 160px;
background-image: url('http://static.photos/automotive/200x200/1');
background-size: contain;
background-repeat: no-repeat;
bottom: 50px;
left: 50%;
transform: translateX(-50%);
z-index: 10;
}
.opponent {
position: absolute;
width: 80px;
height: 160px;
background-image: url('http://static.photos/automotive/200x200/2');
background-size: contain;
background-repeat: no-repeat;
z-index: 5;
}
.score-board {
position: absolute;
top: 20px;
left: 20px;
background-color: rgba(0,0,0,0.7);
padding: 10px;
border-radius: 5px;
border-left: 4px solid #E10600;
z-index: 20;
}
.game-over {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: rgba(0,0,0,0.9);
padding: 30px;
border-radius: 10px;
text-align: center;
display: none;
z-index: 30;
}
.controls {
position: absolute;
bottom: 20px;
width: 100%;
display: flex;
justify-content: center;
gap: 20px;
z-index: 20;
}
.control-btn {
background-color: #E10600;
color: white;
border: none;
padding: 15px 25px;
border-radius: 50%;
font-size: 20px;
cursor: pointer;
}
.lap-time {
position: absolute;
top: 20px;
right: 20px;
background-color: rgba(0,0,0,0.7);
padding: 10px;
border-radius: 5px;
border-right: 4px solid #E10600;
z-index: 20;
}
.grass {
position: absolute;
width: 100%;
height: 200%;
background-color: #2a5c2a;
background-image: url('http://static.photos/nature/200x200/5');
background-size: 200px;
}
</style>
</head>
<body>
<div class="track" id="gameArea">
<div class="grass"></div>
<div class="road"></div>
<div class="score-board">
<h3 class="font-bold">LAP: <span id="lap">1</span>/3</h3>
<p>POSITION: <span id="position">1</span></p>
</div>
<div class="lap-time">
<h3 class="font-bold">LAP TIME: <span id="time">0:00.000</span></h3>
<p>BEST: <span id="bestTime">0:00.000</span></p>
</div>
<div class="car" id="playerCar"></div>
<div class="game-over" id="gameOver">
<h2 class="text-3xl font-bold text-red-500 mb-4">RACE FINISHED</h2>
<p class="text-xl mb-2">Final Position: <span id="finalPosition">1</span></p>
<p class="text-xl mb-4">Best Lap: <span id="finalBestTime">0:00.000</span></p>
<button id="restartBtn" class="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-6 rounded">
New Race
</button>
</div>
<div class="controls">
<button class="control-btn" id="leftBtn"><i data-feather="chevron-left"></i></button>
<button class="control-btn" id="rightBtn"><i data-feather="chevron-right"></i></button>
</div>
<div class="text-center mt-3">
<a href="motorsport.html" class="text-white hover:text-red-500">Try Our New Motorsport Game</a>
</div>
</div>
<script>
feather.replace();
// Game variables
let lap = 1;
let position = 1;
let lapStartTime = 0;
let currentLapTime = 0;
let bestLapTime = 0;
let gameSpeed = 5;
let isRaceOver = false;
let opponents = [];
let animationId;
let roadPosition = 0;
// DOM elements
const gameArea = document.getElementById('gameArea');
const road = document.querySelector('.road');
const playerCar = document.getElementById('playerCar');
const lapElement = document.getElementById('lap');
const positionElement = document.getElementById('position');
const timeElement = document.getElementById('time');
const bestTimeElement = document.getElementById('bestTime');
const finalPositionElement = document.getElementById('finalPosition');
const finalBestTimeElement = document.getElementById('finalBestTime');
const gameOverElement = document.getElementById('gameOver');
const restartBtn = document.getElementById('restartBtn');
const leftBtn = document.getElementById('leftBtn');
const rightBtn = document.getElementById('rightBtn');
// Initialize game
function initGame() {
lapStartTime = Date.now();
updateLapTime();
createOpponents();
requestAnimationFrame(gameLoop);
}
// Game loop
function gameLoop() {
if (isRaceOver) return;
// Move road to simulate car moving
roadPosition += gameSpeed;
road.style.backgroundPositionY = `${roadPosition}px`;
// Move opponents
moveOpponents();
// Check lap completion (simplified)
if (roadPosition % 5000 < gameSpeed) {
completeLap();
}
animationId = requestAnimationFrame(gameLoop);
}
// Update lap time display
function updateLapTime() {
currentLapTime = Date.now() - lapStartTime;
timeElement.textContent = formatTime(currentLapTime);
setTimeout(updateLapTime, 10);
}
// Format time (milliseconds to M:SS.mmm)
function formatTime(ms) {
const minutes = Math.floor(ms / 60000);
const seconds = Math.floor((ms % 60000) / 1000);
const milliseconds = ms % 1000;
return `${minutes}:${seconds.toString().padStart(2, '0')}.${milliseconds.toString().padStart(3, '0')}`;
}
// Create AI opponents
function createOpponents() {
for (let i = 0; i < 5; i++) {
const opponent = document.createElement('div');
opponent.className = 'opponent';
opponent.style.left = `${Math.random() * 300 + 50}px`;
opponent.style.top = `${Math.random() * 500}px`;
gameArea.appendChild(opponent);
opponents.push({
element: opponent,
speed: 3 + Math.random() * 2,
x: parseInt(opponent.style.left),
y: parseInt(opponent.style.top)
});
}
}
// Move AI opponents
function moveOpponents() {
opponents.forEach((opponent, index) => {
opponent.y += opponent.speed;
opponent.x += Math.sin(Date.now() / 1000 + index) * 2; // side-to-side movement
// Wrap around track
if (opponent.y > gameArea.offsetHeight) {
opponent.y = -200;
}
opponent.element.style.top = `${opponent.y}px`;
opponent.element.style.left = `${opponent.x}px`;
// Simple collision detection
if (Math.abs(opponent.x - parseInt(playerCar.style.left)) < 60 &&
Math.abs(opponent.y - parseInt(playerCar.style.top)) < 100) {
handleCollision();
}
});
}
// Handle collision
function handleCollision() {
gameSpeed = Math.max(1, gameSpeed - 1); // Slow down on collision
}
// Complete a lap
function completeLap() {
lap++;
lapElement.textContent = lap;
// Update best lap time
if (currentLapTime < bestLapTime || bestLapTime === 0) {
bestLapTime = currentLapTime;
bestTimeElement.textContent = formatTime(bestLapTime);
}
// Increase difficulty
gameSpeed += 0.5;
// Check race completion
if (lap > 3) {
finishRace();
} else {
lapStartTime = Date.now(); // Reset lap timer
}
}
// Finish race
function finishRace() {
isRaceOver = true;
cancelAnimationFrame(animationId);
finalPositionElement.textContent = position;
finalBestTimeElement.textContent = formatTime(bestLapTime);
gameOverElement.style.display = 'block';
}
// Restart game
function restartGame() {
// Clear opponents
opponents.forEach(opponent => opponent.element.remove());
opponents = [];
// Reset variables
lap = 1;
position = 1;
gameSpeed = 5;
isRaceOver = false;
roadPosition = 0;
// Update displays
lapElement.textContent = lap;
positionElement.textContent = position;
timeElement.textContent = '0:00.000';
gameOverElement.style.display = 'none';
// Start game
initGame();
}
// Player car position
let carX = gameArea.offsetWidth / 2;
// Keyboard controls
document.addEventListener('keydown', (e) => {
if (e.key === 'ArrowLeft') {
carX = Math.max(50, carX - 20);
} else if (e.key === 'ArrowRight') {
carX = Math.min(gameArea.offsetWidth - 50, carX + 20);
}
playerCar.style.left = `${carX}px`;
});
// Touch controls
leftBtn.addEventListener('click', () => {
carX = Math.max(50, carX - 20);
playerCar.style.left = `${carX}px`;
});
rightBtn.addEventListener('click', () => {
carX = Math.min(gameArea.offsetWidth - 50, carX + 20);
playerCar.style.left = `${carX}px`;
});
restartBtn.addEventListener('click', restartGame);
// Start game
initGame();
</script>
</body>
</html>
|