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