var NONE = 0;
var BOX = 1;
var CIRCLE = 2;
var POLY = 3;

var NORMAL = 0;
var ASTEROID = 1;
var CRYSTAL = 2;
var STONE = 3;
var PLATFORM = 4;
var BULLET = 5;
var WARP = 6;
var ELEMENT = 7;
var BALL = 8;
var CIRCLE_PLATFORM = 9;
var WALL = 10;

var RED = 1;
var GREEN = 2;
var BLUE = 3;
var VIOLET = 4;
//var WHITE = 0;
//var ORANGE = 1;
//var PINK = 5;
//var GREY = 7;
//var YELLOW = 8;

var asteroid_density = 100.0;	// Плотность/Вес
var asteroid_restitution = 0.7;	// Упругость
var asteroid_friction = 1;		// Трение

var crystal_density = 100.0;
var crystal_restitution = 0.7;
var crystal_friction = 1;

var platform_density = 0;
var platform_restitution = 0.7;
var platform_friction = 1;

var gravity_density = 0;
var gravity_restitution = 0;
var gravity_friction = 5.0;

var ball_density = 1;
var ball_restitution = 0.1; //0.8
var ball_friction = 0.01;

var warp_density = 0;
var warp_restitution = 0;
var warp_friction = 0;

var ballRadius = 15;


function spritesSync(e, x, y)
{
	var p = new Vector(-e.target.syncX, -e.target.syncY);
	p.rotate(-e.target.rotation);
	e.target.x += p.x;
	e.target.y += p.y;
}

