awacke1 commited on
Commit
0999d43
1 Parent(s): f149649

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +22 -13
index.html CHANGED
@@ -74,24 +74,34 @@
74
  class: 'spawner',
75
  'obj-model': `obj: #model${modelNumber}`,
76
  material: {color: '#00FF00', metalness: 0.7, roughness: 0.3},
77
- position: position || new THREE.Vector3(
78
- Math.cos(Math.random() * Math.PI * 2) * 30,
79
- Math.random() * 10 - 5,
80
- Math.sin(Math.random() * Math.PI * 2) * 30
81
- )
82
  });
83
  spawner.health = 100;
84
  spawners.add(spawner);
85
  updateDisplays();
86
  }
87
 
 
 
 
 
 
 
 
 
 
 
88
  function createEnemy(spawnPosition) {
89
  if (enemies.size >= 30) return;
90
  const enemy = createEntity('enemy', {
91
  class: 'enemy',
92
  geometry: {primitive: 'sphere', radius: 0.5},
93
  material: {color: '#FF0000', metalness: 0.7, roughness: 0.3},
94
- position: new THREE.Vector3().addVectors(spawnPosition, new THREE.Vector3((Math.random() - 0.5) * 2, (Math.random() - 0.5) * 2, (Math.random() - 0.5) * 2))
 
 
 
 
95
  });
96
  enemy.appendChild(createEntity('particles', {
97
  'particle-system': {preset: 'dust', particleCount: 100, color: '#FF0000, #FF5500', size: 0.1, dur: 1000, accelerationValue: '0 -9.8 0'}
@@ -103,18 +113,15 @@
103
 
104
  function fireLaser(source, color, target, isPlayer = false) {
105
  const sourcePosition = source.object3D.position.clone();
106
- const targetPosition = target.object3D.position.clone();
107
 
108
  if (isPlayer) {
109
- // For player, set source to be in front of the camera
110
  sourcePosition.copy(camera.object3D.position).add(new THREE.Vector3(0, 0, -1));
111
- // Set target to be far in the direction the camera is facing
112
  const direction = new THREE.Vector3(0, 0, -1);
113
  direction.applyQuaternion(camera.object3D.quaternion);
114
- targetPosition.copy(sourcePosition).add(direction.multiplyScalar(100));
115
  } else {
116
- // For enemies, set target to be in front of the camera
117
- targetPosition.copy(camera.object3D.position).add(new THREE.Vector3(0, 0, -1));
118
  }
119
 
120
  const distance = sourcePosition.distanceTo(targetPosition);
@@ -178,7 +185,7 @@
178
  scene.removeChild(target);
179
  spawners.delete(target);
180
  score += 50;
181
- createSpawner(new THREE.Vector3().addVectors(position, new THREE.Vector3((Math.random() - 0.5) * 10, (Math.random() - 0.5) * 10, (Math.random() - 0.5) * 10)));
182
  }
183
  }
184
  updateDisplays();
@@ -216,6 +223,7 @@
216
  } else {
217
  const direction = new THREE.Vector3().subVectors(cameraPosition, enemy.object3D.position).normalize();
218
  enemy.object3D.position.add(direction.multiplyScalar(0.05));
 
219
  if (enemy.object3D.position.distanceTo(cameraPosition) < 2) {
220
  createExplosion(enemy.object3D.position);
221
  scene.removeChild(enemy);
@@ -231,6 +239,7 @@
231
  spawners.forEach(spawner => {
232
  const direction = new THREE.Vector3().subVectors(cameraPosition, spawner.object3D.position).normalize();
233
  spawner.object3D.position.add(direction.multiplyScalar(0.02));
 
234
  spawner.object3D.lookAt(cameraPosition);
235
  if (spawner.object3D.position.distanceTo(cameraPosition) < 3) {
236
  createExplosion(spawner.object3D.position);
 
74
  class: 'spawner',
75
  'obj-model': `obj: #model${modelNumber}`,
76
  material: {color: '#00FF00', metalness: 0.7, roughness: 0.3},
77
+ position: position || generateSpawnerPosition()
 
 
 
 
78
  });
79
  spawner.health = 100;
80
  spawners.add(spawner);
81
  updateDisplays();
82
  }
83
 
84
+ function generateSpawnerPosition() {
85
+ const angle = Math.random() * Math.PI * 2;
86
+ const distance = 30 + Math.random() * 20; // Spawn between 30 and 50 units away
87
+ return new THREE.Vector3(
88
+ Math.cos(angle) * distance,
89
+ 1.6, // Keep at player's eye level
90
+ Math.sin(angle) * distance - 5 // Offset by -5 to spawn in front of scoreboard
91
+ );
92
+ }
93
+
94
  function createEnemy(spawnPosition) {
95
  if (enemies.size >= 30) return;
96
  const enemy = createEntity('enemy', {
97
  class: 'enemy',
98
  geometry: {primitive: 'sphere', radius: 0.5},
99
  material: {color: '#FF0000', metalness: 0.7, roughness: 0.3},
100
+ position: new THREE.Vector3(
101
+ spawnPosition.x + (Math.random() - 0.5) * 2,
102
+ 1.6, // Keep at player's eye level
103
+ spawnPosition.z + (Math.random() - 0.5) * 2
104
+ )
105
  });
106
  enemy.appendChild(createEntity('particles', {
107
  'particle-system': {preset: 'dust', particleCount: 100, color: '#FF0000, #FF5500', size: 0.1, dur: 1000, accelerationValue: '0 -9.8 0'}
 
113
 
114
  function fireLaser(source, color, target, isPlayer = false) {
115
  const sourcePosition = source.object3D.position.clone();
116
+ let targetPosition;
117
 
118
  if (isPlayer) {
 
119
  sourcePosition.copy(camera.object3D.position).add(new THREE.Vector3(0, 0, -1));
 
120
  const direction = new THREE.Vector3(0, 0, -1);
121
  direction.applyQuaternion(camera.object3D.quaternion);
122
+ targetPosition = sourcePosition.clone().add(direction.multiplyScalar(100));
123
  } else {
124
+ targetPosition = camera.object3D.position.clone();
 
125
  }
126
 
127
  const distance = sourcePosition.distanceTo(targetPosition);
 
185
  scene.removeChild(target);
186
  spawners.delete(target);
187
  score += 50;
188
+ createSpawner(generateSpawnerPosition());
189
  }
190
  }
191
  updateDisplays();
 
223
  } else {
224
  const direction = new THREE.Vector3().subVectors(cameraPosition, enemy.object3D.position).normalize();
225
  enemy.object3D.position.add(direction.multiplyScalar(0.05));
226
+ enemy.object3D.position.y = 1.6; // Keep at player's eye level
227
  if (enemy.object3D.position.distanceTo(cameraPosition) < 2) {
228
  createExplosion(enemy.object3D.position);
229
  scene.removeChild(enemy);
 
239
  spawners.forEach(spawner => {
240
  const direction = new THREE.Vector3().subVectors(cameraPosition, spawner.object3D.position).normalize();
241
  spawner.object3D.position.add(direction.multiplyScalar(0.02));
242
+ spawner.object3D.position.y = 1.6; // Keep at player's eye level
243
  spawner.object3D.lookAt(cameraPosition);
244
  if (spawner.object3D.position.distanceTo(cameraPosition) < 3) {
245
  createExplosion(spawner.object3D.position);