Okwutecloud commited on
Commit
054b578
·
verified ·
1 Parent(s): c96693a

Using javascript, bootstrap, and c# and c++ create a motorsport game

Browse files
Files changed (3) hide show
  1. f1game.html +4 -2
  2. index.html +1 -0
  3. motorsport.html +345 -0
f1game.html CHANGED
@@ -140,12 +140,14 @@
140
  New Race
141
  </button>
142
  </div>
143
-
144
  <div class="controls">
145
  <button class="control-btn" id="leftBtn"><i data-feather="chevron-left"></i></button>
146
  <button class="control-btn" id="rightBtn"><i data-feather="chevron-right"></i></button>
147
  </div>
148
- </div>
 
 
 
149
 
150
  <script>
151
  feather.replace();
 
140
  New Race
141
  </button>
142
  </div>
 
143
  <div class="controls">
144
  <button class="control-btn" id="leftBtn"><i data-feather="chevron-left"></i></button>
145
  <button class="control-btn" id="rightBtn"><i data-feather="chevron-right"></i></button>
146
  </div>
147
+ <div class="text-center mt-3">
148
+ <a href="motorsport.html" class="text-white hover:text-red-500">Try Our New Motorsport Game</a>
149
+ </div>
150
+ </div>
151
 
152
  <script>
153
  feather.replace();
index.html CHANGED
@@ -105,6 +105,7 @@
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>
 
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
+ <a href="motorsport.html" class="text-sm font-medium hover:text-primary">Motorsport</a>
109
  </div>
110
  </div>
111
  </nav>
