akhaliq HF Staff commited on
Commit
e15dd3f
Β·
verified Β·
1 Parent(s): 79619b4

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +166 -179
index.html CHANGED
@@ -1,229 +1,216 @@
1
  <!DOCTYPE html>
2
  <html>
3
  <head>
4
- <title>Space Runner Mobile</title>
 
5
  <style>
6
- body { margin: 0; overflow: hidden; touch-action: none; }
 
7
  #hud {
8
  position: fixed;
9
- top: 10px;
10
- left: 10px;
11
- color: #0f0;
12
  font-family: Arial;
13
- font-size: 20px;
14
- padding: 10px;
15
- background: rgba(0,0,0,0.7);
16
- border-radius: 5px;
17
  z-index: 100;
18
  }
19
- #controls {
 
20
  position: fixed;
21
- bottom: 20px;
22
- width: 100%;
23
- display: flex;
24
- justify-content: space-between;
25
- padding: 0 20px;
26
- box-sizing: border-box;
27
  }
28
- .control-btn {
29
- width: 60px;
30
- height: 60px;
31
- background: rgba(255,255,255,0.2);
32
- border-radius: 50%;
33
- display: flex;
34
- justify-content: center;
35
- align-items: center;
36
- color: white;
37
- font-size: 24px;
38
- touch-action: none;
 
 
39
  }
40
  </style>
41
  </head>
42
  <body>
43
  <div id="hud">
44
- <div>πŸš€: <span id="speed">0</span></div>
45
- <div>πŸ›‘οΈ: <span id="shield">100</span>%</div>
46
- <div>⭐: <span id="score">0</span></div>
47
  </div>
48
- <div id="controls">
49
- <div class="control-btn" id="left">←</div>
50
- <div class="control-btn" id="right">β†’</div>
51
  </div>
 
52
 
53
  <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
54
  <script>
55
- // Scene setup
 
 
 
 
 
 
 
 
 
 
 
 
56
  const scene = new THREE.Scene();
57
  const camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
58
  const renderer = new THREE.WebGLRenderer({ antialias: true });
59
  renderer.setSize(window.innerWidth, window.innerHeight);
60
  document.body.appendChild(renderer.domElement);
61
 
62
- // Player Ship (clearly visible pyramid)
63
- const shipGeometry = new THREE.ConeGeometry(0.8, 2, 4);
64
- const shipMaterial = new THREE.MeshPhongMaterial({
65
- color: 0x00ff88,
66
- emissive: 0x005500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  });
68
- const ship = new THREE.Mesh(shipGeometry, shipMaterial);
69
- ship.rotation.x = Math.PI / 2;
70
- scene.add(ship);
71
-
72
- // Floor (colorful grid for better orientation)
73
- const grid = new THREE.GridHelper(40, 40, 0x4444ff, 0x222266);
74
- scene.add(grid);
75
-
76
- // Lighting
77
- const ambientLight = new THREE.AmbientLight(0x404040);
78
- scene.add(ambientLight);
79
- const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
80
- directionalLight.position.set(0, 10, 5);
81
- scene.add(directionalLight);
82
-
83
- // Game state
84
- let asteroids = [];
85
- let powerUps = [];
86
- let currentSpeed = 0;
87
- let shields = 100;
88
- let score = 0;
89
- let touchX = 0;
90
- const MAX_SPEED = 0.3;
91
-
92
- // Mobile controls
93
- let controls = {
94
- left: false,
95
- right: false
96
- };
97
-
98
- // Touch handling
99
- document.getElementById('left').addEventListener('touchstart', () => controls.left = true);
100
- document.getElementById('left').addEventListener('touchend', () => controls.left = false);
101
- document.getElementById('right').addEventListener('touchstart', () => controls.right = true);
102
- document.getElementById('right').addEventListener('touchend', () => controls.right = false);
103
-
104
- // Keyboard controls
105
- window.addEventListener('keydown', (e) => {
106
- if(e.key === 'ArrowLeft') controls.left = true;
107
- if(e.key === 'ArrowRight') controls.right = true;
108
- });
109
- window.addEventListener('keyup', (e) => {
110
- if(e.key === 'ArrowLeft') controls.left = false;
111
- if(e.key === 'ArrowRight') controls.right = false;
112
  });
