Update index.html
Browse files- index.html +194 -18
index.html
CHANGED
@@ -1,19 +1,195 @@
|
|
1 |
-
<!
|
2 |
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
<html>
|
3 |
+
<head>
|
4 |
+
<meta charset="utf-8">
|
5 |
+
<title>Chofko the Octopus: Dynamic Life Simulator</title>
|
6 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/aframe/1.2.0/aframe.min.js"></script>
|
7 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/cannon.js/0.6.2/cannon.min.js"></script>
|
8 |
+
<style>
|
9 |
+
.controls {
|
10 |
+
position: absolute;
|
11 |
+
bottom: 20px;
|
12 |
+
left: 50%;
|
13 |
+
transform: translateX(-50%);
|
14 |
+
display: flex;
|
15 |
+
gap: 10px;
|
16 |
+
}
|
17 |
+
.controls button {
|
18 |
+
padding: 10px 20px;
|
19 |
+
font-size: 16px;
|
20 |
+
cursor: pointer;
|
21 |
+
}
|
22 |
+
</style>
|
23 |
+
</head>
|
24 |
+
<body>
|
25 |
+
<a-scene physics="debug: true;">
|
26 |
+
<a-assets>
|
27 |
+
<img id="sky" src="/api/placeholder/1024/512" alt="surrealist sky">
|
28 |
+
</a-assets>
|
29 |
+
|
30 |
+
<a-sky src="#sky"></a-sky>
|
31 |
+
|
32 |
+
<a-entity id="chofko" dynamic-body position="0 1.5 -3">
|
33 |
+
<a-sphere color="#FF69B4" radius="0.5"></a-sphere>
|
34 |
+
<a-text value="Chofko" position="0 0.75 0" align="center" color="#FFF" scale="0.5 0.5 0.5"></a-text>
|
35 |
+
<a-entity id="tentacles"></a-entity>
|
36 |
+
</a-entity>
|
37 |
+
|
38 |
+
<a-plane static-body position="0 0 -4" rotation="-90 0 0" width="50" height="50" color="#7BC8A4"></a-plane>
|
39 |
+
|
40 |
+
<a-entity id="particles" position="0 0.1 -4"></a-entity>
|
41 |
+
|
42 |
+
<a-entity id="camera" camera look-controls position="0 10 0" rotation="-45 0 0"></a-entity>
|
43 |
+
</a-scene>
|
44 |
+
|
45 |
+
<div class="controls">
|
46 |
+
<button onclick="move('left')">Left</button>
|
47 |
+
<button onclick="move('right')">Right</button>
|
48 |
+
<button onclick="move('up')">Up</button>
|
49 |
+
<button onclick="move('down')">Down</button>
|
50 |
+
</div>
|
51 |
+
|
52 |
+
<script>
|
53 |
+
// Chofko movement
|
54 |
+
const chofko = document.querySelector('#chofko');
|
55 |
+
let velocity = new THREE.Vector3();
|
56 |
+
const maxSpeed = 0.1;
|
57 |
+
const acceleration = 0.01;
|
58 |
+
const deceleration = 0.995;
|
59 |
+
|
60 |
+
function move(direction) {
|
61 |
+
switch(direction) {
|
62 |
+
case 'left':
|
63 |
+
velocity.x -= acceleration;
|
64 |
+
break;
|
65 |
+
case 'right':
|
66 |
+
velocity.x += acceleration;
|
67 |
+
break;
|
68 |
+
case 'up':
|
69 |
+
velocity.z -= acceleration;
|
70 |
+
break;
|
71 |
+
case 'down':
|
72 |
+
velocity.z += acceleration;
|
73 |
+
break;
|
74 |
+
}
|
75 |
+
velocity.clampScalar(-maxSpeed, maxSpeed);
|
76 |
+
}
|
77 |
+
|
78 |
+
// Create tentacles
|
79 |
+
const tentacleColors = ['#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#FF00FF', '#00FFFF', '#FFA500', '#800080'];
|
80 |
+
const tentaclesEntity = document.querySelector('#tentacles');
|
81 |
+
|
82 |
+
for (let i = 0; i < 8; i++) {
|
83 |
+
const angle = (i / 8) * Math.PI * 2;
|
84 |
+
const x = Math.cos(angle) * 0.5;
|
85 |
+
const z = Math.sin(angle) * 0.5;
|
86 |
+
const tentacle = document.createElement('a-entity');
|
87 |
+
tentacle.setAttribute('geometry', {primitive: 'cylinder', radius: 0.05, height: 1});
|
88 |
+
tentacle.setAttribute('material', {color: tentacleColors[i]});
|
89 |
+
tentacle.setAttribute('position', {x: x, y: -0.5, z: z});
|
90 |
+
tentacle.setAttribute('rotation', {x: 90, y: 0, z: (i * 45) + 90});
|
91 |
+
tentaclesEntity.appendChild(tentacle);
|
92 |
+
}
|
93 |
+
|
94 |
+
// Particle life simulation
|
95 |
+
const particlesEntity = document.querySelector('#particles');
|
96 |
+
const particleCount = 100;
|
97 |
+
const particles = [];
|
98 |
+
|
99 |
+
class Particle {
|
100 |
+
constructor(x, z, color) {
|
101 |
+
this.entity = document.createElement('a-sphere');
|
102 |
+
this.entity.setAttribute('radius', 0.1);
|
103 |
+
this.entity.setAttribute('color', color);
|
104 |
+
this.entity.setAttribute('position', {x: x, y: 0.1, z: z});
|
105 |
+
particlesEntity.appendChild(this.entity);
|
106 |
+
|
107 |
+
this.velocity = new THREE.Vector3(
|
108 |
+
(Math.random() - 0.5) * 0.02,
|
109 |
+
0,
|
110 |
+
(Math.random() - 0.5) * 0.02
|
111 |
+
);
|
112 |
+
|
113 |
+
particles.push(this);
|
114 |
+
}
|
115 |
+
|
116 |
+
update() {
|
117 |
+
const position = this.entity.getAttribute('position');
|
118 |
+
position.x += this.velocity.x;
|
119 |
+
position.z += this.velocity.z;
|
120 |
+
|
121 |
+
// Boundary check
|
122 |
+
if (Math.abs(position.x) > 25) this.velocity.x *= -1;
|
123 |
+
if (Math.abs(position.z) > 25) this.velocity.z *= -1;
|
124 |
+
|
125 |
+
this.entity.setAttribute('position', position);
|
126 |
+
}
|
127 |
+
}
|
128 |
+
|
129 |
+
// Create initial particles
|
130 |
+
for (let i = 0; i < particleCount; i++) {
|
131 |
+
new Particle(
|
132 |
+
(Math.random() - 0.5) * 50,
|
133 |
+
(Math.random() - 0.5) * 50,
|
134 |
+
`hsl(${Math.random() * 360}, 100%, 50%)`
|
135 |
+
);
|
136 |
+
}
|
137 |
+
|
138 |
+
// Breeding function
|
139 |
+
function breed(p1, p2) {
|
140 |
+
const x = (p1.entity.getAttribute('position').x + p2.entity.getAttribute('position').x) / 2;
|
141 |
+
const z = (p1.entity.getAttribute('position').z + p2.entity.getAttribute('position').z) / 2;
|
142 |
+
const color = p1.entity.getAttribute('color');
|
143 |
+
new Particle(x, z, color);
|
144 |
+
}
|
145 |
+
|
146 |
+
// Main game loop
|
147 |
+
function gameLoop() {
|
148 |
+
// Update Chofko's position
|
149 |
+
velocity.multiplyScalar(deceleration);
|
150 |
+
const position = chofko.getAttribute('position');
|
151 |
+
position.x += velocity.x;
|
152 |
+
position.z += velocity.z;
|
153 |
+
chofko.setAttribute('position', position);
|
154 |
+
|
155 |
+
// Update particles
|
156 |
+
particles.forEach(p => p.update());
|
157 |
+
|
158 |
+
// Check for breeding
|
159 |
+
for (let i = 0; i < particles.length; i++) {
|
160 |
+
for (let j = i + 1; j < particles.length; j++) {
|
161 |
+
const p1 = particles[i].entity.getAttribute('position');
|
162 |
+
const p2 = particles[j].entity.getAttribute('position');
|
163 |
+
const distance = new THREE.Vector3(p1.x, p1.y, p1.z).distanceTo(new THREE.Vector3(p2.x, p2.y, p2.z));
|
164 |
+
|
165 |
+
if (distance < 0.3 && Math.random() < 0.001 && particles.length < 200) {
|
166 |
+
breed(particles[i], particles[j]);
|
167 |
+
}
|
168 |
+
}
|
169 |
+
}
|
170 |
+
|
171 |
+
requestAnimationFrame(gameLoop);
|
172 |
+
}
|
173 |
+
|
174 |
+
gameLoop();
|
175 |
+
|
176 |
+
// Keyboard controls
|
177 |
+
document.addEventListener('keydown', (event) => {
|
178 |
+
switch(event.key) {
|
179 |
+
case 'ArrowLeft':
|
180 |
+
move('left');
|
181 |
+
break;
|
182 |
+
case 'ArrowRight':
|
183 |
+
move('right');
|
184 |
+
break;
|
185 |
+
case 'ArrowUp':
|
186 |
+
move('up');
|
187 |
+
break;
|
188 |
+
case 'ArrowDown':
|
189 |
+
move('down');
|
190 |
+
break;
|
191 |
+
}
|
192 |
+
});
|
193 |
+
</script>
|
194 |
+
</body>
|
195 |
+
</html>
|