AdhamYasser2025 commited on
Commit
d45ca85
·
verified ·
1 Parent(s): a0dc6b6

اعملي لعبة سباق سيارات ثري دي بسيطة للموبايل

Browse files
Files changed (2) hide show
  1. README.md +8 -5
  2. index.html +379 -18
README.md CHANGED
@@ -1,10 +1,13 @@
1
  ---
2
- title: Pixelrush Racer 3d
3
- emoji: 👀
4
- colorFrom: gray
5
- colorTo: red
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  ---
2
+ title: PixelRush Racer 3D 🏎️
3
+ colorFrom: green
4
+ colorTo: pink
5
+ emoji: 🐳
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite-v3
10
  ---
11
 
12
+ # Welcome to your new DeepSite project!
13
+ This project was created with [DeepSite](https://deepsite.hf.co).
index.html CHANGED
@@ -1,19 +1,380 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
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, user-scalable=no">
6
+ <title>PixelRush Racer 3D</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://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
10
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
11
+ <script src="https://unpkg.com/feather-icons"></script>
12
+ <style>
13
+ * {
14
+ margin: 0;
15
+ padding: 0;
16
+ box-sizing: border-box;
17
+ touch-action: manipulation;
18
+ }
19
+ body {
20
+ overflow: hidden;
21
+ font-family: 'Segoe UI', system-ui, sans-serif;
22
+ }
23
+ #gameContainer {
24
+ position: relative;
25
+ width: 100vw;
26
+ height: 100vh;
27
+ }
28
+ #uiOverlay {
29
+ position: absolute;
30
+ top: 0;
31
+ left: 0;
32
+ width: 100%;
33
+ height: 100%;
34
+ pointer-events: none;
35
+ z-index: 10;
36
+ }
37
+ .control-btn {
38
+ pointer-events: auto;
39
+ background: rgba(255, 255, 255, 0.2);
40
+ backdrop-filter: blur(10px);
41
+ border: 2px solid rgba(255, 255, 255, 0.3);
42
+ border-radius: 50%;
43
+ width: 80px;
44
+ height: 80px;
45
+ display: flex;
46
+ align-items: center;
47
+ justify-content: center;
48
+ color: white;
49
+ font-size: 24px;
50
+ transition: all 0.2s ease;
51
+ }
52
+ .control-btn:active {
53
+ background: rgba(255, 255, 255, 0.4);
54
+ transform: scale(0.95);
55
+ }
56
+ #scoreDisplay {
57
+ background: rgba(0, 0, 0, 0.7);
58
+ backdrop-filter: blur(10px);
59
+ border-radius: 20px;
60
+ padding: 15px 25px;
61
+ }
62
+ #startScreen, #gameOverScreen {
63
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
64
+ }
65
+ .floating {
66
+ animation: float 3s ease-in-out infinite;
67
+ }
68
+ @keyframes float {
69
+ 0%, 100% { transform: translateY(0px); }
70
+ 50% { transform: translateY(-10px); }
71
+ }
72
+ </style>
73
+ </head>
74
+ <body class="bg-gray-900">
75
+ <div id="gameContainer">
76
+ <canvas id="gameCanvas"></canvas>
77
+
78
+ <div id="uiOverlay" class="flex flex-col h-full">
79
+ <!-- Top Bar -->
80
+ <div class="flex justify-between items-start p-6">
81
+ <div id="scoreDisplay" class="text-white font-bold text-xl">
82
+ Score: <span id="score">0</span>
83
+ </div>
84
+ <div class="flex gap-4">
85
+ <div class="control-btn" id="pauseBtn">
86
+ <i data-feather="pause"></i>
87
+ </div>
88
+ </div>
89
+ </div>
90
+
91
+ <!-- Controls -->
92
+ <div class="flex-1 flex items-end justify-between p-8">
93
+ <div class="control-btn" id="leftBtn">
94
+ <i data-feather="chevron-left"></i>
95
+ </div>
96
+ <div class="control-btn" id="rightBtn">
97
+ <i data-feather="chevron-right"></i>
98
+ </div>
99
+ </div>
100
+ </div>
101
+
102
+ <!-- Start Screen -->
103
+ <div id="startScreen" class="absolute inset-0 flex items-center justify-center z-20">
104
+ <div class="text-center text-white p-8 max-w-md">
105
+ <div class="floating mb-8">
106
+ <i data-feather="flag" class="w-24 h-24 mx-auto"></i>
107
+ </div>
108
+ <h1 class="text-5xl font-bold mb-4 bg-gradient-to-r from-yellow-400 to-orange-500 bg-clip-text text-transparent">
109
+ PixelRush Racer
110
+ </h1>
111
+ <p class="text-xl mb-8 opacity-90">Swipe or tap to dodge obstacles!</p>
112
+ <button id="startBtn" class="bg-gradient-to-r from-green-400 to-blue-500 hover:from-green-500 hover:to-blue-600 text-white font-bold py-4 px-8 rounded-full text-xl transition-all duration-300 transform hover:scale-105 shadow-2xl">
113
+ START RACE
114
+ </button>
115
+ </div>
116
+ </div>
117
+
118
+ <!-- Game Over Screen -->
119
+ <div id="gameOverScreen" class="absolute inset-0 flex items-center justify-center z-20 hidden">
120
+ <div class="text-center text-white p-8 max-w-md">
121
+ <i data-feather="flag" class="w-16 h-16 mx-auto mb-4"></i>
122
+ <h2 class="text-4xl font-bold mb-2">Race Over!</h2>
123
+ <p class="text-2xl mb-4">Final Score: <span id="finalScore">0</span></p>
124
+ <div class="flex gap-4 justify-center">
125
+ <button id="restartBtn" class="bg-gradient-to-r from-green-400 to-blue-500 text-white font-bold py-3 px-6 rounded-full transition-all duration-300 transform hover:scale-105">
126
+ RESTART
127
+ </button>
128
+ <button id="menuBtn" class="bg-gradient-to-r from-gray-600 to-gray-700 text-white font-bold py-3 px-6 rounded-full transition-all duration-300 transform hover:scale-105">
129
+ MENU
130
+ </button>
131
+ </div>
132
+ </div>
133
+ </div>
134
+ </div>
135
+
136
+ <script>
137
+ // Game Variables
138
+ let scene, camera, renderer, car, obstacles = [];
139
+ let score = 0;
140
+ let gameSpeed = 0.1;
141
+ let carPosition = 0;
142
+ let gameActive = false;
143
+ let lastObstacleTime = 0;
144
+ const lanePositions = [-2, 0, 2];
145
+
146
+ // Initialize Three.js
147
+ function init() {
148
+ // Scene
149
+ scene = new THREE.Scene();
150
+ scene.background = new THREE.Color(0x87CEEB);
151
+
152
+ // Camera
153
+ camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
154
+ camera.position.set(0, 5, 10);
155
+ camera.lookAt(0, 0, 0);
156
+
157
+ // Renderer
158
+ renderer = new THREE.WebGLRenderer({ canvas: document.getElementById('gameCanvas'), antialias: true });
159
+ renderer.setSize(window.innerWidth, window.innerHeight);
160
+ renderer.shadowMap.enabled = true;
161
+
162
+ // Lighting
163
+ const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
164
+ scene.add(ambientLight);
165
+
166
+ const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
167
+ directionalLight.position.set(10, 20, 5);
168
+ directionalLight.castShadow = true;
169
+ scene.add(directionalLight);
170
+
171
+ // Road
172
+ const roadGeometry = new THREE.PlaneGeometry(20, 1000);
173
+ const roadMaterial = new THREE.MeshStandardMaterial({ color: 0x333333 });
174
+ const road = new THREE.Mesh(roadGeometry, roadMaterial);
175
+ road.rotation.x = -Math.PI / 2;
176
+ road.receiveShadow = true;
177
+ scene.add(road);
178
+
179
+ // Road markings
180
+ for (let i = -500; i < 500; i += 4) {
181
+ const markingGeometry = new THREE.PlaneGeometry(0.5, 2);
182
+ const markingMaterial = new THREE.MeshStandardMaterial({ color: 0xffffff });
183
+ const marking = new THREE.Mesh(markingGeometry, markingMaterial);
184
+ marking.rotation.x = -Math.PI / 2;
185
+ marking.position.set(0, 0.01, i);
186
+ scene.add(marking);
187
+ }
188
+
189
+ // Create player car
190
+ const carGeometry = new THREE.BoxGeometry(1, 0.5, 2);
191
+ const carMaterial = new THREE.MeshStandardMaterial({ color: 0xff4444 });
192
+ car = new THREE.Mesh(carGeometry, carMaterial);
193
+ car.position.y = 0.5;
194
+ car.castShadow = true;
195
+ scene.add(car);
196
+
197
+ // Event Listeners
198
+ setupEventListeners();
199
+
200
+ // Start animation loop
201
+ animate();
202
+ }
203
+
204
+ function setupEventListeners() {
205
+ // Control buttons
206
+ document.getElementById('leftBtn').addEventListener('click', moveLeft);
207
+ document.getElementById('rightBtn').addEventListener('click', moveRight);
208
+ document.getElementById('startBtn').addEventListener('click', startGame);
209
+ document.getElementById('restartBtn').addEventListener('click', restartGame);
210
+ document.getElementById('menuBtn').addEventListener('click', showMenu);
211
+ document.getElementById('pauseBtn').addEventListener('click', togglePause);
212
+
213
+ // Touch controls
214
+ let touchStartX = 0;
215
+ document.addEventListener('touchstart', (e) => {
216
+ touchStartX = e.touches[0].clientX;
217
+ });
218
+
219
+ document.addEventListener('touchend', (e) => {
220
+ if (!gameActive) return;
221
+
222
+ const touchEndX = e.changedTouches[0].clientX;
223
+ const diff = touchEndX - touchStartX;
224
+
225
+ if (Math.abs(diff) > 50) {
226
+ if (diff > 0) {
227
+ moveRight();
228
+ } else {
229
+ moveLeft();
230
+ }
231
+ }
232
+ });
233
+
234
+ // Keyboard controls
235
+ document.addEventListener('keydown', (e) => {
236
+ if (!gameActive) return;
237
+
238
+ if (e.key === 'ArrowLeft') {
239
+ moveLeft();
240
+ } else if (e.key === 'ArrowRight') {
241
+ moveRight();
242
+ }
243
+ });
244
+
245
+ // Window resize
246
+ window.addEventListener('resize', () => {
247
+ camera.aspect = window.innerWidth / window.innerHeight;
248
+ camera.updateProjectionMatrix();
249
+ renderer.setSize(window.innerWidth, window.innerHeight);
250
+ });
251
+ }
252
+
253
+ function moveLeft() {
254
+ if (!gameActive) return;
255
+
256
+ const currentLane = lanePositions.indexOf(carPosition);
257
+ if (currentLane > 0) {
258
+ carPosition = lanePositions[currentLane - 1];
259
+ }
260
+ }
261
+
262
+ function moveRight() {
263
+ if (!gameActive) return;
264
+
265
+ const currentLane = lanePositions.indexOf(carPosition);
266
+ if (currentLane < lanePositions.length - 1) {
267
+ carPosition = lanePositions[currentLane + 1];
268
+ }
269
+ }
270
+
271
+ function startGame() {
272
+ document.getElementById('startScreen').classList.add('hidden');
273
+ gameActive = true;
274
+ score = 0;
275
+ gameSpeed = 0.1;
276
+ carPosition = 0;
277
+ obstacles.forEach(obstacle => scene.remove(obstacle));
278
+ obstacles = [];
279
+ updateScore();
280
+ }
281
+
282
+ function restartGame() {
283
+ document.getElementById('gameOverScreen').classList.add('hidden');
284
+ startGame();
285
+ }
286
+
287
+ function showMenu() {
288
+ document.getElementById('gameOverScreen').classList.add('hidden');
289
+ document.getElementById('startScreen').classList.remove('hidden');
290
+ gameActive = false;
291
+ }
292
+
293
+ function togglePause() {
294
+ gameActive = !gameActive;
295
+ const icon = document.querySelector('#pauseBtn i');
296
+ if (gameActive) {
297
+ icon.setAttribute('data-feather', 'pause');
298
+ } else {
299
+ icon.setAttribute('data-feather', 'play');
300
+ }
301
+ feather.replace();
302
+ }
303
+
304
+ function spawnObstacle() {
305
+ const obstacleGeometry = new THREE.BoxGeometry(1, 1, 1);
306
+ const obstacleMaterial = new THREE.MeshStandardMaterial({ color: Math.random() * 0xffffff });
307
+ const obstacle = new THREE.Mesh(obstacleGeometry, obstacleMaterial);
308
+
309
+ obstacle.position.x = lanePositions[Math.floor(Math.random() * lanePositions.length)];
310
+ obstacle.position.y = 0.5;
311
+ obstacle.position.z = -20;
312
+ obstacle.castShadow = true;
313
+
314
+ scene.add(obstacle);
315
+ obstacles.push(obstacle);
316
+ }
317
+
318
+ function updateScore() {
319
+ document.getElementById('score').textContent = score;
320
+ }
321
+
322
+ function checkCollision() {
323
+ const carBox = new THREE.Box3().setFromObject(car);
324
+
325
+ for (let obstacle of obstacles) {
326
+ const obstacleBox = new THREE.Box3().setFromObject(obstacle);
327
+ if (carBox.intersectsBox(obstacleBox)) {
328
+ gameOver();
329
+ return;
330
+ }
331
+ }
332
+ }
333
+
334
+ function gameOver() {
335
+ gameActive = false;
336
+ document.getElementById('finalScore').textContent = score;
337
+ document.getElementById('gameOverScreen').classList.remove('hidden');
338
+ }
339
+
340
+ function animate() {
341
+ requestAnimationFrame(animate);
342
+
343
+ if (gameActive) {
344
+ // Move car smoothly to target position
345
+ car.position.x += (carPosition - car.position.x) * 0.2;
346
+
347
+ // Spawn obstacles
348
+ const currentTime = Date.now();
349
+ if (currentTime - lastObstacleTime > 2000 - (score * 10)) {
350
+ spawnObstacle();
351
+ lastObstacleTime = currentTime;
352
+ }
353
+
354
+ // Update obstacles
355
+ for (let i = obstacles.length - 1; i >= 0; i--) {
356
+ obstacles[i].position.z += gameSpeed;
357
+
358
+ // Remove obstacles that are behind the camera
359
+ if (obstacles[i].position.z > 10) {
360
+ scene.remove(obstacles[i]);
361
+ obstacles.splice(i, 1);
362
+ score++;
363
+ gameSpeed += 0.001;
364
+ updateScore();
365
+ }
366
+ }
367
+
368
+ // Check collisions
369
+ checkCollision();
370
+ }
371
+
372
+ renderer.render(scene, camera);
373
+ }
374
+
375
+ // Initialize game when page loads
376
+ window.addEventListener('load', init);
377
+ feather.replace();
378
+ </script>
379
+ </body>
380
  </html>