113
 
114
- // Create clearly visible asteroids
115
- const createAsteroid = () => {
116
- const size = 1 + Math.random();
117
- const geometry = new THREE.OctahedronGeometry(size);
118
- const material = new THREE.MeshPhongMaterial({
119
- color: 0xff4444,
120
- emissive: 0x440000
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  });
122
- const asteroid = new THREE.Mesh(geometry, material);
123
- asteroid.position.set(
124
- (Math.random() - 0.5) * 20,
125
- (Math.random() - 0.5) * 10,
126
- -50
127
- );
128
- return asteroid;
129
- };
130
 
131
- // Create power-ups (clearly distinct from asteroids)
132
- const createPowerUp = () => {
133
- const geometry = new THREE.TorusGeometry(0.5, 0.2, 8, 24);
134
- const material = new THREE.MeshPhongMaterial({
135
- color: 0x00ffff,
136
- emissive: 0x004444
137
- });
138
- const powerUp = new THREE.Mesh(geometry, material);
139
- powerUp.position.set(
140
- (Math.random() - 0.5) * 20,
141
- (Math.random() - 0.5) * 10,
 
 
 
 
 
 
 
 
 
 
 
142
  -50
143
  );
144
- return powerUp;
145
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
146
 
147
  function updateHUD() {
148
- document.getElementById('speed').textContent = Math.floor(currentSpeed * 1000);
149
- document.getElementById('shield').textContent = Math.floor(shields);
150
  document.getElementById('score').textContent = score;
 
 
151
  }
152
 
153
- function animate() {
154
- requestAnimationFrame(animate);
155
-
156
- // Ship movement controls
157
- if(controls.left) ship.position.x -= 0.2;
158
- if(controls.right) ship.position.x += 0.2;
159
- ship.position.x = THREE.MathUtils.clamp(ship.position.x, -8, 8);
160
-
161
- // Game progression
162
- currentSpeed = Math.min(currentSpeed + 0.0001, MAX_SPEED);
163
- score += Math.floor(currentSpeed * 100);
164
-
165
- // Asteroid handling
166
- asteroids.forEach((asteroid, index) => {
167
- asteroid.position.z += currentSpeed * 50;
168
- asteroid.rotation.x += 0.02;
169
- asteroid.rotation.y += 0.02;
170
-
171
- if(asteroid.position.z > 20) {
172
- scene.remove(asteroid);
173
- asteroids.splice(index, 1);
174
- }
175
- });
176
-
177
- // Power-up handling
178
- powerUps.forEach((powerUp, index) => {
179
- powerUp.position.z += currentSpeed * 50;
180
- powerUp.rotation.x += 0.05;
181
-
182
- if(powerUp.position.z > 20) {
183
- scene.remove(powerUp);
184
- powerUps.splice(index, 1);
185
- }
186
- });
187
-
188
- // Spawning (slower pace for mobile)
189
- if(Math.random() < 0.015) {
190
- const asteroid = createAsteroid();
191
- scene.add(asteroid);
192
- asteroids.push(asteroid);
193
- }
194
 
195
- if(Math.random() < 0.008) {
196
- const powerUp = createPowerUp();
197
- scene.add(powerUp);
198
- powerUps.push(powerUp);
199
- }
200
-
201
- // Camera follow
202
- camera.position.set(
203
- ship.position.x * 0.5,
204
- ship.position.y + 3,
205
- 5 + currentSpeed * 50
206
- );
207
- camera.lookAt(ship.position);
208
 
209
- renderer.render(scene, camera);
210
- updateHUD();
 
 
 
 
 
 
 
 
211
  }
212
 
213
- // Initial setup
214
  camera.position.z = 5;
215
  animate();
 
216
 
217
- // Responsive handling
218
- window.addEventListener('resize', () => {
219
- camera.aspect = window.innerWidth / window.innerHeight;
220
- camera.updateProjectionMatrix();
221
- renderer.setSize(window.innerWidth, window.innerHeight);
222
  });
223
-
224
- // Prevent touch scrolling
225
- document.body.addEventListener('touchstart', (e) => e.preventDefault(), { passive: false });
226
- document.body.addEventListener('touchmove', (e) => e.preventDefault(), { passive: false });
227
  </script>
228
  </body>
229
  </html>
 
1
  <!DOCTYPE html>
2
  <html>
3
  <head>
4
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
5
+ <title>πŸš€ Galactic Dodge!</title>
6
  <style>
7
+ * { margin: 0; padding: 0; touch-action: manipulation; }
8
+ body { overflow: hidden; background: #000; }
9
  #hud {
10
  position: fixed;
11
+ top: 15px;
12
+ left: 15px;
13
+ color: #fff;
14
  font-family: Arial;
15
+ font-size: 24px;
16
+ text-shadow: 0 0 10px #00ffff;
 
 
17
  z-index: 100;
18
  }
19
+ #gameOver {
20
+ display: none;
21
  position: fixed;
22
+ top: 50%;
23
+ left: 50%;
24
+ transform: translate(-50%, -50%);
25
+ text-align: center;
26
+ color: #fff;
27
+ text-shadow: 0 0 15px #ff0066;
28
  }