motorsport.html ADDED
@@ -0,0 +1,345 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>Motorsport Racing Game</title>
7
+ <!-- Bootstrap CSS -->
8
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
9
+ <style>
10
+ body {
11
+ background-color: #121212;
12
+ color: white;
13
+ overflow: hidden;
14
+ font-family: 'Arial', sans-serif;
15
+ }
16
+ #gameContainer {
17
+ position: relative;
18
+ width: 100%;
19
+ height: 100vh;
20
+ overflow: hidden;
21
+ }
22
+ #track {
23
+ position: absolute;
24
+ width: 100%;
25
+ height: 200%;
26
+ background-color: #333;
27
+ background-image: linear-gradient(90deg, #555 1px, transparent 1px),
28
+ linear-gradient(#555 1px, transparent 1px);
29
+ background-size: 40px 40px;
30
+ }
31
+ #playerCar {
32
+ position: absolute;
33
+ width: 60px;
34
+ height: 120px;
35
+ background-image: url('http://static.photos/automotive/200x200/1');
36
+ background-size: contain;
37
+ background-repeat: no-repeat;
38
+ bottom: 50px;
39
+ left: 50%;
40
+ transform: translateX(-50%);
41
+ z-index: 10;
42
+ }
43
+ .opponent {
44
+ position: absolute;
45
+ width: 60px;
46
+ height: 120px;
47
+ background-size: contain;
48
+ background-repeat: no-repeat;
49
+ z-index: 5;
50
+ }
51
+ #hud {
52
+ position: absolute;
53
+ top: 20px;
54
+ left: 20px;
55
+ background-color: rgba(0,0,0,0.7);
56
+ padding: 10px;
57
+ border-radius: 5px;
58
+ z-index: 20;
59
+ }
60
+ #gameOverModal {
61
+ z-index: 30;
62
+ }
63
+ .control-btn {
64
+ width: 80px;
65
+ height: 80px;
66
+ font-size: 24px;
67
+ }
68
+ </style>
69
+ </head>
70
+ <body>
71
+ <div id="gameContainer">
72
+ <div id="track"></div>
73
+ <div id="playerCar"></div>
74
+
75
+ <div id="hud" class="text-white">
76
+ <h3>LAP: <span id="lapCounter">1</span>/3</h3>
77
+ <p>POSITION: <span id="position">1</span></p>
78
+ <p>TIME: <span id="raceTime">0:00.000</span></p>
79
+ <p>BEST: <span id="bestTime">0:00.000</span></p>
80
+ <p>SPEED: <span id="speed">200</span> km/h</p>
81
+ </div>
82
+
83
+ <!-- Game Over Modal -->
84
+ <div class="modal fade" id="gameOverModal" tabindex="-1" aria-hidden="true">
85
+ <div class="modal-dialog modal-dialog-centered">
86
+ <div class="modal-content bg-dark text-white">
87
+ <div class="modal-header border-0">
88
+ <h5 class="modal-title">Race Finished</h5>
89
+ </div>
90
+ <div class="modal-body text-center">
91
+ <h2 class="mb-3">Final Position: <span id="finalPosition">1</span></h2>
92
+ <p class="mb-1">Best Lap: <span id="finalBestTime">0:00.000</span></p>
93
+ <p>Total Time: <span id="finalTotalTime">0:00.000</span></p>
94
+ </div>
95
+ <div class="modal-footer border-0 justify-content-center">
96
+ <button id="restartBtn" class="btn btn-danger px-4">Race Again</button>
97
+ </div>
98
+ </div>
99
+ </div>
100
+ </div>
101
+
102
+ <!-- Mobile Controls -->
103
+ <div class="d-flex justify-content-center gap-4 fixed-bottom mb-4 d-md-none">
104
+ <button id="leftBtn" class="btn btn-primary control-btn rounded-circle">←</button>
105
+ <button id="rightBtn" class="btn btn-primary control-btn rounded-circle">→</button>
106
+ </div>
107
+ </div>
108
+
109
+ <!-- Bootstrap JS -->
110
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
111
+
112
+ <script>
113
+ // Game state
114
+ const gameState = {
115
+ lap: 1,
116
+ position: 1,
117
+ speed: 200,
118
+ isRaceOver: false,
119
+ opponents: [],
120
+ trackPosition: 0,
121
+ raceStartTime: 0,
122
+ currentLapTime: 0,
123
+ bestLapTime: 0,
124
+ totalRaceTime: 0,
125
+ playerX: 50,
126
+ gameSpeed: 5
127
+ };
128
+
129
+ // DOM elements
130
+ const track = document.getElementById('track');
131
+ const playerCar = document.getElementById('playerCar');
132
+ const lapCounter = document.getElementById('lapCounter');
133
+ const positionElement = document.getElementById('position');
134
+ const raceTimeElement = document.getElementById('raceTime');
135
+ const bestTimeElement = document.getElementById('bestTime');
136
+ const speedElement = document.getElementById('speed');
137
+ const finalPositionElement = document.getElementById('finalPosition');
138
+ const finalBestTimeElement = document.getElementById('finalBestTime');
139
+ const finalTotalTimeElement = document.getElementById('finalTotalTime');
140
+ const gameOverModal = new bootstrap.Modal(document.getElementById('gameOverModal'));
141
+ const restartBtn = document.getElementById('restartBtn');
142
+ const leftBtn = document.getElementById('leftBtn');
143
+ const rightBtn = document.getElementById('rightBtn');
144
+
145
+ // Initialize game
146
+ function initGame() {
147
+ // Reset game state
148
+ gameState.lap = 1;
149
+ gameState.position = 1;
150
+ gameState.speed = 200;
151
+ gameState.isRaceOver = false;
152
+ gameState.trackPosition = 0;
153
+ gameState.raceStartTime = Date.now();
154
+ gameState.currentLapTime = 0;
155
+ gameState.totalRaceTime = 0;
156
+ gameState.playerX = 50;
157
+ gameState.gameSpeed = 5;
158
+
159
+ // Clear existing opponents
160
+ gameState.opponents.forEach(opponent => {
161
+ if (opponent.element && opponent.element.parentNode) {
162
+ opponent.element.parentNode.removeChild(opponent.element);
163
+ }
164
+ });
165
+ gameState.opponents = [];
166
+
167
+ // Update UI
168
+ lapCounter.textContent = gameState.lap;
169
+ positionElement.textContent = gameState.position;
170
+ raceTimeElement.textContent = formatTime(0);
171
+ bestTimeElement.textContent = formatTime(0);
172
+ speedElement.textContent = gameState.speed;
173
+ playerCar.style.left = `${gameState.playerX}%`;
174
+
175
+ // Create opponents
176
+ createOpponents();
177
+
178
+ // Start game loop
179
+ requestAnimationFrame(gameLoop);
180
+ }
181
+
182
+ // Game loop
183
+ function gameLoop() {
184
+ if (gameState.isRaceOver) return;
185
+
186
+ // Move track
187
+ gameState.trackPosition += gameState.gameSpeed;
188
+ track.style.backgroundPositionY = `${gameState.trackPosition}px`;
189
+
190
+ // Move opponents
191
+ moveOpponents();
192
+
193
+ // Update lap time
194
+ updateLapTime();
195
+
196
+ // Check lap completion
197
+ if (gameState.trackPosition % 5000 < gameState.gameSpeed) {
198
+ completeLap();
199
+ }
200
+
201
+ requestAnimationFrame(gameLoop);
202
+ }
203
+
204
+ // Create opponents
205
+ function createOpponents() {
206
+ const opponentImages = [
207
+ 'http://static.photos/automotive/200x200/2',
208
+ 'http://static.photos/automotive/200x200/3',
209
+ 'http://static.photos/automotive/200x200/4',
210
+ 'http://static.photos/automotive/200x200/5'
211
+ ];
212
+
213
+ for (let i = 0; i < 5; i++) {
214
+ const opponent = document.createElement('div');
215
+ opponent.className = 'opponent';
216
+ opponent.style.backgroundImage = `url('${opponentImages[i % opponentImages.length]}')`;
217
+
218
+ const xPos = 30 + Math.random() * 40;
219
+ const yPos = -200 - Math.random() * 300;
220
+
221
+ opponent.style.left = `${xPos}%`;
222
+ opponent.style.top = `${yPos}px`;
223
+
224
+ document.getElementById('gameContainer').appendChild(opponent);
225
+
226
+ gameState.opponents.push({
227
+ element: opponent,
228
+ x: xPos,
229
+ y: yPos,
230
+ speed: 3 + Math.random() * 3
231
+ });
232
+ }
233
+ }
234
+
235
+ // Move opponents
236
+ function moveOpponents() {
237
+ gameState.opponents.forEach((opponent, index) => {
238
+ opponent.y += opponent.speed;
239
+ opponent.x += Math.sin(Date.now() / 1000 + index) * 0.5;
240
+
241
+ // Wrap around track
242
+ if (opponent.y > window.innerHeight) {
243
+ opponent.y = -200;
244
+ opponent.x = 30 + Math.random() * 40;
245
+ }
246
+
247
+ opponent.element.style.top = `${opponent.y}px`;
248
+ opponent.element.style.left = `${opponent.x}%`;
249
+
250
+ // Simple collision detection
251
+ if (Math.abs(opponent.x - gameState.playerX) < 10 &&
252
+ Math.abs(opponent.y - (window.innerHeight - 170)) < 100) {
253
+ handleCollision();
254
+ }
255
+ });
256
+ }
257
+
258
+ // Handle collision
259
+ function handleCollision() {
260
+ gameState.speed = Math.max(100, gameState.speed - 20);
261
+ speedElement.textContent = gameState.speed;
262
+ gameState.gameSpeed = Math.max(2, gameState.gameSpeed - 0.5);
263
+ }
264
+
265
+ // Update lap time
266
+ function updateLapTime() {
267
+ const currentTime = Date.now();
268
+ gameState.currentLapTime = currentTime - (gameState.raceStartTime + gameState.totalRaceTime);
269
+ gameState.totalRaceTime = currentTime - gameState.raceStartTime;
270
+
271
+ raceTimeElement.textContent = formatTime(gameState.currentLapTime);
272
+ speedElement.textContent = Math.floor(gameState.speed + Math.random() * 5);
273
+ }
274
+
275
+ // Format time
276
+ function formatTime(ms) {
277
+ const minutes = Math.floor(ms / 60000);
278
+ const seconds = Math.floor((ms % 60000) / 1000);
279
+ const milliseconds = ms % 1000;
280
+ return `${minutes}:${seconds.toString().padStart(2, '0')}.${milliseconds.toString().padStart(3, '0')}`;
281
+ }
282
+
283
+ // Complete a lap
284
+ function completeLap() {
285
+ gameState.lap++;
286
+ lapCounter.textContent = gameState.lap;
287
+
288
+ // Update best lap time
289
+ if (gameState.currentLapTime < gameState.bestLapTime || gameState.bestLapTime === 0) {
290
+ gameState.bestLapTime = gameState.currentLapTime;
291
+ bestTimeElement.textContent = formatTime(gameState.bestLapTime);
292
+ }
293
+
294
+ // Check race completion
295
+ if (gameState.lap > 3) {
296
+ finishRace();
297
+ } else {
298
+ // Reset lap timer
299
+ gameState.raceStartTime = Date.now() - gameState.totalRaceTime;
300
+ }
301
+ }
302
+
303
+ // Finish race
304
+ function finishRace() {
305
+ gameState.isRaceOver = true;
306
+
307
+ finalPositionElement.textContent = gameState.position;
308
+ finalBestTimeElement.textContent = formatTime(gameState.bestLapTime);
309
+ finalTotalTimeElement.textContent = formatTime(gameState.totalRaceTime);
310
+
311
+ gameOverModal.show();
312
+ }
313
+
314
+ // Keyboard controls
315
+ document.addEventListener('keydown', (e) => {
316
+ if (e.key === 'ArrowLeft') {
317
+ gameState.playerX = Math.max(20, gameState.playerX - 5);
318
+ } else if (e.key === 'ArrowRight') {
319
+ gameState.playerX = Math.min(80, gameState.playerX + 5);
320
+ }
321
+ playerCar.style.left = `${gameState.playerX}%`;
322
+ });
323
+
324
+ // Touch controls
325
+ leftBtn.addEventListener('click', () => {
326
+ gameState.playerX = Math.max(20, gameState.playerX - 5);
327
+ playerCar.style.left = `${gameState.playerX}%`;
328
+ });
329
+
330
+ rightBtn.addEventListener('click', () => {
331
+ gameState.playerX = Math.min(80, gameState.playerX + 5);
332
+ playerCar.style.left = `${gameState.playerX}%`;
333
+ });
334
+
335
+ // Restart game
336
+ restartBtn.addEventListener('click', () => {
337
+ gameOverModal.hide();
338
+ initGame();
339
+ });
340
+
341
+ // Initialize game when page loads
342
+ window.addEventListener('load', initGame);
343
+ </script>
344
+ </body>
345
+ </html>