GithubHelp home page GithubHelp logo

px's Introduction

Px

Px is a tiny 2D canvas framework for turn-based puzzle games.

scrot

Features

  • Collision checking
  • Keyboard/Mouse events
  • Level serialization
  • Tiny (~1.9kb gzipped and minified)

Getting Started

Include px.js in your html file.

<script src="px.js"></script>

Create some entity templates. These are the 'objects' you can spawn in the level grid.

A player:

px.create('player', function (x, y) {
  this.x = x;
  this.y = y;
  this.color = 'pink';

  this.keypress = function (e) {
    if (e.key === 'ArrowRight') {
      px.move(this, this.x + 1, this.y);
    }
    // TODO: Check for other keys...
  }

  this.collide = function (entity) {
    // The player can't go through walls!
    return entity !== 'wall';
  }
});

A wall:

px.create('wall', function (x, y) {
  this.x = x;
  this.y = y;
  this.color = '#CCC';
});

Initialize your game.

window.onload = function () {
  px.init(5, 5, 48);
  // You can also spawn entities using the level editor
  // by clicking to create entities.
  px.spawn('player', 1, 2);
  px.spawn('wall', 3, 2);
  px.draw();
};

A complete game example

px's People

Contributors

stillwwater avatar

Stargazers

mohamad hani janaty avatar Josh Ghent avatar Dan Jordan avatar Álvaro García León avatar Jun Liu avatar Georgii Rychko avatar Sander Ledegen avatar Kostas Nasis avatar Arthur Melo avatar Joe Tercero avatar Eric J Nesser avatar ⊣˚∆˚⊢ avatar Ebrahim Hamdy avatar Joohun, Maeng avatar Haroldo de Oliveira Pinheiro avatar Luke Haas avatar 2358 avatar Jevgeni avatar Radu Micu avatar  avatar Dali avatar Rish avatar Alexis H. Munsayac avatar Nicolas Zamarreno avatar Ben Coullie avatar Twanneman avatar  avatar Tom Scharstein avatar Marshall Jones avatar  avatar Jan Roudaut avatar  avatar Etienne Dldc avatar JGolfetto avatar Opeyemi Obembe avatar Nicolas PIPLARD avatar  avatar Todd Pressley avatar Chris Johnson avatar azu avatar cheongjin kim (김청진) avatar Vincenzo La Spesa avatar Rhio Kim avatar lukaszkups avatar ant cosentino avatar 0xfab1 avatar Piotr Kapera avatar Grady O'Connell avatar Rafael Valverde avatar Michael Leonard avatar Andy Mroczkowski avatar Trym Nilsen avatar Willie Avendano avatar Andrew Wooldridge avatar

Watchers

Andrew Wooldridge avatar ⊣˚∆˚⊢ avatar James Cloos avatar  avatar

Forkers

git2358

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.