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 🙏

© 2025 – Pkg Stats / Ryan Hefner

learn2dgame-js

v1.0.10

Published

A small module to help new coders to learn 2D programming

Readme

learn2dgame-js

beginner-friendly JavaScript library for learning 2D game development in the browser. Perfect for students, educators, and anyone wanting to learn javascript game development (Beginner Friendly).

Clean code are written in this repository.

Link To Final Version : https://github.com/Liberaa/module

Link To Working repository : https://github.com/Liberaa/NpmGamePackage

Features

  • Simple Player Movement - WASD controls or platformer physics
  • Collision Detection - AABB collision system with obstacles
  • Score System - Built-in scoring with UI display
  • Scene Management - Multiple levels/scenes support
  • Menu System - Pause menus and game UI
  • Collectibles - Coin collection system
  • No Dependencies - Pure JavaScript, works in any modern browser

Installation

npm install learn2dgame-js

Option 1: With Vite (Recommended)

npm create vite@latest my-game -- --template vanilla
cd my-game
npm install learn2dgame-js
import { Game, Obstacle, Coin, SceneManager, Menu, score } from 'learn2dgame-js'

Option 2: Without a Build Tool

npm install learn2dgame-js

Create index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>My Game</title>
</head>
<body>
    <script type="module" src="index.js"></script>
</body>
</html>

In index.js:

import { Game, Obstacle, Coin, SceneManager, Menu, score } from './node_modules/learn2dgame-js/dist/learn2dgame-js.js'

Open with Live Server (VS Code extension) or any local development server.

Quick Start

import { Game, Obstacle, Coin, SceneManager } from 'learn2dgame-js'

const scenes = new SceneManager()

function level1() {
  new Obstacle({ positionX: 200, positionY: 500, width: 400, height: 50, color: 'brown' })
  new Coin({ positionX: 300, positionY: 450 })
}

scenes.add(level1, 20)
scenes.set(0)

new Game('platform', {
  movementSpeed: 10,
  jumpStrengthValue: 15,
  color: 'blue'
})

Controls:

  • A = Move left
  • D = Move right
  • Space = Jump

API Reference

Game

new Game(controlScheme, options)

Parameters:

  • controlScheme: 'wasd' or 'platform'
  • options:
    • movementSpeed (number): Player speed (default: 8)
    • gravityForce (number): Gravity for platform mode (default: 0.5)
    • jumpStrengthValue (number): Jump power (default: 12)
    • color (string): Player color (default: 'red')

Obstacle

new Obstacle({ positionX, positionY, width, height, color, border })

Creates a platform or wall.

Coin

new Coin({ positionX, positionY, size })

Creates a collectible coin (worth 10 points).

SceneManager

const scenes = new SceneManager()
scenes.add(sceneFn, targetScore)  // Register scene
scenes.set(index)                 // Load scene
scenes.next()                     // Next scene

Score

import { score } from 'learn2dgame-js'

score.add(points)     // Add points
score.reset()         // Reset to 0
score.value           // Current score

Menu

const menu = new Menu()

menu.create({
  title: 'Pause Menu',
  buttons: [
    { text: 'Resume', onClick: () => menu.close() }
  ]
})

menu.close()

Examples

Multi-Level Game

import { Game, Obstacle, Coin, SceneManager } from 'learn2dgame-js'

const scenes = new SceneManager()

function level1() {
  new Obstacle({ positionX: 200, positionY: 500, width: 300, height: 50, color: 'brown' })
  new Coin({ positionX: 300, positionY: 450 })
}

function level2() {
  new Obstacle({ positionX: 100, positionY: 500, width: 150, height: 50, color: 'green' })
  new Obstacle({ positionX: 350, positionY: 400, width: 150, height: 50, color: 'green' })
  new Coin({ positionX: 400, positionY: 350 })
}

scenes.add(level1, 20)
scenes.add(level2, 20)
scenes.set(0)

new Game('platform')

Pause Menu

import { Menu, score } from 'learn2dgame-js'

const menu = new Menu()

document.addEventListener('keydown', e => {
  if (e.key.toLowerCase() === 'm') {
    menu.create({
      title: 'Pause',
      buttons: [
        { text: 'Resume', onClick: () => menu.close() },
        { text: 'Reset Score', onClick: () => score.reset() }
      ]
    })
  }
})

Level Design Tips

Easy staircase:

new Obstacle({ positionX: 100, positionY: 500, width: 150, height: 50 })
new Obstacle({ positionX: 250, positionY: 450, width: 150, height: 50 })
new Obstacle({ positionX: 400, positionY: 400, width: 150, height: 50 })

Gap jumping:

new Obstacle({ positionX: 100, positionY: 500, width: 150, height: 50 })
new Obstacle({ positionX: 350, positionY: 500, width: 150, height: 50 })

WASD (Top-Down) Mode

new Game('wasd', { movementSpeed: 5 })

Known Issues

  • Double jump bug: Spamming Space can trigger mid-air jumps
  • Menu overlap: Menu persists if open during scene change

License

MIT License - Perfect for learning and educational use! https://github.com/Liberaa/NpmGamePackage/blob/main/LICENSE

Why This Library?

  • Learning Focused: Understand game development step by step
  • No Complex Setup: Just JavaScript and a browser
  • Simple Code: Readable, modifiable source code
  • Quick Results: Working game in minutes
  • Foundation Building: Learn concepts for larger projects