Okwutecloud commited on
Commit
5b76f58
·
verified ·
1 Parent(s): e0e33ad

Create a formula one game

Browse files
Files changed (3) hide show
  1. f1game.html +251 -0
  2. formula1.html +5 -3
  3. index.html +1 -0
f1game.html ADDED
@@ -0,0 +1,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>F1 Racing Game</title>
7
+ <link rel="icon" type="image/x-icon" href="/static/favicon.ico">
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
10
+ <style>
11
+ body {
12
+ background-color: #15151E;
13
+ color: #F4F4F4;
14
+ overflow: hidden;
15
+ font-family: 'Arial', sans-serif;
16
+ }
17
+ .game-container {
18
+ background-image: url('http://static.photos/sport/1200x630/10');
19
+ background-size: cover;
20
+ background-position: center;
21
+ height: 100vh;
22
+ position: relative;
23
+ }
24
+ .car {
25
+ position: absolute;
26
+ width: 100px;
27
+ height: 200px;
28
+ background-image: url('http://static.photos/automotive/200x200/1');
29
+ background-size: contain;
30
+ background-repeat: no-repeat;
31
+ bottom: 50px;
32
+ left: 50%;
33
+ transform: translateX(-50%);
34
+ }
35
+ .obstacle {
36
+ position: absolute;
37
+ width: 80px;
38
+ height: 120px;
39
+ background-image: url('http://static.photos/automotive/200x200/2');
40
+ background-size: contain;
41
+ background-repeat: no-repeat;
42
+ }
43
+ .score-board {
44
+ position: absolute;
45
+ top: 20px;
46
+ left: 20px;
47
+ background-color: rgba(0,0,0,0.7);
48
+ padding: 10px;
49
+ border-radius: 5px;
50
+ border-left: 4px solid #E10600;
51
+ }
52
+ .game-over {
53
+ position: absolute;
54
+ top: 50%;
55
+ left: 50%;
56
+ transform: translate(-50%, -50%);
57
+ background-color: rgba(0,0,0,0.9);
58
+ padding: 30px;
59
+ border-radius: 10px;
60
+ text-align: center;
61
+ display: none;
62
+ }
63
+ .controls {
64
+ position: absolute;
65
+ bottom: 20px;
66
+ width: 100%;
67
+ display: flex;
68
+ justify-content: center;
69
+ gap: 20px;
70
+ }
71
+ .control-btn {
72
+ background-color: #E10600;
73
+ color: white;
74
+ border: none;
75
+ padding: 15px 25px;
76
+ border-radius: 50%;
77
+ font-size: 20px;
78
+ cursor: pointer;
79
+ }
80
+ </style>
81
+ </head>
82
+ <body>
83
+ <div class="game-container" id="gameArea">
84
+ <div class="score-board">
85
+ <h3 class="font-bold">SCORE: <span id="score">0</span></h3>
86
+ <p>HIGH SCORE: <span id="highScore">0</span></p>
87
+ </div>
88
+
89
+ <div class="car" id="playerCar"></div>
90
+
91
+ <div class="game-over" id="gameOver">
92
+ <h2 class="text-3xl font-bold text-red-500 mb-4">GAME OVER</h2>
93
+ <p class="text-xl mb-6">Your Score: <span id="finalScore">0</span></p>
94
+ <button id="restartBtn" class="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-6 rounded">
95
+ Play Again
96
+ </button>
97
+ </div>
98
+
99
+ <div class="controls">
100
+ <button class="control-btn" id="leftBtn"><i data-feather="chevron-left"></i></button>
101
+ <button class="control-btn" id="rightBtn"><i data-feather="chevron-right"></i></button>
102
+ </div>
103
+ </div>
104
+
105
+ <script>
106
+ feather.replace();
107
+
108
+ // Game variables
109
+ let score = 0;
110
+ let highScore = localStorage.getItem('f1HighScore') || 0;
111
+ let gameSpeed = 5;
112
+ let isGameOver = false;
113
+ let obstacles = [];
114
+ let animationId;
115
+
116
+ // DOM elements
117
+ const gameArea = document.getElementById('gameArea');
118
+ const playerCar = document.getElementById('playerCar');
119
+ const scoreElement = document.getElementById('score');
120
+ const highScoreElement = document.getElementById('highScore');
121
+ const finalScoreElement = document.getElementById('finalScore');
122
+ const gameOverElement = document.getElementById('gameOver');
123
+ const restartBtn = document.getElementById('restartBtn');
124
+ const leftBtn = document.getElementById('leftBtn');
125
+ const rightBtn = document.getElementById('rightBtn');
126
+
127
+ // Set high score display
128
+ highScoreElement.textContent = highScore;
129
+
130
+ // Player car position
131
+ let carPosition = 50; // percentage from left
132
+
133
+ // Keyboard controls
134
+ document.addEventListener('keydown', (e) => {
135
+ if (e.key === 'ArrowLeft' && carPosition > 10) {
136
+ carPosition -= 10;
137
+ } else if (e.key === 'ArrowRight' && carPosition < 90) {
138
+ carPosition += 10;
139
+ }
140
+ updateCarPosition();
141
+ });
142
+
143
+ // Touch controls
144
+ leftBtn.addEventListener('click', () => {
145
+ if (carPosition > 10) {
146
+ carPosition -= 10;
147
+ updateCarPosition();
148
+ }
149
+ });
150
+
151
+ rightBtn.addEventListener('click', () => {
152
+ if (carPosition < 90) {
153
+ carPosition += 10;
154
+ updateCarPosition();
155
+ }
156
+ });
157
+
158
+ function updateCarPosition() {
159
+ playerCar.style.left = `${carPosition}%`;
160
+ }
161
+
162
+ // Create obstacles
163
+ function createObstacle() {
164
+ if (isGameOver) return;
165
+
166
+ const obstacle = document.createElement('div');
167
+ obstacle.className = 'obstacle';
168
+ obstacle.style.left = `${Math.random() * 80 + 10}%`;
169
+ obstacle.style.top = '-120px';
170
+ gameArea.appendChild(obstacle);
171
+ obstacles.push(obstacle);
172
+
173
+ setTimeout(createObstacle, Math.random() * 2000 + 1000);
174
+ }
175
+
176
+ // Move obstacles
177
+ function moveObstacles() {
178
+ obstacles.forEach((obstacle, index) => {
179
+ const obstacleTop = parseInt(obstacle.style.top) + gameSpeed;
180
+ obstacle.style.top = `${obstacleTop}px`;
181
+
182
+ // Check collision
183
+ if (obstacleTop > gameArea.offsetHeight - 200 &&
184
+ obstacleTop < gameArea.offsetHeight - 50 &&
185
+ Math.abs(parseInt(obstacle.style.left) - carPosition) < 10) {
186
+ gameOver();
187
+ }
188
+
189
+ // Remove obstacle when off screen
190
+ if (obstacleTop > gameArea.offsetHeight) {
191
+ obstacle.remove();
192
+ obstacles.splice(index, 1);
193
+ score++;
194
+ scoreElement.textContent = score;
195
+
196
+ // Increase speed every 5 points
197
+ if (score % 5 === 0) {
198
+ gameSpeed += 0.5;
199
+ }
200
+ }
201
+ });
202
+
203
+ if (!isGameOver) {
204
+ animationId = requestAnimationFrame(moveObstacles);
205
+ }
206
+ }
207
+
208
+ // Game over function
209
+ function gameOver() {
210
+ isGameOver = true;
211
+ cancelAnimationFrame(animationId);
212
+
213
+ // Update high score
214
+ if (score > highScore) {
215
+ highScore = score;
216
+ localStorage.setItem('f1HighScore', highScore);
217
+ highScoreElement.textContent = highScore;
218
+ }
219
+
220
+ finalScoreElement.textContent = score;
221
+ gameOverElement.style.display = 'block';
222
+ }
223
+
224
+ // Restart game
225
+ function restartGame() {
226
+ // Clear obstacles
227
+ obstacles.forEach(obstacle => obstacle.remove());
228
+ obstacles = [];
229
+
230
+ // Reset variables
231
+ score = 0;
232
+ gameSpeed = 5;
233
+ isGameOver = false;
234
+
235
+ // Update displays
236
+ scoreElement.textContent = score;
237
+ gameOverElement.style.display = 'none';
238
+
239
+ // Start game
240
+ createObstacle();
241
+ moveObstacles();
242
+ }
243
+
244
+ restartBtn.addEventListener('click', restartGame);
245
+
246
+ // Start game
247
+ createObstacle();
248
+ moveObstacles();
249
+ </script>
250
+ </body>
251
+ </html>
formula1.html CHANGED
@@ -45,8 +45,9 @@
45
  <a href="#" class="hover:text-f1red">News</a>
