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 🙏

© 2024 – Pkg Stats / Ryan Hefner

pico-socket

v2.0.0

Published

Server and Client library for adding Online Multiplayer to Pico-8

Downloads

4

Readme

pico-socket

A simple library for adding Online Multiplayer in pico-8

What is it?

pico-socket is a library that allows multiple pico-8 web clients (HTML export) to talk to each other via websockets. pico-socket only requires a simple config, no additional coding outside of your game, and is flexible for most game types.

How to Use

Requirements

  • NodeJS - https://nodejs.org/en/
  • pico-8 - https://www.lexaloffle.com/pico-8.php

pico-8 interface

In order for pico-socket to work, you need to read and write values to GPIO pins in your pico-8 game.

One of these pins needs to be reserved for a room id, which determines which clients can talk to who. Only players in the same room will share state.

Another pin needs to be reserved for the player id. This will be used for determing which pins this player is responsible for updating.

After that, you are welcome to use the pins however you like. You can store general game state, player information, whatever you want!

Note: Values must be 0-255, they can not be negative, and if they would go beyond those values, they will loop around.

For example, you may reserve pins in the following way:

| 0x5f80 | 0x5f81 | 0x5f82 | 0x5f83 | 0x5f84 | 0x5f85 | | ------- | --------- | ---------- | ---------- | ---------- | ---------- | | room id | player id | player 1 x | player 1 y | player 2 x | player 2 y |

pico-socket interface

Export your game for the web (e.g. export game.html) and put the exported files in a folder by themselves (the generated html and js file).

In that folder, create a pico-socket.yml that has the following data:

  • roomIdIndex - the GPIO pin index which dictates which other players you can connect to
  • playerIdIndex - the GPIO pin index which dictates which player this is
  • playerDataIndicies - a list of indicies per-player, which dictates which GPIO pins that player is responsible for

Using the above example again, you might configure pico-socket in the following way:

roomIdIndex: 0 # 0x5f80
playerIdIndex: 1 # 0x5f81
playerDataIndicies:
  - [] # no data for player 0
  - [2, 3] # 0x5f82 and 0x5f83 - player 1 X and Y position
  - [4, 5] # 0x5f84 and 0x5f85 - player 2 X and Y position

This would tell pico-socket that if the playerId was 1, we should send whatever data they have in 0x5f82 and 0x5f83. Player 2 would take in those values, and it's GPIO pins would be updated whenever player 1 changed them.

Running the game

In our folder, we should have an html file, a js file, and a pico-socket.yml. Now we can run the following command:

npx pico-socket

This will kick off a server on localhost:5000. Navigate to that address, and you should see your game! You can open this address in multiple windows, and they should all be able to interact with each other.

Deployment

If you want to deploy a project to a cloud service (like heroku), you can create a package.json for your project with the following command:

npx pico-socket --package

This will create a package.json with the appropriate scripts. From there, you can push your project to github and point to heroku, or whatever cloud service you are familiar with.

Sample

Included in this repo is a simple project that you can look at as a reference.

Pong Example

For a more complex example, check out https://github.com/JRJurman/pico-pong-online

Architecture

Architecture Diagram

Credits

This Project borrows heavily (but simplifies) the logic in Ethan Jurman's Pico Tiny Tanks - https://github.com/ethanjurman/pico-tiny-tanks

Special shout-outs go to Tina Howard and Randy Goodman who also helped contribute to the initial examples and interface for pico-socket