Update app.py
Browse files
app.py
CHANGED
@@ -43,7 +43,6 @@ game_html = f"""
|
|
43 |
position: absolute; bottom: 10px; left: 10px; color: white;
|
44 |
background-color: rgba(0, 0, 0, 0.5); padding: 10px; border-radius: 5px;
|
45 |
}}
|
46 |
-
.message {{ position: absolute; color: cyan; font-size: 16px; z-index: 1; }}
|
47 |
#gameOver {{ position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: red; font-size: 48px; z-index: 1; display: none; }}
|
48 |
</style>
|
49 |
</head>
|
@@ -65,7 +64,7 @@ game_html = f"""
|
|
65 |
<script>
|
66 |
// Game variables
|
67 |
let score = 0, gameTime = 0, lives = 3, gameActive = true;
|
68 |
-
let snake, foodItems = [], lSysCreatures = [],
|
69 |
const playerName = "{player_name}";
|
70 |
const maxGameTime = 300; // 5 minutes in seconds
|
71 |
let initialLength = 3, lastLength = 3, moveCounter = 0, moveInterval = 0.1;
|
@@ -265,24 +264,28 @@ game_html = f"""
|
|
265 |
creature.position.copy(position);
|
266 |
lSysCreatures.push(creature);
|
267 |
scene.add(creature);
|
268 |
-
|
269 |
}}
|
270 |
|
271 |
-
function
|
272 |
-
const
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
|
|
|
|
|
|
|
|
283 |
}}
|
284 |
|
285 |
-
function
|
286 |
const response = new THREE.Mesh(
|
287 |
new THREE.SphereGeometry(0.3, 16, 16),
|
288 |
new THREE.MeshBasicMaterial({{ color: 0xff0000 }})
|
@@ -292,11 +295,32 @@ game_html = f"""
|
|
292 |
setTimeout(() => scene.remove(response), 2000);
|
293 |
}}
|
294 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
function resetSnake() {{
|
296 |
snake.forEach(seg => scene.remove(seg));
|
297 |
snake = [];
|
298 |
const snakeMaterial = new THREE.MeshStandardMaterial({{color: 0x00ff00}});
|
299 |
-
for (let i = 0; i < initialLength; i++) {{
|
300 |
const segment = new THREE.Mesh(new THREE.SphereGeometry(0.5, 16, 16), snakeMaterial);
|
301 |
segment.position.set(-i * 1.2, 0.5, 0);
|
302 |
segment.castShadow = true;
|
@@ -323,7 +347,7 @@ game_html = f"""
|
|
323 |
if (key === 'a' || key === 'arrowleft') keys.a = false;
|
324 |
if (key === 's' || key === 'arrowdown') keys.s = false;
|
325 |
if (key === 'd' || key === 'arrowright') keys.d = false;
|
326 |
-
if (key === 'r' && gameActive
|
327 |
}});
|
328 |
|
329 |
function updateSnake(delta) {{
|
@@ -445,9 +469,11 @@ game_html = f"""
|
|
445 |
resetSnake();
|
446 |
foodItems.forEach(f => scene.remove(f));
|
447 |
lSysCreatures.forEach(c => scene.remove(c));
|
|
|
448 |
buildings.forEach(b => scene.remove(b));
|
449 |
foodItems = [];
|
450 |
lSysCreatures = [];
|
|
|
451 |
buildings = [];
|
452 |
score = 0;
|
453 |
lives = 3;
|
@@ -508,12 +534,8 @@ game_html = f"""
|
|
508 |
if (gameTime >= maxGameTime) endGame();
|
509 |
updateSnake(delta);
|
510 |
updateScore(delta);
|
|
|
511 |
updateLighting(delta);
|
512 |
-
messages = messages.filter(m => {{
|
513 |
-
m.ttl -= delta;
|
514 |
-
if (m.ttl <= 0) document.body.removeChild(m.div);
|
515 |
-
return m.ttl > 0;
|
516 |
-
}});
|
517 |
}}
|
518 |
|
519 |
renderer.render(scene, camera);
|
|
|
43 |
position: absolute; bottom: 10px; left: 10px; color: white;
|
44 |
background-color: rgba(0, 0, 0, 0.5); padding: 10px; border-radius: 5px;
|
45 |
}}
|
|
|
46 |
#gameOver {{ position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: red; font-size: 48px; z-index: 1; display: none; }}
|
47 |
</style>
|
48 |
</head>
|
|
|
64 |
<script>
|
65 |
// Game variables
|
66 |
let score = 0, gameTime = 0, lives = 3, gameActive = true;
|
67 |
+
let snake, foodItems = [], lSysCreatures = [], quineAgents = [], buildings = [];
|
68 |
const playerName = "{player_name}";
|
69 |
const maxGameTime = 300; // 5 minutes in seconds
|
70 |
let initialLength = 3, lastLength = 3, moveCounter = 0, moveInterval = 0.1;
|
|
|
264 |
creature.position.copy(position);
|
265 |
lSysCreatures.push(creature);
|
266 |
scene.add(creature);
|
267 |
+
sendQuineAgent(creature);
|
268 |
}}
|
269 |
|
270 |
+
function sendQuineAgent(sender) {{
|
271 |
+
const agent = new THREE.Mesh(
|
272 |
+
new THREE.SphereGeometry(0.3, 16, 16),
|
273 |
+
new THREE.MeshStandardMaterial({{color: 0x00ffff, emissive: 0x00ffff, emissiveIntensity: 0.5}})
|
274 |
+
);
|
275 |
+
agent.position.copy(sender.position).add(new THREE.Vector3(0, 5, 0));
|
276 |
+
agent.userData = {{
|
277 |
+
origin: sender.position.clone(),
|
278 |
+
angle: Math.random() * Math.PI * 2,
|
279 |
+
speed: 0.5 + Math.random() * 0.5,
|
280 |
+
radius: 3 + Math.random() * 2,
|
281 |
+
ttl: 5 // 5 seconds lifespan
|
282 |
+
}};
|
283 |
+
quineAgents.push(agent);
|
284 |
+
scene.add(agent);
|
285 |
+
setTimeout(() => lSysCreatures.forEach(c => c !== sender && listenToAgent(c, agent)), 1000);
|
286 |
}}
|
287 |
|
288 |
+
function listenToAgent(creature) {{
|
289 |
const response = new THREE.Mesh(
|
290 |
new THREE.SphereGeometry(0.3, 16, 16),
|
291 |
new THREE.MeshBasicMaterial({{ color: 0xff0000 }})
|
|
|
295 |
setTimeout(() => scene.remove(response), 2000);
|
296 |
}}
|
297 |
|
298 |
+
function updateQuineAgents(delta) {{
|
299 |
+
for (let i = quineAgents.length - 1; i >= 0; i--) {{
|
300 |
+
const agent = quineAgents[i];
|
301 |
+
agent.userData.ttl -= delta;
|
302 |
+
if (agent.userData.ttl <= 0) {{
|
303 |
+
scene.remove(agent);
|
304 |
+
quineAgents.splice(i, 1);
|
305 |
+
continue;
|
306 |
+
}}
|
307 |
+
// Orbit around origin
|
308 |
+
agent.userData.angle += agent.userData.speed * delta;
|
309 |
+
const offsetX = Math.cos(agent.userData.angle) * agent.userData.radius;
|
310 |
+
const offsetZ = Math.sin(agent.userData.angle) * agent.userData.radius;
|
311 |
+
agent.position.set(
|
312 |
+
agent.userData.origin.x + offsetX,
|
313 |
+
agent.userData.origin.y + 5 + Math.sin(gameTime * agent.userData.speed) * 0.5, // Small vertical bob
|
314 |
+
agent.userData.origin.z + offsetZ
|
315 |
+
);
|
316 |
+
}}
|
317 |
+
}}
|
318 |
+
|
319 |
function resetSnake() {{
|
320 |
snake.forEach(seg => scene.remove(seg));
|
321 |
snake = [];
|
322 |
const snakeMaterial = new THREE.MeshStandardMaterial({{color: 0x00ff00}});
|
323 |
+
for (let i K = 0; i < initialLength; i++) {{
|
324 |
const segment = new THREE.Mesh(new THREE.SphereGeometry(0.5, 16, 16), snakeMaterial);
|
325 |
segment.position.set(-i * 1.2, 0.5, 0);
|
326 |
segment.castShadow = true;
|
|
|
347 |
if (key === 'a' || key === 'arrowleft') keys.a = false;
|
348 |
if (key === 's' || key === 'arrowdown') keys.s = false;
|
349 |
if (key === 'd' || key === 'arrowright') keys.d = false;
|
350 |
+
if (key === 'r' && !gameActive) resetGame();
|
351 |
}});
|
352 |
|
353 |
function updateSnake(delta) {{
|
|
|
469 |
resetSnake();
|
470 |
foodItems.forEach(f => scene.remove(f));
|
471 |
lSysCreatures.forEach(c => scene.remove(c));
|
472 |
+
quineAgents.forEach(a => scene.remove(a));
|
473 |
buildings.forEach(b => scene.remove(b));
|
474 |
foodItems = [];
|
475 |
lSysCreatures = [];
|
476 |
+
quineAgents = [];
|
477 |
buildings = [];
|
478 |
score = 0;
|
479 |
lives = 3;
|
|
|
534 |
if (gameTime >= maxGameTime) endGame();
|
535 |
updateSnake(delta);
|
536 |
updateScore(delta);
|
537 |
+
updateQuineAgents(delta);
|
538 |
updateLighting(delta);
|
|
|
|
|
|
|
|
|
|
|
539 |
}}
|
540 |
|
541 |
renderer.render(scene, camera);
|