SLITHER

by rga4

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/controls/OrbitControls.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tween.js/18.6.4/tween.umd.js"></script>
<!DOCTYPE html>
<html lang="ru">
<head>
  <meta charset="UTF-8">
  <title>Worm.io Game</title>
  <style>
    body { margin: 0; overflow: hidden; background: #000; }
    canvas { display: block; }
  </style>
</head>
<body>
</body>
</html>

JavaScript

// Глобальные переменные
    let scene, camera, renderer, controls;
    let worms = [];
    let foods = [];
    let clock;
    let playerWorm;
    const worldSize = 500; // Размер игрового поля: от -250 до 250 в X и Z

    // Массив юникод-символов для еды (более 20 вариантов)
    const foodSymbols = [
      "🍎", "🍊", "🍌", "🍇", "🍉", "🍓", "🥝", "🍑", "🍒", "🥥",
      "🍍", "🍅", "🥑", "🍆", "🌽", "🥕", "🥦", "🍄", "🌶", "🍋",
      "🍈", "🍐", "🍏", "🍣", "🍤"
    ];

    // Класс для объекта еды
    class Food {
      constructor(position) {
        this.symbol = foodSymbols[Math.floor(Math.random() * foodSymbols.length)];
        this.position = position.clone();
        this.createMesh();
      }

      createMesh() {
        // Отрисовка символа на холсте и создание текстурного спрайта
        const size = 64;
        const canvas = document.createElement('canvas');
        canvas.width = size;
        canvas.height = size;
        const context = canvas.getContext('2d');
        context.font = "48px sans-serif";
        context.textAlign = "center";
        context.textBaseline = "middle";
        context.fillStyle = "#fff";
        context.fillText(this.symbol, size / 2, size / 2);

        const texture = new THREE.CanvasTexture(canvas);
        texture.needsUpdate = true;

        const material = new THREE.SpriteMaterial({ map: texture, transparent: true });
        this.mesh = new THREE.Sprite(material);
        this.mesh.scale.set(20, 20, 1);
        this.mesh.position.copy(this.position);
        scene.add(this.mesh);
      }

      remove() {
        scene.remove(this.mesh);
      }
    }

    // Класс для червя
    class Worm {
      constructor(isPlayer = false) {
        this.isPlayer = isPlayer;
        this.color = new THREE.Color(Math.random(), Math.random(), Math.random());
        this.segments = [];
        this.segmentMeshes = [];
        this.segmentCount = 10;  // Стартовое количество сегментов
        this.segmentDistance = 10;
        this.speed = 40;    ...