Napoleonic Political Magnificence
Wondering what’s next for npm?Check out our public roadmap! »

potion

1.1.2 • Public • Published

Potion

npm version

Potion is a game library with simple and useful abstractions.

  • Asset loader
  • Input event handling
  • Sound manager
  • State manager
  • Multi-layered canvas
  • HiDPI monitor support
  • Debugger for in game logging and switch toggling

Examples

Documentation

Installation

Potion is compatible with CommonJS modules. Can be used with browserify, webpack and others. You can install it from npm.

npm install potion

There is also a built version you can download

Usage

<div class="container"></div>
var Potion = require('potion');
 
var app = Potion.init(document.querySelector('.container'), {
  configure: function() {
    app.resize(400, 400);
  },
 
  init: function() {
    this.x = 0;
    this.y = 0;
    this.dx = 0;
    this.dy = 0;
  },
 
  update: function(time) {
    if (app.input.isKeyDown('w')) { this.dy -= 5000 * time; }
    if (app.input.isKeyDown('d')) { this.dx += 5000 * time; }
    if (app.input.isKeyDown('s')) { this.dy += 5000 * time; }
    if (app.input.isKeyDown('a')) { this.dx -= 5000 * time; }
 
    this.dx = this.dx + (0 - this.dx) * 8 * time;
    this.dy = this.dy + (0 - this.dy) * 8 * time;
 
    this.x += this.dx * time;
    this.y += this.dy * time;
  },
 
  render: function() {
    app.video.ctx.fillRect(this.x, this.y, 10, 10);
  }
});

See also

License

MIT license

Keywords

none

Install

npm i potion

DownloadsWeekly Downloads

148

Version

1.1.2

License

MIT

Last publish

Collaborators

  • avatar