var objects = [

	//pearl
//	{
//        name: "pearl",
//        image: "pearl.png",
//        type: BALL,
//        width: 20,
//        height: 20,
//        bodyWidth: 20,
//        bodyHeight: 20,
//        frames: 1,
//        bodyType: CIRCLE,
//        bodyPosCorrect: {x: 0, y: 0},
//        remove: false,
//        fixed: false,
//        density: ball_density,
//        restitution: ball_restitution,
//        friction: ball_friction
//	},

    {
        name: 'asteroids_a',
        image: 'objects/asteroids/asteroids_a.png',
        width: 34,
        height: 34,
        frames: 2,
        bodyWidth: 20,
        bodyHeight: 20,
        bodyType: CIRCLE,
        bodyPosCorrect: {x: -1, y: -1},
        fixed: true,
        density: asteroid_density,
        restitution: asteroid_restitution,
        friction: asteroid_friction,
        custom: null,
        type: ASTEROID,
        typeName: 'ASTEROID',
    },

    {
        name: 'asteroids_b',
        image: 'objects/asteroids/asteroids_b.png',
        width: 34,
        height: 34,
        frames: 2,
        bodyWidth: 20,
        bodyHeight: 20,
        bodyType: CIRCLE,
        bodyPosCorrect: {x: -1, y: -1},
        fixed: true,
        density: asteroid_density,
        restitution: asteroid_restitution,
        friction: asteroid_friction,
        custom: null,
        type: ASTEROID,
        typeName: 'ASTEROID',
    },

    {
        name: 'asteroids_c',
        image: 'objects/asteroids/asteroids_c.png',
        width: 34,
        height: 34,
        frames: 2,
        bodyWidth: 20,
        bodyHeight: 20,
        bodyType: CIRCLE,
        bodyPosCorrect: {x: -1, y: -1},
        fixed: true,
        density: asteroid_density,
        restitution: asteroid_restitution,
        friction: asteroid_friction,
        custom: null,
        type: ASTEROID,
        typeName: 'ASTEROID',
    },

    ////////////////
    {
        name: 'crystal_d',
        image: 'objects/crystals/crystal_d.png',
        width: 34,
        height: 34,
        frames: 2,
        bodyWidth: 20,
        bodyHeight: 20,
        bodyType: CIRCLE,
        bodyPosCorrect: {x: -1, y: -1},
        fixed: true,
        density: asteroid_density,
        restitution: asteroid_restitution,
        friction: asteroid_friction,
        custom: null,
        type: CRYSTAL,
        typeName: 'CRYSTAL',
        color: RED
    },

    {
        name: 'crystal_e',
        image: 'objects/crystals/crystal_e.png',
        width: 34,
        height: 34,
        frames: 2,
        bodyWidth: 20,
        bodyHeight: 20,
        bodyType: CIRCLE,
        bodyPosCorrect: {x: -1, y: -1},
        fixed: true,
        density: asteroid_density,
        restitution: asteroid_restitution,
        friction: asteroid_friction,
        custom: null,
        type: CRYSTAL,
        typeName: 'CRYSTAL',
        color: GREEN
    },

    {
        name: 'crystal_f',
        image: 'objects/crystals/crystal_f.png',
        width: 34,
        height: 34,
        frames: 2,
        bodyWidth: 20,
        bodyHeight: 20,
        bodyType: CIRCLE,
        bodyPosCorrect: {x: -1, y: -1},
        fixed: true,
        density: asteroid_density,
        restitution: asteroid_restitution,
        friction: asteroid_friction,
        custom: null,
        type: CRYSTAL,
        typeName: 'CRYSTAL',
        color: VIOLET
    },

    {
        name: 'crystal_i',
        image: 'objects/crystals/crystal_i.png',
        width: 34,
        height: 34,
        frames: 2,
        bodyWidth: 20,
        bodyHeight: 20,
        bodyType: CIRCLE,
        bodyPosCorrect: {x: -1, y: -1},
        fixed: true,
        density: asteroid_density,
        restitution: asteroid_restitution,
        friction: asteroid_friction,
        custom: null,
        type: CRYSTAL,
        typeName: 'CRYSTAL',
        color: BLUE
    },

    //////////////
    {
        name: 'stone_a',
        image: 'objects/stones/stone_a.png',
        width: 26,
        height: 20,
        frames: 2,
        bodyWidth: 16,
        bodyHeight: 10,
        bodyType: BOX,
        bodyPosCorrect: {x: -3, y: 0},
        fixed: true,
        density: crystal_density,
        restitution: crystal_restitution,
        friction: crystal_friction,
        custom: null,
        type: STONE,
        typeName: 'STONE',
    },

    {
        name: 'stone_b',
        image: 'objects/stones/stone_b.png',
        width: 26,
        height: 20,
        frames: 2,
        bodyWidth: 16,
        bodyHeight: 10,
        bodyType: BOX,
        bodyPosCorrect: {x: -3, y: 0},
        fixed: true,
        density: crystal_density,
        restitution: crystal_restitution,
        friction: crystal_friction,
        custom: null,
        type: STONE,
        typeName: 'STONE',
    },

    {
        name: 'stone_c',
        image: 'objects/stones/stone_c.png',
        width: 26,
        height: 20,
        frames: 2,
        bodyWidth: 16,
        bodyHeight: 10,
        bodyType: BOX,
        bodyPosCorrect: {x: -3, y: 0},
        fixed: true,
        density: crystal_density,
        restitution: crystal_restitution,
        friction: crystal_friction,
        custom: null,
        type: STONE,
        typeName: 'STONE',
    },

    {
        name: 'stone_d',
        image: 'objects/stones/stone_d.png',
        width: 26,
        height: 20,
        frames: 2,
        bodyWidth: 16,
        bodyHeight: 10,
        bodyType: BOX,
        bodyPosCorrect: {x: -3, y: 0},
        fixed: true,
        density: crystal_density,
        restitution: crystal_restitution,
        friction: crystal_friction,
        custom: null,
        type: STONE,
        typeName: 'STONE',
        color: RED
    },

    {
        name: 'stone_e',
        image: 'objects/stones/stone_e.png',
        width: 26,
        height: 20,
        frames: 2,
        bodyWidth: 16,
        bodyHeight: 10,
        bodyType: BOX,
        bodyPosCorrect: {x: -3, y: 0},
        fixed: true,
        density: crystal_density,
        restitution: crystal_restitution,
        friction: crystal_friction,
        custom: null,
        type: STONE,
        typeName: 'STONE',
        color: GREEN
    },

    {
        name: 'stone_f',
        image: 'objects/stones/stone_f.png',
        width: 26,
        height: 20,
        frames: 2,
        bodyWidth: 16,
        bodyHeight: 10,
        bodyType: BOX,
        bodyPosCorrect: {x: -3, y: 0},
        fixed: true,
        density: crystal_density,
        restitution: crystal_restitution,
        friction: crystal_friction,
        custom: null,
        type: STONE,
        typeName: 'STONE',
        color: VIOLET
    },

    {
        name: 'stone_i',
        image: 'objects/stones/stone_i.png',
        width: 26,
        height: 20,
        frames: 2,
        bodyWidth: 16,
        bodyHeight: 10,
        bodyType: BOX,
        bodyPosCorrect: {x: -3, y: 0},
        fixed: true,
        density: crystal_density,
        restitution: crystal_restitution,
        friction: crystal_friction,
        custom: null,
        type: STONE,
        typeName: 'STONE',
        color: BLUE
    },

    //////////////
    {
        name: 'ball_1',
        image: 'objects/balls/ball_1.png',
        width: 15,
        height: 16,
        frames: 1,
        bodyWidth: 15,
        bodyHeight: 15,
        bodyType: CIRCLE,
        bodyPosCorrect: {x: 0, y: 0},
        fixed: true,
        density: platform_density,
        restitution: platform_restitution,
        friction: platform_friction,
        custom: null,
        type: CIRCLE_PLATFORM,
    },

    {
        name: 'ball_2',
        image: 'objects/balls/ball_2.png',
        width: 15,
        height: 15,
        frames: 1,
        bodyWidth: 15,
        bodyHeight: 15,
        bodyType: CIRCLE,
        bodyPosCorrect: {x: 0, y: 0},
        fixed: true,
        density: platform_density,
        restitution: platform_restitution,
        friction: platform_friction,
        custom: null,
        type: CIRCLE_PLATFORM,
    },

    {
        name: 'ball_3',
        image: 'objects/balls/ball_3.png',
        width: 15,
        height: 15,
        frames: 1,
        bodyWidth: 15,
        bodyHeight: 15,
        bodyType: CIRCLE,
        bodyPosCorrect: {x: 0, y: 0},
        fixed: true,
        density: platform_density,
        restitution: platform_restitution,
        friction: platform_friction,
        custom: null,
        type: CIRCLE_PLATFORM,
    },

    {
        name: 'ball_4',
        image: 'objects/balls/ball_4.png',
        width: 15,
        height: 15,
        frames: 1,
        bodyWidth: 15,
        bodyHeight: 15,
        bodyType: CIRCLE,
        bodyPosCorrect: {x: 0, y: 0},
        fixed: true,
        density: platform_density,
        restitution: platform_restitution,
        friction: platform_friction,
        custom: null,
        type: CIRCLE_PLATFORM,
    },

    {
        name: 'ball_5',
        image: 'objects/balls/ball_5.png',
        width: 15,
        height: 15,
        frames: 1,
        bodyWidth: 15,
        bodyHeight: 15,
        bodyType: CIRCLE,
        bodyPosCorrect: {x: 0, y: 0},
        fixed: true,
        density: platform_density,
        restitution: platform_restitution,
        friction: platform_friction,
        custom: null,
        type: CIRCLE_PLATFORM,
    },

    {
        name: 'ball_6',
        image: 'objects/balls/ball_6.png',
        width: 15,
        height: 15,
        frames: 1,
        bodyWidth: 15,
        bodyHeight: 15,
        bodyType: CIRCLE,
        bodyPosCorrect: {x: 0, y: 0},
        fixed: true,
        density: platform_density,
        restitution: platform_restitution,
        friction: platform_friction,
        custom: null,
        type: CIRCLE_PLATFORM,
    },

    {
        name: 'ball_7',
        image: 'objects/balls/ball_7.png',
        width: 15,
        height: 15,
        frames: 1,
        bodyWidth: 15,
        bodyHeight: 15,
        bodyType: CIRCLE,
        bodyPosCorrect: {x: 0, y: 0},
        fixed: true,
        density: platform_density,
        restitution: platform_restitution,
        friction: platform_friction,
        custom: null,
        type: CIRCLE_PLATFORM,
    },

    //////////////////
    {
        name: 'spaceships_large',
        image: 'objects/spaceships/spaceships_large.png',
        width: 53,
        height: 11,
        frames: 1,
        bodyWidth: 53,
        bodyHeight: 11,
        bodyType: POLY,
        points: [[[11, -5], [25, 0], [11, 5], [-11, 5], [-25, 0], [-11, -5]]],
        bodyPosCorrect: {x: 0, y: 0},
        fixed: true,
        density: platform_density,
        restitution: platform_restitution,
        friction: platform_friction,
        custom: null,
        type: PLATFORM
    },

    {
        name: 'spaceships_medium',
        image: 'objects/spaceships/spaceships_medium.png',
        width: 39,
        height: 9,
        frames: 1,
        bodyWidth: 39,
        bodyHeight: 9,
        bodyType: POLY,
        points: [[[9, -4], [19, 0], [9, 4], [-9, 4], [-19, 0], [-9, -4]]],
        bodyPosCorrect: {x: 0, y: 0},
        fixed: true,
        density: platform_density,
        restitution: platform_restitution,
        friction: platform_friction,
        custom: null,
        type: PLATFORM
    },

    {
        name: 'spaceships_small',
        image: 'objects/spaceships/spaceships_small.png',
        width: 25,
        height: 8,
        frames: 1,
        bodyWidth: 25,
        bodyHeight: 8,
        bodyType: POLY,
        points: [[[5, -4], [12, 0], [5, 4], [-5, 4], [-12, 0], [-5, -4]]],
        bodyPosCorrect: {x: 0, y: 0},
        fixed: true,
        density: platform_density,
        restitution: platform_restitution,
        friction: platform_friction,
        custom: null,
        type: PLATFORM
    },

	//atwill
//	{
//        name: "atwill",
//        image: "elements/atwill.png",
//        type: PEARL,
//        width: 39,
//        height: 39,
//        bodyWidth: 36,
//        bodyHeight: 36,
//        frames: 1,
//        bodyType: CIRCLE,
//        bodyPosCorrect: {x: 0, y: 0},
//        remove: false,
//        fixed: false,
//        density: blowfish_density,
//        restitution: blowfish_restitution,
//        friction: blowfish_friction
//	},

	//whatever
//	{
//        name: "whatever",
//        image: "elements/whatever.png",
//        type: PEARL,
//        width: 21,
//        height: 21,
//        bodyWidth: 20,
//        bodyHeight: 20,
//        frames: 1,
//        bodyType: CIRCLE,
//        bodyPosCorrect: {x: 0, y: 0},
//        remove: false,
//        fixed: false,
//        density: blowfish_density,
//        restitution: blowfish_restitution,
//        friction: blowfish_friction
//	},

	//multipear
//	{
//        name: "multipearl",
//        image: "elements/multipearl.png",
//        type: MULTIPEARL,
//        width: 39,
//        height: 39,
//        bodyWidth: 36,
//        bodyHeight: 36,
//        frames: 1,
//        bodyType: CIRCLE,
//        bodyPosCorrect: {x: 0, y: 0},
//        remove: false,
//        fixed: false,
//        density: blowfish_density,
//        restitution: blowfish_restitution,
//        friction: blowfish_friction
//	},

	//warp_hole.png
//	{
//        name: "warp_hole",
//        image: "elements/warp_hole.png",
//        type: WARP,
//        width: 33,
//        height: 32,
//        bodyWidth: 32,
//        bodyHeight: 32,
//        frames: 1,
//        bodyType: CIRCLE,
//        bodyPosCorrect: {x: 0, y: 0},
//        remove: false,
//        fixed: false,
//        density: warp_density,
//        restitution: warp_restitution,
//        friction: warp_friction
//	},

];