Write a JavaScript game in 256 letters
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
docs
src
static
web_modules/gcc
web_typings
.gitattributes
.gitignore
LICENSE.txt
README.md
builder.js
devserver.js
package.json
repl_screenshot.gif
shortener.js
tsconfig.json
webpack.config.js

README.md

jsgame256

Write a JavaScript game in 256 letters.

Aliases, Variables

// aliases
// p5.mouseIsPressed
declare const M: boolean;
// p5.mouseX
declare const X: number;
// p5.mouseY
declare const Y: number;
// p5.random()
declare const R: (min: number | any[], max?: number) => any;
// Tone.synth.triggerAttackRelease()
declare const N: (note: number | string, duration: number | string) => void;
// _.range()
declare const A: (start: number, end?: number, step?: number) => number[];
// You can use all p5.js functions

// variables
// score
declare let S: number;
// ticks
declare let T: number;

Sample games

Click the image to play.

springcar

snowdrop

fallingboot

lineart

inoutcar

boxpress

piyopoyon

sinebomb

Sample not games

pillars pillars

Create your own game

REPL screenshot

  1. Clone this repository
% git clone https://github.com/abagames/jsgame256.git
  1. Install packages
% npm install
  1. Write a game title (e.g. 'falling') to src/_boot.ts
import * as g from "./falling";
  1. Create a source file (e.g. src/falling.ts)

  2. Copy src/_template.ts to the source file

  3. Launch the dev server

% npm start
  1. Open http://localhost:8080/ with a browser

  2. You can use the REPL on the dev server

REPL> T
311
REPL> //p
//PAUSE
REPL> rect(10, 20, 30, 40)
undefined
REPL> //r
//RESUME
  1. Write your code in function U()
export let f;

export function U() {
  clear();
  if (!T) {
    f = A(30).map(i => [0, 99]);
  }
  f.map(g => {
    g[1] += 1 + T / 999;
    if (g[1] > 99) {
      g[0] = R(-9, 99);
      g[1] = R(-99, 0);
      S++;
    }
    text("🏀", g[0], g[1]);
  });
  if (get(X, 77)[3] > 0 || X < 0) {
    S = 0;
    T = -1;
  }
  text("🦑", X - 4, 80);
}
  1. Build the html file with the '//b' command
REPL> //b
REPL>
[at-loader] Checking started in a separate process...

[at-loader] Ok, 0.001 sec.

Build: falling.html
clear(),T||(f=A(30).map(i=>[0,99])),f.map(g=>{g[1]+=1+T/999,g[1]>99&&(g[0]=R(-9,99),g[1]=R(-99,0),S++),text("🏀",g[0],g[1])}),(get(X,77)[3]>0||X<0)&&(S=0,T=-1),text("🦑",X-4,80)
177 / 256
  1. If you want to publish your game, set the publishing URL (e.g. https://foo.com/bar/) to builder.js before building the html file
const imageUrl = "https://foo.com/bar/";