29
+ #share {
30
+ display: none;
31
+ position: fixed;
32
+ bottom: 20px;
33
+ left: 50%;
34
+ transform: translateX(-50%);
35
+ padding: 15px 30px;
36
+ background: #00ff88;
37
+ color: #000;
38
+ border: none;
39
+ border-radius: 30px;
40
+ font-size: 20px;
41
+ cursor: pointer;
42
  }
43
  </style>
44
  </head>
45
  <body>
46
  <div id="hud">
47
+ <div>⭐ <span id="score">0</span></div>
48
+ <div>❀️ <span id="lives">3</span></div>
 
49
  </div>
50
+ <div id="gameOver">
51
+ <h1 style="font-size: 2em">GAME OVER!</h1>
52
+ <p style="margin: 20px 0">Score: <span id="finalScore">0</span></p>
53
  </div>
54
+ <button id="share" onclick="shareScore()">Share Your Score πŸ“’</button>
55
 
56
  <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
57
  <script>
58
+ // Game Configuration
59
+ const CONFIG = {
60
+ PLAYER_SPEED: 0.3,
61
+ ASTEROID_SPAWN_RATE: 1000,
62
+ POWERUP_CHANCE: 0.3,
63
+ INITIAL_LIVES: 3
64
+ };
65
+
66
+ // Game State
67
+ let score = 0, lives = CONFIG.INITIAL_LIVES, isGameOver = false;
68
+ let touchStartX = 0, currentX = 0;
69
+
70
+ // Scene Setup
71
  const scene = new THREE.Scene();
72
  const camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
73
  const renderer = new THREE.WebGLRenderer({ antialias: true });
74
  renderer.setSize(window.innerWidth, window.innerHeight);
75
  document.body.appendChild(renderer.domElement);
76
 
77
+ // Player (Simple Pyramid)
78
+ const player = new THREE.Mesh(
79
+ new THREE.ConeGeometry(0.8, 1.5, 4),
80
+ new THREE.MeshBasicMaterial({ color: 0x00ff88 })
81
+ );
82
+ player.position.z = 3;
83
+ scene.add(player);
84
+
85
+ // Particles (Simple Starfield)
86
+ const stars = new THREE.Points(
87
+ new THREE.BufferGeometry().setFromPoints(
88
+ Array(1000).fill().map(() => new THREE.Vector3(
89
+ (Math.random() - 0.5) * 100,
90
+ (Math.random() - 0.5) * 100,
91
+ (Math.random() - 0.5) * 100
92
+ ))
93
+ ),
94
+ new THREE.PointsMaterial({ size: 0.1, color: 0xffffff })
95
+ );
96
+ scene.add(stars);
97
+
98
+ // Touch Controls
99
+ document.addEventListener('touchstart', e => {
100
+ touchStartX = e.touches[0].clientX;
101
  });