46
  <a href="#" class="hover:text-f1red">Schedule</a>
47
  <a href="#" class="hover:text-f1red">Drivers</a>
48
- <a href="#" class="hover:text-f1red">Teams</a>
49
- <a href="#" class="hover:text-f1red">Standings</a>
 
50
  </div>
51
  </div>
52
  <div class="flex items-center space-x-4">
@@ -394,7 +395,8 @@
394
  <li><a href="#" class="text-gray-400 hover:text-f1red">Schedule</a></li>
395
  <li><a href="#" class="text-gray-400 hover:text-f1red">Drivers</a></li>
396
  <li><a href="#" class="text-gray-400 hover:text-f1red">Teams</a></li>
397
- </ul>
 
398
  </div>
399
  <div>
400
  <h3 class="text-lg font-bold mb-4">Follow Us</h3>
 
45
  <a href="#" class="hover:text-f1red">News</a>
46
  <a href="#" class="hover:text-f1red">Schedule</a>
47
  <a href="#" class="hover:text-f1red">Drivers</a>
48
+ <a href="#" class="hover:text-f1red">Teams</a>
49
+ <a href="f1game.html" class="hover:text-f1red">Game</a>
50
+ <a href="#" class="hover:text-f1red">Standings</a>
51
  </div>
52
  </div>
