awacke1 commited on
Commit
3a0edc7
1 Parent(s): 1f71a34

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +172 -7
index.html CHANGED
@@ -7,12 +7,109 @@
7
  </head>
8
  <body>
9
  <a-scene fog="type: linear; color: #87CEEB; near: 0; far: 50">
10
- <!-- ... (previous assets and scene setup remain the same) ... -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  </a-scene>
12
 
13
  <script>
14
  (function() {
15
- // ... (previous variable declarations and functions remain the same) ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  function fireLaser(source, color, direction, isPlayer = false) {
18
  const sourcePosition = source.object3D.position.clone();
@@ -25,14 +122,14 @@
25
  class: 'laser',
26
  geometry: {
27
  primitive: 'cylinder',
28
- radius: isPlayer ? 0.2 : 0.1, // Player lasers are twice as wide
29
  height: laserLength
30
  },
31
  material: {
32
  color: color,
33
- opacity: isPlayer ? 0.5 : 1, // Player lasers are 50% transparent
34
  transparent: isPlayer,
35
- shader: 'flat' // This ensures the laser color is not affected by lighting
36
  },
37
  position: sourcePosition.clone().add(direction.multiplyScalar(laserLength / 2))
38
  });
@@ -61,6 +158,53 @@
61
  });
62
  }
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  function shootFromCamera() {
65
  const direction = new THREE.Vector3(0, 0, -1);
66
  direction.applyQuaternion(camera.object3D.quaternion);
@@ -92,10 +236,31 @@
92
  }
93
  });
94
 
95
- // ... (rest of the updateGame function remains the same) ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  }
97
 
98
- // ... (rest of the script remains the same) ...
 
 
 
 
99
  })();
100
  </script>
101
  </body>
 
7
  </head>
8
  <body>
9
  <a-scene fog="type: linear; color: #87CEEB; near: 0; far: 50">
10
+ <a-assets>
11
+ <a-asset-item id="model1" src="1.obj"></a-asset-item>
12
+ <a-asset-item id="model2" src="2.obj"></a-asset-item>
13
+ <a-asset-item id="model3" src="3.obj"></a-asset-item>
14
+ <a-asset-item id="model4" src="4.obj"></a-asset-item>
15
+ <a-asset-item id="model5" src="5.obj"></a-asset-item>
16
+ <a-asset-item id="model6" src="6.obj"></a-asset-item>
17
+ <a-asset-item id="model7" src="7.obj"></a-asset-item>
18
+ <a-asset-item id="model8" src="8.obj"></a-asset-item>
19
+ <a-asset-item id="model9" src="9.obj"></a-asset-item>
20
+ <a-asset-item id="model10" src="10.obj"></a-asset-item>
21
+ </a-assets>
22
+ <a-sky color="#87CEEB"></a-sky>
23
+ <a-entity id="player" position="0 1.6 0">
24
+ <a-entity camera look-controls wasd-controls>
25
+ <a-entity id="cursor" cursor="fuse: false;" position="0 0 -1"
26
+ geometry="primitive: ring; radiusInner: 0.02; radiusOuter: 0.03"
27
+ material="color: white; shader: flat"
28
+ raycaster="objects: .enemy, .spawner"></a-entity>
29
+ </a-entity>
30
+ </a-entity>
31
+ <a-entity id="scoreBar" position="-2 3 -5">
32
+ <a-box width="2" height="0.2" depth="0.1" color="#444444"></a-box>
33
+ <a-box id="scoreIndicator" width="2" height="0.2" depth="0.1" color="#FFA500" scale="0 1 1"></a-box>
34
+ <a-text value="Score" position="0 -0.3 0" align="center" color="white"></a-text>
35
+ </a-entity>
36
+ <a-entity id="healthBar" position="2 3 -5">
37
+ <a-box width="2" height="0.2" depth="0.1" color="#444444"></a-box>
38
+ <a-box id="healthIndicator" width="2" height="0.2" depth="0.1" color="#00FF00" scale="1 1 1"></a-box>
39
+ <a-text value="Health" position="0 -0.3 0" align="center" color="white"></a-text>
40
+ </a-entity>
41
+ <a-entity id="spawnCounter" position="0 3 -5">
42
+ <a-text value="Spawn Points: 0" align="center" color="white"></a-text>
43
+ </a-entity>
44
  </a-scene>
45
 
46
  <script>