102
+
103
+ document.addEventListener('touchmove', e => {
104
+ if(isGameOver) return;
105
+ currentX = (e.touches[0].clientX - touchStartX) * 0.02;
106
+ player.position.x = THREE.MathUtils.clamp(currentX, -7, 7);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  });
108
 
109
+ // Game Loop
110
+ function animate() {
111
+ if(isGameOver) return;
112
+
113
+ // Spawn Objects
114
+ if(Math.random() < 0.02) spawnObject();
115
+
116
+ // Update Stars
117
+ stars.rotation.x += 0.0005;
118
+ stars.rotation.y += 0.0005;
119
+
120
+ // Check Collisions
121
+ scene.children.forEach(obj => {
122
+ if(obj !== player && obj.position.z > 0) {
123
+ if(player.position.distanceTo(obj.position) < 2) {
124
+ if(obj.userData.isPowerUp) {
125
+ score += 100;
126
+ lives = Math.min(CONFIG.INITIAL_LIVES, lives + 1);
127
+ } else {
128
+ lives--;
129
+ if(lives <= 0) endGame();
130
+ }
131
+ scene.remove(obj);
132
+ updateHUD();
133
+ }
134
+ }
135
  });
 
 
 
 
 
 
 
 
136
 
137
+ renderer.render(scene, camera);
138
+ requestAnimationFrame(animate);
139
+ }
140
+
141
+ function spawnObject() {
142
+ const isPowerUp = Math.random() < CONFIG.POWERUP_CHANCE;
143
+ const geometry = isPowerUp ?
144
+ new THREE.OctahedronGeometry(0.5) :
145
+ new THREE.IcosahedronGeometry(1);
146
+
147
+ const object = new THREE.Mesh(
148
+ geometry,
149
+ new THREE.MeshBasicMaterial({
150
+ color: isPowerUp ? 0x00ffff : 0xff4444,
151
+ wireframe: true
152
+ })
153
+ );
154
+
155
+ object.userData.isPowerUp = isPowerUp;
156
+ object.position.set(
157
+ (Math.random() - 0.5) * 14,
158
+ (Math.random() - 0.5) * 8,
159
  -50
160
  );
161
+
162
+ scene.add(object);
163
+ animateObject(object);
164
+ }
165
+
166
+ function animateObject(obj) {
167
+ const speed = 0.1 + (score * 0.0001);
168
+ function move() {
169
+ if(isGameOver) return;
170
+ obj.position.z += speed;
171
+ if(obj.position.z > 5) scene.remove(obj);
172
+ else requestAnimationFrame(move);
173
+ }
174
+ move();
175
+ }
176
 
177
  function updateHUD() {
 
 
178
  document.getElementById('score').textContent = score;
179
+ document.getElementById('lives').textContent = lives;
180
+ score += 1;
181
  }
182
 
183
+ function endGame() {
184
+ isGameOver = true;
185
+ document.getElementById('gameOver').style.display = 'block';
186
+ document.getElementById('share').style.display = 'block';
187
+ document.getElementById('finalScore').textContent = score;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
 
189
+ // Save high score
190
+ localStorage.setItem('highScore', Math.max(score, localStorage.getItem('highScore') || 0));
191
+ }
 
 
 
 
 
 
 
 
 
 
192
 
193
+ async function shareScore() {
194
+ try {
195
+ await navigator.share({
196
+ title: 'Galactic Dodge!',
197
+ text: `πŸš€ I scored ${score} in Galactic Dodge! Can you beat me?`,
198
+ url: window.location.href
199
+ });
200
+ } catch {
201
+ prompt("Copy link to challenge friends:", window.location.href);
202
+ }
203
  }
204
 
205
+ // Init
206
  camera.position.z = 5;
207
  animate();
208
+ updateHUD();
209
 
210
+ // Restart on tap
211
+ document.addEventListener('touchend', () => {
212
+ if(isGameOver) location.reload();
 
 
213
  });
 
 
 
 
214
  </script>
215
  </body>
216
  </html>