Fork me on GitHub

Javascript Game Engine for HTML5.

Entity is an awsome all new javascript game engine. It focuses on flexibility, reusability and robustness. To make this happen Entity utilizies the entity-component design where all logic is implemented in components and entities are created from adding or removing components. Its supported on all major browsers and will be coming to mobile devices soon.

Installation

Install Ruby

Install the EntityJS Gem

$ gem install entityjs

Create a new platform game

$ entityjs new my_game platform

Start the server and play

$ entityjs server
Your game is here:
  http://localhost:2345
....

More detailed instructions.

Coding Guide

First we have to create a ready function. So the code does not run until all javascript has been loaded.

re.ready(function(){

	//window is ready
    
});

Create a new component that will define a monster.

re.ready(function(){
	
	//create the monster 'class'
	re.c('monster')
	.requires('image monster.png');
    
});

Load up the monster image.

re.ready(function(){

	re.c('monster')
	.requires('image monster.png');
    
    //load up
    re.load('monster.png')
    .complete(function(){
      
    });
    
});

Before we can draw the monster on canvas. We have to initialize the system and start the main loop.

re.ready(function(){

	re.c('monster')
	.requires('image monster.png');
    
    re.load('monster.png')
    .complete(function(){
    	
        //init and start system
        re.sys.init('#canvas')
        .start();
        
    });
    
});

Now create 10 new monster entities and display them all at random positions.

re.ready(function(){

	re.c('monster')
	.requires('image monster.png');
    
    re.load('monster.png')
    .complete(function(){
    	
        re.sys.init('#canvas')
        .start();
        
        //create monsters!
        re.e('monster', 10)
        .each(function(){
        	
       		this.posX = re.random(re.sys.sizeX);
          this.posY = re.random(re.sys.sizeY);
        });
        
    });
    
});

Lets setup a query that finds all monsters and set there health to 100.

re.ready(function(){

	re.c('monster')
	.requires('image monster.png');
    
    re.load('monster.png')
    .complete(function(){
    	
        re.sys.init('#canvas')
        .start();
        
        re.e('monster', 10)
        .each(function(){
        
       		this.posX = re.random(re.sys.sizeX);
          this.posY = re.random(re.sys.sizeY);
        });
        
        //find all monsters!
        re('monster').attr('health', 100);
        
    });
    
});

That was Simple

Now you see how easy it is to develop an Entity game. The whole system revolves around creating components and adding them to entites. In this way you can create reusable low coupling code. The quick guide went through all 5 of the core classes, Re, Component, Entity, Load, and finally Query. These classes are the back bone and power of the Entity engine, learn them well!

For more info take a look at the API. You can also checkout the tutorials.