akhaliq HF Staff commited on
Commit
dd36112
·
verified ·
1 Parent(s): e15dd3f

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +95 -82
index.html CHANGED
@@ -2,7 +2,7 @@
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; }
@@ -11,7 +11,7 @@
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;
@@ -21,88 +21,110 @@
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
 
@@ -110,27 +132,30 @@
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
 
@@ -141,76 +166,64 @@
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>
 
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>🌟 Cosmic Dodger!</title>
6
  <style>
7
  * { margin: 0; padding: 0; touch-action: manipulation; }
8
  body { overflow: hidden; background: #000; }
 
11
  top: 15px;
12
  left: 15px;
13
  color: #fff;
14
+ font-family: 'Courier New', monospace;
15
  font-size: 24px;
16
  text-shadow: 0 0 10px #00ffff;
17
  z-index: 100;
 
21
  position: fixed;
22
  top: 50%;
23
  left: 50%;
24
+ transform: translate(-score50%, -50%);
25
  text-align: center;
26
  color: #fff;
27
+ background: rgba(0,0,0,0.9);
28
+ padding: 20px;
29
+ border-radius: 15px;
30
+ border: 2px solid #00ff88;
31
  }
32
+ #restart {
33
  display: none;
34
  position: fixed;
35
  bottom: 20px;
36
  left: 50%;
37
  transform: translateX(-50%);
38
+ padding: 12px 25px;
39
  background: #00ff88;
40
  color: #000;
41
  border: none;
42
+ border-radius: 25px;
43
+ font-size: 18px;
44
  cursor: pointer;
45
  }
46
  </style>
47
  </head>
48
  <body>
49
  <div id="hud">
50
+ <div>SCORE: <span id="score">0</span></div>
51
+ <div>LIVES: <span id="lives">3</span></div>
52
  </div>
53
  <div id="gameOver">
54
+ <h1 style="color: #ff0066">GAME OVER</h1>
55
+ <p>Final Score: <span id="finalscore">0</span></p>
56
  </div>
57
+ <button id="restart" onclick="location.reload()">PLAY AGAIN</button>
58
 
59
  <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
60
  <script>
 
61
  const CONFIG = {
62
  PLAYER_SPEED: 0.3,
63
+ ASTEROID_SPAWN: 0.02,
64
+ POWERUP_CHANCE: 0.25,
65
  INITIAL_LIVES: 3
66
  };
67
 
 
68
  let score = 0, lives = CONFIG.INITIAL_LIVES, isGameOver = false;
69
+ let touchStartX = 0, currentX = 0, speedMultiplier = 1;
70
 
 
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 (Glowing Cube)
78
  const player = new THREE.Mesh(
79
+ new THREE.BoxGeometry(0.8, 0.8, 0.8),
80
+ new THREE.MeshStandardMaterial({
81
+ color: 0x00ff88,
82
+ emissive: 0x00ff88,
83
+ emissiveIntensity: 0.5
84
+ })
85
  );
86
  player.position.z = 3;
87
  scene.add(player);
88
 
89
+ // Shield Effect
90
+ const shield = new THREE.Mesh(
91
+ new THREE.SphereGeometry(1.2, 16, 16),
92
+ new THREE.MeshStandardMaterial({
93
+ color: 0x00ffff,
94
+ transparent: true,
95
+ opacity: 0.3
96
+ })
97
+ );
98
+ shield.visible = false;
99
+ player.add(shield);
100
+
101
+ // Starfield
102
  const stars = new THREE.Points(
103
  new THREE.BufferGeometry().setFromPoints(
104
+ Array(1500).fill().map(() => new THREE.Vector3(
105
  (Math.random() - 0.5) * 100,
106
  (Math.random() - 0.5) * 100,
107
  (Math.random() - 0.5) * 100
108
  ))
109
  ),
110
+ new THREE.PointsMaterial({
111
+ size: 0.1,
112
+ color: 0xffffff,
113
+ transparent: true,
114
+ opacity: 0.8
115
+ })
116
  );
