README.md

Pentagine

Pentagine is a lightweight JavaScript library for HTML5 2D Game Development that renders to <canvas>. For now, it consists of a State Machine, a Sprite class to load and draw images and some keyboard input functions.

Example

Clone pentagine with git clone git@github.com:davidgomes/pentagine.git and then open examples/index.html for a list of examples.

Here's a small example of all the JavaScript code necessary to draw a ball and make it movable:

functionPlayState() {
this.setup=function() {
this.ball =newpenta.Sprite('ball.png', 100, 50);
this.ball.speed =400;
};
this.update=function() {
if (penta.isDown("up")) {
this.ball.y-=this.ball.speed *this.dt;
}
if (penta.isDown("down")) {
this.ball.y+=this.ball.speed *this.dt;
}
if (penta.isDown("left")) {
this.ball.x-=this.ball.speed *this.dt;
}
if (penta.isDown("right")) {
this.ball.x+=this.ball.speed *this.dt;
}
};
this.draw=function() {
penta.clearCanvas('#333'); // Colored backgroundthis.ball.draw();
};
}
/* If penta.desiredFPS is not declared, the game will run as fast as possible, and on any State, you can use 'this.dt' to get the delta time between two ticks and use it to make movement smooth. However, if desiredFPS is declared, this.dt also works.*/
penta.setup({ desiredFPS:60,
preventedKeys: ['down', 'right', 'left', 'up', 'space'],
firstState:newPlayState(),
width:400,
height:400 });

License

Thanks

I'd like to thank to ippa because Pentagine is loosely inspired on his HTML5 Game Development library - jaws. I also used some of his code, but this is not a fork, the two libraries are quite different.