47
  (function() {
48
+ const scene = document.querySelector('a-scene');
49
+ const player = document.querySelector('#player');
50
+ const camera = document.querySelector('[camera]');
51
+ const cursor = document.querySelector('#cursor');
52
+ const scoreIndicator = document.querySelector('#scoreIndicator');
53
+ const healthIndicator = document.querySelector('#healthIndicator');
54
+ const spawnCounter = document.querySelector('#spawnCounter');
55
+ let score = 0, health = 10000, enemies = new Set(), spawners = new Set(), explosionCount = 0;
56
+ const maxScore = 1000;
57
+
58
+ function updateDisplays() {
59
+ scoreIndicator.setAttribute('scale', `${Math.min(score / maxScore, 1)} 1 1`);
60
+ healthIndicator.setAttribute('scale', `${Math.max(health / 10000, 0)} 1 1`);
61
+ spawnCounter.setAttribute('text', `value: Spawn Points: ${spawners.size}`);
62
+ }
63
+
64
+ function createEntity(type, attributes) {
65
+ const entity = document.createElement('a-entity');
66
+ Object.entries(attributes).forEach(([key, value]) => entity.setAttribute(key, value));
67
+ scene.appendChild(entity);
68
+ return entity;
69
+ }
70
+
71
+ function generateSpawnerPosition() {
72
+ const angle = Math.random() * Math.PI * 2;
73
+ const distance = 10 + Math.random() * 10; // Spawn between 10 and 20 units away
74
+ return new THREE.Vector3(
75
+ Math.cos(angle) * distance,
76
+ 1.6, // Keep at player's eye level
77
+ Math.sin(angle) * distance - 5 // Offset by -5 to spawn in front of scoreboard
78
+ );
79
+ }
80
+
81
+ function createSpawner(position = null) {
82
+ const modelNumber = Math.floor(Math.random() * 10) + 1;
83
+ const spawner = createEntity('spawner', {
84
+ class: 'spawner',
85
+ 'obj-model': `obj: #model${modelNumber}`,
86
+ material: {color: '#00FF00', metalness: 0.7, roughness: 0.3},
87
+ position: position || generateSpawnerPosition()
88
+ });
89
+ spawner.health = 100;
90
+ spawners.add(spawner);
91
+ updateDisplays();
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, opacity: 0.5, transparent: true},
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'}
108
+ }));
109
+ enemy.creationTime = Date.now();
110
+ enemies.add(enemy);
111
+ updateDisplays();
112
+ }
113
 
114
  function fireLaser(source, color, direction, isPlayer = false) {
115
  const sourcePosition = source.object3D.position.clone();
 
122
  class: 'laser',
123
  geometry: {
124
  primitive: 'cylinder',
125
+ radius: isPlayer ? 0.2 : 0.1, // Player lasers are wider
126
  height: laserLength
127
  },
128
  material: {
129
  color: color,
130
+ opacity: isPlayer ? 0.5 : 1, // Player lasers are semi-transparent
131
  transparent: isPlayer,
132
+ shader: 'flat' // Ensures the laser color is not affected by lighting
133
  },
134
  position: sourcePosition.clone().add(direction.multiplyScalar(laserLength / 2))
135
  });
 
158
  });
159
  }
160
 
161
+ function isPointNearLine(lineStart, lineEnd, point, threshold) {
162
+ const lineVec = new THREE.Vector3().subVectors(lineEnd, lineStart);
163
+ const pointVec = new THREE.Vector3().subVectors(point, lineStart);
164
+ const lineLengthSq = lineVec.lengthSq();
165
+ const dotProduct = pointVec.dot(lineVec);
166
+ const t = Math.max(0, Math.min(1, dotProduct / lineLengthSq));
167
+ const projection = lineStart.clone().add(lineVec.multiplyScalar(t));
168
+ return point.distanceTo(projection) < threshold;
169
+ }
170
+
171
+ function handleHit(target, position) {
172
+ if (target.classList.contains('enemy')) {
173
+ createExplosion(position);
174
+ scene.removeChild(target);
175
+ enemies.delete(target);
176
+ score += 10;
177
+ health = Math.min(10000, health + 20);
178
+ } else if (target.classList.contains('spawner')) {
179
+ target.health -= 20;
180
+ createExplosion(position);
181
+ if (target.health <= 0) {
182
+ scene.removeChild(target);
183
+ spawners.delete(target);
184
+ score += 50;
185
+ createSpawner(generateSpawnerPosition());
186
+ }
187
+ }
188
+ updateDisplays();
189
+ }
190
+
191
+ function createExplosion(position) {
192
+ const explosion = createEntity('explosion', {position: position});
193
+ for (let i = 0; i < 20; i++) {
194
+ const particle = createEntity('particle', {
195
+ geometry: {primitive: 'sphere', radius: 0.1},
196
+ material: {color: '#FFA500'},
197
+ position: `${(Math.random() - 0.5) * 2} ${(Math.random() - 0.5) * 2} ${(Math.random() - 0.5) * 2}`
198
+ });
199
+ particle.setAttribute('animation', {property: 'position', to: `${(Math.random() - 0.5) * 2} ${(Math.random() - 0.5) * 2} ${(Math.random() - 0.5) * 2}`, dur: 1000, easing: 'easeOutQuad'});
200
+ particle.setAttribute('animation__opacity', {property: 'material.opacity', from: 1, to: 0, dur: 1000, easing: 'easeOutQuad'});
201
+ explosion.appendChild(particle);
202
+ }
203
+ setTimeout(() => scene.removeChild(explosion), 1000);
204
+ explosionCount++;
205
+ updateDisplays();
206
+ }
207
+
208
  function shootFromCamera() {
209
  const direction = new THREE.Vector3(0, 0, -1);
210
  direction.applyQuaternion(camera.object3D.quaternion);
 
236
  }
237
  });
238
 
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);
246
+ scene.removeChild(spawner);
247
+ spawners.delete(spawner);
248
+ health = Math.max(0, health - 100);
249
+ }
250
+ if (Math.random() < 0.005 && enemies.size < 30) {
251
+ createEnemy(spawner.object3D.position);
252
+ }
253
+ });
254
+
255
+ while (spawners.size < 5) createSpawner();
256
+ updateDisplays();
257
  }
258
 
259
+ document.addEventListener('keydown', (event) => { if (event.code === 'Space') shootFromCamera(); });
260
+ scene.addEventListener('click', shootFromCamera);
261
+
262
+ updateDisplays();
263
+ setInterval(updateGame, 1000 / 60); // 60 FPS update
264
  })();
265
  </script>
266
  </body>