Model entities. Inherit a class to assign a polygon and positions your class


Class.create("Character", {

    initialize: function() {


    passable: function(x, y, other_entity) {
        var state;

        this.savePosition(); // save positions
        this.position(x, y); // test new positions
        state = this.hit(other_entity); // test collision for new positions

        if (state.over >= 1) { 
            this.restorePosition(); // If collision, restores the initial positions
            return false;

        return true;




Position X


Position Y



Change the position of the entity and the element. Returns object {x: , y: }


Saves the current positions


Restores the current positions


Polygons define the entity


Define the polygon as a rectangle. The element will take up his new dimensions (`width` and `height` properties). If `x` and `y` are undefined, they will default 0. If only one parameter is defined, the shape is a square with the given width


Calls the function when two or more entities come into colision. Return this object : { over: out: result: { coincident: [] lines: [] } } * over : The number of times that the entity hit the other entity * out : it is 1 if the entity does not affect other entity * result * coincident : Array containing the lines coinciding with the lines of the other entity. 0 corresponds to the first line from the first point of the polygon. * lines : Values in each line with other lines. Example [ false, false, {x: 32, y: 32}, "Coincident" ] Here, it is testing the first line of the polygon entity A. We test the line with 4 sides polygon entity B : 1. The first line of entity A does not intersect with the first line of entity B 2. The first line of entity A does not intersect with the second line of entity B 3. The first line of Entity A has an intersection at positions (32,32) with the third line entity B 4. The first line of entity A coincides with the fourth line entity B > In this example, `coincident` object is : coincident: [3] The number of lines is equal to the order (n) of the polygon - 1.


Retrieves points of the polygon. Returns an array of objects : [ {x: , y: }, {x: , y: }, {x: , y: } ... ]


Find the origin point of the polygon. Returns an object : {x: , y: }


Retrieves the polygon


Sets or retrieves a frame