Pixel Engine

Island Joy

Pixel Engine

A minimalist online game engine.

Drawing

clear(): clears canvas

fill(color): draws rect of color color over full canvas

rect(x, y, w, h, color): draws rect of width w, height h, and color color at x, y

Game Loop

start(): runs once at the start of the game before update and draw

update(delta): runs once a frame where delta is time in milliseconds since last call

draw(): runs once a frame after update

Keyboard Input

isKeyDown(key): returns whether given character key is pressed

isKey(key): returns whether given character key was pressed in the last frame

Maps

loadMap(index): loads map of index index to canvas

loadTile(x, y, index): loads tile of index index at x, y

Example

// define player
const player = {
  x: 0,
  y: 0,
  width: 16,
  height: 16,
  color: 'blue'
};
const speed = 0.1;

// runs once on start
function start() {
  fill('green');
}

// runs once a frame
function update(delta) {
  if (isKeyDown('w')) player.y -= speed * delta;
  if (isKeyDown('a')) player.x -= speed * delta;
  if (isKeyDown('s')) player.y += speed * delta;
  if (isKeyDown('d')) player.x += speed * delta;
}

// runs once a frame after update
function draw() {
  fill('green');
  objRect(player);
}