53
  <div class="flex items-center space-x-4">
 
395
  <li><a href="#" class="text-gray-400 hover:text-f1red">Schedule</a></li>
396
  <li><a href="#" class="text-gray-400 hover:text-f1red">Drivers</a></li>
397
  <li><a href="#" class="text-gray-400 hover:text-f1red">Teams</a></li>
398
+ <li><a href="f1game.html" class="text-gray-400 hover:text-f1red">F1 Game</a></li>
399
+ </ul>
400
  </div>
401
  <div>
402
  <h3 class="text-lg font-bold mb-4">Follow Us</h3>
index.html CHANGED
@@ -104,6 +104,7 @@
104
  <a href="#" class="text-sm font-medium hover:text-primary">Toys & Games</a>
105
  <a href="#" class="text-sm font-medium hover:text-primary">Pet Supplies</a>
106
  <a href="formula1.html" class="text-sm font-medium hover:text-primary">Sports</a>
 
107
  </div>
108
  </div>
109
  </nav>
 
104
  <a href="#" class="text-sm font-medium hover:text-primary">Toys & Games</a>
105
  <a href="#" class="text-sm font-medium hover:text-primary">Pet Supplies</a>
106
  <a href="formula1.html" class="text-sm font-medium hover:text-primary">Sports</a>
107
+ <a href="f1game.html" class="text-sm font-medium hover:text-primary">F1 Game</a>
108
  </div>
109
  </div>
110
  </nav>