117
  scene.add(stars);
118
 
119
+ // Lighting
120
+ const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
121
+ scene.add(ambientLight);
122
+
123
+ // Controls
124
+ document.addEventListener('touchstart', e => touchStartX = e.touches[0].clientX);
125
  document.addEventListener('touchmove', e => {
126
  if(isGameOver) return;
127
+ currentX = (e.touches[0].clientX - touchStartX) * 0.025;
128
  player.position.x = THREE.MathUtils.clamp(currentX, -7, 7);
129
  });
130
 
 
132
  function animate() {
133
  if(isGameOver) return;
134
 
135
+ // Spawning
136
+ if(Math.random() < CONFIG.ASTEROID_SPAWN + score/50000) spawnObject();
137
 
138
+ // Difficulty increase
139
+ speedMultiplier = 1 + score/5000;
140
+
141
+ // Visual Updates
142
  stars.rotation.x += 0.0005;
143
  stars.rotation.y += 0.0005;
144
+ player.rotation.y += 0.02;
145
 
146
+ // Collision Detection
147
  scene.children.forEach(obj => {
148
+ if(obj.userData?.isHazard && obj.position.distanceTo(player.position) < 1.2) {
149
+ if(obj.userData.isPowerUp) {
150
+ lives = Math.min(5, lives + 1);
151
+ score += 100;
152
+ activateShield();
153
+ } else {
154
+ if(!shield.visible) lives--;
155
+ if(lives <= 0) endGame();
 
 
 
156
  }
157
+ scene.remove(obj);
158
+ updateHUD();
159
  }
160
  });
161
 
 
166
  function spawnObject() {
167
  const isPowerUp = Math.random() < CONFIG.POWERUP_CHANCE;
168
  const geometry = isPowerUp ?
169
+ new THREE.IcosahedronGeometry(0.6) :
170
+ new THREE.OctahedronGeometry(1);
171
 
172
+ const obj = new THREE.Mesh(
173
  geometry,
174
+ new THREE.MeshStandardMaterial({
175
  color: isPowerUp ? 0x00ffff : 0xff4444,
176
+ emissive: isPowerUp ? 0x00ffff : 0xff4444,
177
+ emissiveIntensity: 0.2
178
  })
179
  );
180
 
181
+ obj.position.set(
 
182
  (Math.random() - 0.5) * 14,
183
  (Math.random() - 0.5) * 8,
184
  -50
185
  );
186
 
187
+ obj.userData = { isHazard: true, isPowerUp };
188
+
189
+ // Animation
 
 
 
190
  function move() {
191
+ obj.position.z += 0.15 * speedMultiplier;
192
+ obj.rotation.x += 0.02;
193
+ obj.rotation.y += 0.02;
194
  if(obj.position.z > 5) scene.remove(obj);
195
  else requestAnimationFrame(move);
196
  }
197
+
198
+ scene.add(obj);
199
  move();
200
  }
201
 
202
+ function activateShield() {
203
+ shield.visible = true;
204
+ setTimeout(() => shield.visible = false, 2000);
205
+ }
206
+
207
  function updateHUD() {
208
  document.getElementById('score').textContent = score;
209
  document.getElementById('lives').textContent = lives;
210
+ score += speedMultiplier;
211
  }
212
 
213
  function endGame() {
214
  isGameOver = true;
215
  document.getElementById('gameOver').style.display = 'block';
216
+ document.getElementById('restart').style.display = 'block';
 
 
 
217
  localStorage.setItem('highScore', Math.max(score, localStorage.getItem('highScore') || 0));
218
  }
219
 
 
 
 
 
 
 
 
 
 
 
 
 
220
  // Init
221
  camera.position.z = 5;
222
  animate();
223
  updateHUD();
224
 
225
+ // Restart
226
+ document.addEventListener('touchend', () => isGameOver && location.reload());
 
 
227
  </script>
228
  </body>
229
  </html>