awacke1 commited on
Commit
229648c
1 Parent(s): 6c9ed02

Create index.html

Browse files
Files changed (1) hide show
  1. index.html +338 -0
index.html ADDED
@@ -0,0 +1,338 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Chofko's Diverse Ecosystem Simulator</title>
6
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/aframe/1.2.0/aframe.min.js"></script>
7
+ <style>
8
+ .controls {
9
+ position: absolute;
10
+ bottom: 20px;
11
+ left: 50%;
12
+ transform: translateX(-50%);
13
+ display: flex;
14
+ gap: 10px;
15
+ }
16
+ .controls button {
17
+ padding: 10px 20px;
18
+ font-size: 16px;
19
+ cursor: pointer;
20
+ }
21
+ #score {
22
+ position: absolute;
23
+ top: 20px;
24
+ left: 20px;
25
+ font-size: 24px;
26
+ color: white;
27
+ background-color: rgba(0,0,0,0.5);
28
+ padding: 10px;
29
+ border-radius: 5px;
30
+ }
31
+ </style>
32
+ </head>
33
+ <body>
34
+ <a-scene>
35
+ <a-assets>
36
+ <img id="sky" src="/api/placeholder/1024/512" alt="surrealist sky">
37
+ </a-assets>
38
+
39
+ <a-sky src="#sky"></a-sky>
40
+
41
+ <a-plane position="0 0 -4" rotation="-90 0 0" width="100" height="100" color="#7BC8A4"></a-plane>
42
+
43
+ <a-entity id="entities"></a-entity>
44
+
45
+ <a-entity id="camera" camera look-controls position="0 40 0" rotation="-90 0 0"></a-entity>
46
+ </a-scene>
47
+
48
+ <div id="score">Score: 0</div>
49
+
50
+ <div class="controls">
51
+ <button onmousedown="startMove('left')" onmouseup="stopMove('left')" ontouchstart="startMove('left')" ontouchend="stopMove('left')">Left</button>
52
+ <button onmousedown="startMove('right')" onmouseup="stopMove('right')" ontouchstart="startMove('right')" ontouchend="stopMove('right')">Right</button>
53
+ <button onmousedown="startMove('up')" onmouseup="stopMove('up')" ontouchstart="startMove('up')" ontouchend="stopMove('up')">Up</button>
54
+ <button onmousedown="startMove('down')" onmouseup="stopMove('down')" ontouchstart="startMove('down')" ontouchend="stopMove('down')">Down</button>
55
+ <button onclick="toggleSpeed()">Toggle Speed</button>
56
+ </div>
57
+
58
+ <script>
59
+ const entitiesEl = document.querySelector('#entities');
60
+ const entities = [];
61
+ const initialEntityCount = 100;
62
+ let score = 0;
63
+ const maxEntities = 300;
64
+ let isSlowMode = false;
65
+
66
+ const primitiveTypes = ['a-sphere', 'a-box', 'a-cone', 'a-cylinder', 'a-tetrahedron', 'a-octahedron'];
67
+ const typeColors = {
68
+ 'a-sphere': ['#FF69B4', '#FF1493'],
69
+ 'a-box': ['#4169E1', '#1E90FF'],
70
+ 'a-cone': ['#32CD32', '#00FF00'],
71
+ 'a-cylinder': ['#FFD700', '#FFA500'],
72
+ 'a-tetrahedron': ['#8A2BE2', '#9400D3'],
73
+ 'a-octahedron': ['#FF4500', '#FF6347']
74
+ };
75
+
76
+ class Entity {
77
+ constructor(x, z, isPlayer = false, type = null, gender = null, radius = null) {
78
+ this.isPlayer = isPlayer;
79
+ this.type = type || (isPlayer ? 'a-sphere' : primitiveTypes[Math.floor(Math.random() * primitiveTypes.length)]);
80
+ this.gender = gender || (Math.random() < 0.5 ? 'male' : 'female');
81
+ this.el = document.createElement(this.type);
82
+ this.radius = radius || (isPlayer ? 1.5 : 0.5);
83
+ this.color = isPlayer ? '#FF00FF' : typeColors[this.type][this.gender === 'male' ? 0 : 1];
84
+
85
+ if (this.type === 'a-sphere' || this.type === 'a-cylinder') {
86
+ this.el.setAttribute('radius', this.radius);
87
+ } else {
88
+ this.el.setAttribute('width', this.radius * 2);
89
+ this.el.setAttribute('height', this.radius * 2);
90
+ this.el.setAttribute('depth', this.radius * 2);
91
+ }
92
+
93
+ this.el.setAttribute('color', this.color);
94
+ this.el.setAttribute('position', {x: x, y: this.radius, z: z});
95
+ entitiesEl.appendChild(this.el);
96
+
97
+ this.velocity = {
98
+ x: isPlayer ? 0 : (Math.random() - 0.5) * 0.2,
99
+ z: isPlayer ? 0 : (Math.random() - 0.5) * 0.2
100
+ };
101
+
102
+ this.acceleration = { x: 0, z: 0 };
103
+
104
+ if (!isPlayer) {
105
+ entities.push(this);
106
+ }
107
+
108
+ if (isPlayer) {
109
+ // Add a text label above the player
110
+ this.label = document.createElement('a-text');
111
+ this.label.setAttribute('value', 'PLAYER');
112
+ this.label.setAttribute('align', 'center');
113
+ this.label.setAttribute('position', {x: 0, y: this.radius * 2, z: 0});
114
+ this.label.setAttribute('scale', {x: 5, y: 5, z: 5});
115
+ this.label.setAttribute('color', '#FFFFFF');
116
+ this.el.appendChild(this.label);
117
+ }
118
+ }
119
+
120
+ update(deltaTime) {
121
+ this.velocity.x += this.acceleration.x * deltaTime;
122
+ this.velocity.z += this.acceleration.z * deltaTime;
123
+
124
+ this.velocity.x *= 0.99;
125
+ this.velocity.z *= 0.99;
126
+
127
+ const position = this.el.getAttribute('position');
128
+ position.x += this.velocity.x * deltaTime;
129
+ position.z += this.velocity.z * deltaTime;
130
+
131
+ if (Math.abs(position.x) > 50) {
132
+ this.velocity.x *= -1;
133
+ position.x = Math.sign(position.x) * 50;
134
+ }
135
+ if (Math.abs(position.z) > 50) {
136
+ this.velocity.z *= -1;
137
+ position.z = Math.sign(position.z) * 50;
138
+ }
139
+
140
+ this.el.setAttribute('position', position);
141
+
142
+ this.acceleration = { x: 0, z: 0 };
143
+ }
144
+
145
+ applyForce(force) {
146
+ this.acceleration.x += force.x / this.radius;
147
+ this.acceleration.z += force.z / this.radius;
148
+ }
149
+
150
+ grow(amount) {
151
+ this.radius += amount;
152
+ if (this.type === 'a-sphere' || this.type === 'a-cylinder') {
153
+ this.el.setAttribute('radius', this.radius);
154
+ } else {
155
+ this.el.setAttribute('width', this.radius * 2);
156
+ this.el.setAttribute('height', this.radius * 2);
157
+ this.el.setAttribute('depth', this.radius * 2);
158
+ }
159
+ const position = this.el.getAttribute('position');
160
+ position.y = this.radius;
161
+ this.el.setAttribute('position', position);
162
+
163
+ if (this.isPlayer && this.label) {
164
+ this.label.setAttribute('position', {x: 0, y: this.radius * 2, z: 0});
165
+ }
166
+ }
167
+
168
+ remove() {
169
+ entitiesEl.removeChild(this.el);
170
+ const index = entities.indexOf(this);
171
+ if (index > -1) {
172
+ entities.splice(index, 1);
173
+ }
174
+ }
175
+ }
176
+
177
+ const player = new Entity(0, 0, true);
178
+ let moveDirection = { x: 0, z: 0 };
179
+
180
+ function createEntities() {
181
+ for (let i = 0; i < initialEntityCount; i++) {
182
+ new Entity(
183
+ (Math.random() - 0.5) * 100,
184
+ (Math.random() - 0.5) * 100
185
+ );
186
+ }
187
+ }
188
+
189
+ function spawnNewEntity() {
190
+ if (entities.length < maxEntities && Math.random() < 0.02) {
191
+ new Entity(
192
+ (Math.random() - 0.5) * 100,
193
+ (Math.random() - 0.5) * 100
194
+ );
195
+ }
196
+ }
197
+
198
+ function startMove(direction) {
199
+ switch(direction) {
200
+ case 'left': moveDirection.x = -1; break;
201
+ case 'right': moveDirection.x = 1; break;
202
+ case 'up': moveDirection.z = -1; break;
203
+ case 'down': moveDirection.z = 1; break;
204
+ }
205
+ }
206
+
207
+ function stopMove(direction) {
208
+ switch(direction) {
209
+ case 'left': case 'right': moveDirection.x = 0; break;
210
+ case 'up': case 'down': moveDirection.z = 0; break;
211
+ }
212
+ }
213
+
214
+ function toggleSpeed() {
215
+ isSlowMode = !isSlowMode;
216
+ }
217
+
218
+ function canEat(entity1, entity2) {
219
+ const typeIndex = primitiveTypes.indexOf(entity1.type);
220
+ const otherTypeIndex = primitiveTypes.indexOf(entity2.type);
221
+ return (typeIndex + 1) % primitiveTypes.length === otherTypeIndex;
222
+ }
223
+
224
+ function tryMating(entity1, entity2) {
225
+ if (entity1.type === entity2.type && entity1.gender !== entity2.gender && Math.random() < 0.1) {
226
+ const childRadius = (entity1.radius + entity2.radius) / 2 * 0.8;
227
+ new Entity(
228
+ (entity1.el.getAttribute('position').x + entity2.el.getAttribute('position').x) / 2,
229
+ (entity1.el.getAttribute('position').z + entity2.el.getAttribute('position').z) / 2,
230
+ false,
231
+ entity1.type,
232
+ Math.random() < 0.5 ? 'male' : 'female',
233
+ childRadius
234
+ );
235
+ }
236
+ }
237
+
238
+ function checkCollisions() {
239
+ const playerPosition = player.el.getAttribute('position');
240
+ for (let i = 0; i < entities.length; i++) {
241
+ const entity = entities[i];
242
+ const entityPosition = entity.el.getAttribute('position');
243
+ const dx = playerPosition.x - entityPosition.x;
244
+ const dz = playerPosition.z - entityPosition.z;
245
+ const distance = Math.sqrt(dx * dx + dz * dz);
246
+
247
+ if (distance < player.radius + entity.radius) {
248
+ if (player.radius > entity.radius * 1.5 && canEat(player, entity)) {
249
+ player.grow(entity.radius * 0.02); // Further reduced growth rate
250
+ entity.remove();
251
+ score += 1;
252
+ updateScore();
253
+ i--;
254
+ } else {
255
+ const angle = Math.atan2(dz, dx);
256
+ const force = 0.01 / distance;
257
+ player.applyForce({ x: -Math.cos(angle) * force, z: -Math.sin(angle) * force });
258
+ entity.applyForce({ x: Math.cos(angle) * force, z: Math.sin(angle) * force });
259
+ }
260
+ }
261
+
262
+ for (let j = i + 1; j < entities.length; j++) {
263
+ const otherEntity = entities[j];
264
+ const otherPosition = otherEntity.el.getAttribute('position');
265
+ const entityDx = entityPosition.x - otherPosition.x;
266
+ const entityDz = entityPosition.z - otherPosition.z;
267
+ const entityDistance = Math.sqrt(entityDx * entityDx + entityDz * entityDz);
268
+
269
+ if (entityDistance < entity.radius + otherEntity.radius) {
270
+ if (entity.radius > otherEntity.radius * 1.2 && canEat(entity, otherEntity)) {
271
+ entity.grow(otherEntity.radius * 0.1);
272
+ otherEntity.remove();
273
+ j--;
274
+ } else if (otherEntity.radius > entity.radius * 1.2 && canEat(otherEntity, entity)) {
275
+ otherEntity.grow(entity.radius * 0.1);
276
+ entity.remove();
277
+ i--;
278
+ break;
279
+ } else {
280
+ tryMating(entity, otherEntity);
281
+ const angle = Math.atan2(entityDz, entityDx);
282
+ const force = 0.005 / entityDistance;
283
+ entity.applyForce({ x: -Math.cos(angle) * force, z: -Math.sin(angle) * force });
284
+ otherEntity.applyForce({ x: Math.cos(angle) * force, z: Math.sin(angle) * force });
285
+ }
286
+ }
287
+ }
288
+ }
289
+ }
290
+
291
+ function updateScore() {
292
+ document.getElementById('score').textContent = `Score: ${score}`;
293
+ }
294
+
295
+ let lastTime = 0;
296
+ function gameLoop(timestamp) {
297
+ const deltaTime = timestamp - lastTime;
298
+ lastTime = timestamp;
299
+
300
+ const speedFactor = isSlowMode ? 0.5 : 1;
301
+ player.applyForce({
302
+ x: moveDirection.x * 0.0005 * speedFactor,
303
+ z: moveDirection.z * 0.0005 * speedFactor
304
+ });
305
+
306
+ entities.forEach(e => e.update(deltaTime * speedFactor));
307
+ player.update(deltaTime * speedFactor);
308
+ checkCollisions();
309
+ spawnNewEntity();
310
+ requestAnimationFrame(gameLoop);
311
+ }
312
+
313
+ document.querySelector('a-scene').addEventListener('loaded', function () {
314
+ createEntities();
315
+ requestAnimationFrame(gameLoop);
316
+ });
317
+
318
+ document.addEventListener('keydown', (event) => {
319
+ switch(event.key) {
320
+ case 'ArrowLeft': startMove('left'); break;
321
+ case 'ArrowRight': startMove('right'); break;
322
+ case 'ArrowUp': startMove('up'); break;
323
+ case 'ArrowDown': startMove('down'); break;
324
+ case 'Shift': toggleSpeed(); break;
325
+ }
326
+ });
327
+
328
+ document.addEventListener('keyup', (event) => {
329
+ switch(event.key) {
330
+ case 'ArrowLeft': stopMove('left'); break;
331
+ case 'ArrowRight': stopMove('right'); break;
332
+ case 'ArrowUp': stopMove('up'); break;
333
+ case 'ArrowDown': stopMove('down'); break;
334
+ }
335
+ });
336
+ </script>
337
+ </body>
338
+ </html>