npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

snake-game-engine

v1.2.0

Published

A versatile and framework-agnostic Snake game engine that supports both single-player and multiplayer modes. Built with TypeScript, it provides a flexible core that can be integrated into any rendering context.

Readme

Snake Game Engine 🐍

A flexible game engine for creating both single player and multiplayer Snake games.

🎮 Features

  • Single player and multiplayer support
  • Customizable rendering system
  • Configurable scoring system
  • Optional continuous space mode (border crossing)
  • Collision system
  • Direction queue management

📦 Installation

npm install snake-game-engine
// or
yarn add snake-game-engine
// or
pnpm add snake-game-engine

📋 Basic Usage

Single Player

import { Snake } from "./core/snake";

// Game configuration
const gameConfig = {
  width: 20, // Grid width
  height: 20, // Grid height
  tickRate: 200, // Milliseconds between each update
  continuousSpace: false, // If true, snake can cross borders
  scoreConfig: {
    foodMultiplier: 10,
    movementMultiplier: -1,
    useSnakeLength: true,
    onScoreUpdate: (score) => console.log(`Score: ${score}`),
  },
};

// Render configuration
const renderConfig = {
  snakeRenderer: (position) => / logic to render snake /,
  foodRenderer: (position) => / logic to render food /,
  clearRenderer: (element) => / logic to clear an element /,
};

// Create instance
const snake = new Snake(gameConfig, renderConfig, () =>
  console.log("Game Over!")
);

// Start game
snake.start();

// Direction control
snake.setDirection({ x: 1, y: 0 }); // right
snake.setDirection({ x: 0, y: -1 }); // up
snake.setDirection({ x: 0, y: 1 }); // down
snake.setDirection({ x: -1, y: 0 }); // left

Multiplayer

import { MultiplayerSnake } from "./core/multiplayer-snake";

// Multiplayer configuration
const multiplayerConfig = {
  onFoodCollected: ({ collectedBy, newFoodPosition }) => {
    // Notify other players when food is collected
  },
  onPlayerPositionUpdate: (playerId, positions) => {
    // Send position updates to other players
  },
  onPlayerDied: (playerId, finalPositions) => {
    // Handle when a player loses
  },
};

// Create multiplayer instance
const multiplayerSnake = new MultiplayerSnake(
  "player-1", // Unique player ID
  gameConfig,
  renderConfig,
  multiplayerConfig,
  () => console.log("Game Over!")
);

// Other players management
multiplayerSnake.addPlayer("player-2", { x: 0, y: 0 });
multiplayerSnake.receivePlayerUpdate("player-2", [/ new positions /]);
multiplayerSnake.updateFoodPosition({ x: 10, y: 10 });

⚙️ Configuration

GameConfig

interface GameConfig {
  width: number; // Grid width
  height: number; // Grid height
  tickRate: number; // Update speed
  continuousSpace: boolean; // Crossable borders mode
  scoreConfig: {
    foodMultiplier: number; // Points for collected food
    movementMultiplier: number; // Points for movement
    useSnakeLength: boolean; // Use length for score calculation
    calculateScore?: Function; // Custom score calculation function
    onScoreUpdate?: Function; // Score update callback
  };
}

RenderConfig

interface RenderConfig<T> {
  snakeRenderer: (position: Vector2D) => T; // Renders snake segment
  foodRenderer: (position: Vector2D) => T; // Renders food
  clearRenderer: (element: T) => void; // Clears element
}

🔑 Important Notes

  • The system is type-safe and uses generics for rendering
  • Multiplayer mode requires an external networking system
  • The scoring system is fully customizable
  • The direction queue prevents too rapid direction changes
  • Collisions are handled automatically

🔄 Multiplayer Architecture

The following sequence diagram illustrates the message flow in a multiplayer implementation:

Multiplayer Sequence Diagram

Example Implementations