	function PersType(Sz, tX, tW, tH, Health) {
		this.Health = Health;
		this.Sz = Sz;
		this.tX = tX;
		this.tW = tW;
		this.tH = tH;	
		this.tWd2 = (0.5 + tW/2) << 0;
		this.tHd2 = (0.5 + tH/2) << 0;
		this.ARect = function(P1, P2) {
			if ((P2.Y >= P1.Y - this.Sz) 
			 & (P2.Y <= P1.Y + this.Sz)) {
				if (P1.D > 0) {
					var x1 = P1.X + this.Sz;
					var x2 = x1 + P2.Tex.Sz + 10;
				}
				else {
					var x2 = P1.X - this.Sz;
					var x1 = x2 - P2.Tex.Sz - 10;			
				}
				//alert(P1.D + "/n " + P2.X + ' ' + x1 + ' ' + x2);
				return ((P2.X >= x1) & (P2.X <= x2));
			}
			return false;
		}
	}
	
	function ButtonType(Sz, tX, tY, tW, tH) {
		this.Sz = Sz;
		this.tX = tX;
		this.tY = tY;
		this.tW = tW;
		this.tH = tH;	
		this.tWd2 = (0.5 + tW/2) << 0;
		this.tHd2 = (0.5 + tH/2) << 0;	
		
		this.ARect = function(P1, P2) {
			alert('ButtonType ARect');
		}
	}

function TSprite(tX, tY, tW, tH) {
		this.tX = tX;
		this.tY = tY;
		this.tW = tW;
		this.tH = tH;	
		this.tWd2 = (0.5 + tW/2) << 0;
		this.tHd2 = (0.5 + tH/2) << 0;	
}

function TMap(ctx) {

	this.width = ctx.canvas.width;
	this.height = ctx.canvas.height;
	var height = this.height;
	this.widthD2 = (0.5 + this.width / 2) << 0;
	this.heightD2 = (0.5 + this.height / 2) << 0;
	this.heightD3 = (0.5 + this.height / 2.5) << 0;
	
	this.keyMe = 0;
	this.keyMe2 = 0;
	
	var M2Pix = 32;
	var M2Pixm2 = M2Pix*2;
	var M2Pixd15 = M2Pix/1.5;
	var Pi180d = Math.PI/180;
	var b2Vec2 = Box2D.Common.Math.b2Vec2,
            b2AABB = Box2D.Collision.b2AABB,
         	b2BodyDef = Box2D.Dynamics.b2BodyDef,
         	b2Body = Box2D.Dynamics.b2Body,
         	b2FixtureDef = Box2D.Dynamics.b2FixtureDef,
         	b2Fixture = Box2D.Dynamics.b2Fixture,
         	b2World = Box2D.Dynamics.b2World,
         	//b2MassData = Box2D.Collision.Shapes.b2MassData,
         	b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape,
         	b2CircleShape = Box2D.Collision.Shapes.b2CircleShape,
         	//b2DebugDraw = Box2D.Dynamics.b2DebugDraw,
            //b2MouseJointDef =  Box2D.Dynamics.Joints.b2MouseJointDef,
			b2DistanceJointDef = Box2D.Dynamics.Joints.b2DistanceJointDef,
			b2RevoluteJointDef = Box2D.Dynamics.Joints.b2RevoluteJointDef;
			//b2PrismaticJointDef = Box2D.Dynamics.Joints.b2PrismaticJointDef; 
                     
		var world = new b2World(new b2Vec2(0, 10), true);
	
		function Add_body(X, Y, A, Shape, Dynamic, D, F, R) {
			var bodyDef = new b2BodyDef();
			if (Dynamic)
				bodyDef.type = b2Body.b2_dynamicBody;
			else
				bodyDef.type = b2Body.b2_staticBody;
			var fixDef = new b2FixtureDef();
			fixDef.density = D;
			fixDef.friction = F;
			fixDef.restitution = R;
			
			fixDef.shape = Shape;
			
			bodyDef.position.Set(X, Y);
			
			var body = world.CreateBody(bodyDef);
			
			body.CreateFixture(fixDef);
			body.SetAngle(A);
			
			return body;
		}
		
		function Add_box(X, Y, W, H, A, Dynamic, D, F, R) {
			var Shape = new b2PolygonShape;
			Shape.SetAsBox(W/M2Pixm2, H/M2Pixm2);
			return Add_body(X/M2Pix, Y/M2Pix, A * Pi180d, Shape, Dynamic, D, F, R);
		}
		
		function Add_ball(X, Y, Radius, Dynamic, D, F, R) {
			return Add_body(X/M2Pix, Y/M2Pix, 0, new b2CircleShape(Radius/M2Pix), Dynamic, D, F, R);
		}	

		this.Add_DJoint = function(A, B) {
			var jointDef = new b2DistanceJointDef(); 
			jointDef.Initialize(A, B, A.GetPosition(), B.GetPosition());
			jointDef.collideConnected = false;
			world.CreateJoint(jointDef);	
		}
		
		this.Add_RJoint = function(A, B) {
			var jointDef = new b2RevoluteJointDef(); 
			jointDef.Initialize(A, B, A.GetPosition());
			jointDef.collideConnected = false;
			world.CreateJoint(jointDef);	
		}	
		
		this.Set_ForceC = function(Obj, X, Y) {
			Obj.SetAwake(true);
			var V = Obj.GetLinearVelocity();
			V.x = X/M2Pixd15;
			V.y = Y/M2Pixd15;
			Obj.SetLinearVelocity(V);
		}
		
		this.Set_Force = function(Obj, X, Y) {
			Obj.SetAwake(true);
			var V = Obj.GetLinearVelocity();
			V.x = X;
			V.y = Y;
			Obj.SetLinearVelocity(V);
		}
		this.Add_Force = function(Obj, X, Y) {
			Obj.SetAwake(true);
			var V = Obj.GetLinearVelocity();
			V.x += X;
			V.y += Y;
			Obj.SetLinearVelocity(V);
		}
	
    function Add_Force(Obj, X, Y) {
			Obj.SetAwake(true);
			var V = Obj.GetLinearVelocity();
			V.x += X;
			V.y += Y;
			Obj.SetLinearVelocity(V);	
	}
	
	function DrawPers(X, Y, T, M, A, A2) {
		ctx.setTransform(M?-1:1, 0, 0, 1, (0.5 + X) << 0, (-1.5 + Y) << 0);
		ctx.drawImage(mImg, T.tX, A2 * T.tH, T.tW, T.tH, -T.tWd2, -T.tHd2, T.tW, T.tH);
		ctx.drawImage(mImg, T.tX, A * T.tH, T.tW, T.tH, -T.tWd2, -T.tHd2, T.tW, T.tH);
		ctx.setTransform(1, 0, 0, 1, 0, 0);
	}	
	function DrawSprite(X, Y, T) {
		ctx.setTransform(1, 0, 0, 1, (0.5 + X) << 0, (0.5 + Y) << 0);
		ctx.drawImage(mImg, T.tX, T.tY, T.tW, T.tH, -T.tWd2, -T.tHd2, T.tW, T.tH);
		ctx.setTransform(1, 0, 0, 1, 0, 0);
	}
	function DrawButton(X, Y, T, A) {
		ctx.setTransform(1, 0, 0, 1, (0.5 + X) << 0, (0.5 + Y) << 0);
		ctx.drawImage(mImg, T.tX, T.tY + A * T.tH, T.tW, T.tH, -T.tWd2, -T.tHd2, T.tW, T.tH);
		ctx.setTransform(1, 0, 0, 1, 0, 0);
	}
	
	function DrawBall(X, Y, radius, color) {
		ctx.beginPath();
		ctx.fillStyle = color;
		ctx.arc(X, Y, radius, 0, Pi2);	
		ctx.closePath();
		ctx.fill();
	}
	function DrawBox(X, Y, W, H, color) {
		ctx.fillStyle = color;
		ctx.fillRect(X, Y, W, H);
	}	
	function DrawBoxA(X, Y, W, H, A, color) {
		ctx.fillStyle = color;
		ctx.translate(X, Y);
		ctx.rotate(A);
		ctx.fillRect(-W/2, -H/2, W, H);
		ctx.rotate(-A);
		ctx.translate(-X, -Y);
	}
	this.DrawBoxA = DrawBoxA;
	 
	function TRope(X1, Y1, X2, Y2, L, Sg, Color, Dynamic) {
		this.aRope = new Array();
		this.eR = Math.sqrt(Math.pow(X1- X2, 2) + Math.pow(Y1 - Y2, 2)) / L / 2;
		this.aRope[0] =  Add_ball(X1, Y1, this.eR, Dynamic, 1.0, 0.5, 0.25);
		var shX = (X2 - X1) / L;
		var shY = (Y2 - Y1) / L;
		var sY = (L) / 2;
		for (var I = 1; I < L; I++) {
			this.aRope[I] =  Add_ball(X1 + I * shX, Y1 + I * shY -((I-sY)*(I-sY) - sY*sY)*Sg, 2,  true, 1.0, 0.5, 0.25);
			var jointDef = new b2DistanceJointDef(); 
			jointDef.Initialize(this.aRope[I - 1], this.aRope[I], this.aRope[I - 1].GetPosition(), this.aRope[I].GetPosition());
			jointDef.collideConnected = false;
			world.CreateJoint(jointDef);	
		}
		this.aRope[L] =  Add_ball(X2, Y2, this.eR, true, 1.0, 0.5, 0.25);
		var jointDef = new b2DistanceJointDef(); 
		jointDef.Initialize(this.aRope[L - 1], this.aRope[L], this.aRope[L - 1].GetPosition(), this.aRope[L].GetPosition());
		jointDef.collideConnected = false;
		world.CreateJoint(jointDef);
		
		this.Visible = true;		
		this.Start = this.aRope[0];
		this.End = this.aRope[this.aRope.length - 1];
		this.Update = function() {}
		this.Draw = function() {
			/*
			for (var I = 0; I <= L; I++) { 
				Pos = this.aRope[I].GetPosition();
				//DrawBall(Pos.x * M2Pix, Pos.y * M2Pix, this.eR, Color);
			}*/
			if (this.Visible) {
				ctx.beginPath();
				ctx.strokeStyle = Color;
				var Pos = this.aRope[0].GetPosition();
				ctx.moveTo(Pos.x * M2Pix, Pos.y * M2Pix);
				for (var I = 1; I <= L; I++) { 
					Pos = this.aRope[I].GetPosition();
					ctx.lineTo(Pos.x * M2Pix, Pos.y * M2Pix);
				}
				ctx.stroke();	
				ctx.closePath();
			}
		}
		this.Clear = function() {
			for (var I = 0; I <= L; I++) 
				world.DestroyBody(this.aRope[I]);
			this.aRope.splice(0, this.aRope.length);		
			this.Visible = false;	
		}
		this.DestroyEnd = function() {
			this.Clear();
			//world.DestroyBody(this.End);
			//this.aRope.splice(this.aRope.length -1, 1);	
			//this.End = this.aRope[this.aRope.length - 1];
		}
	}
	
	function TObj(X, Y) {
		this.X = X;
		this.Y = Y;
		this.XC = X / M2Pix;
		this.YC = Y / M2Pix;	
		
		this.Update = function() {
			var Pos = this.Body.GetPosition();
			this.XC = Pos.x;
			this.YC = Pos.y;
			this.X = Pos.x * M2Pix;
			this.Y = Pos.y * M2Pix;
		}
	}
	
	function TDynamicBall(X, Y, Sz, Color) {
		TDynamicBall.superclass.constructor.call(this, X, Y);
		this.Sz = Sz;
		this.Body = Add_ball(X, Y, Sz, true, 1.0, 0.5, 0.25);

		this.Draw = function() {
			this.Update();
			DrawBall(this.X, this.Y, Sz, Color);
		}
	}
	extend(TDynamicBall, TObj);
	
	function TDynamicBallSprite(X, Y, Sz, Tex) {
		TDynamicBallSprite.superclass.constructor.call(this, X, Y);
		this.Sz = Sz;
		this.Body = Add_ball(X, Y, Sz, true, 1.0, 0.5, 0.25);
		this.Tex = Tex;

		this.Draw = function() {	
			this.Update();
			DrawSprite(this.X, this.Y, this.Tex);
		}
	}
	extend(TDynamicBallSprite, TObj);
	
	function TDynamicPers(X, Y, Tex) {
		TDynamicPers.superclass.constructor.call(this, X, Y);
		
		this.Body = Add_ball(X, Y, Tex.Sz, true, 1.0, 0.5, 0.25);
		
		this.Tex = Tex;
		this.A = 0;
		this.A2 = 5;
		this.Sleep = 0;
		this.ASleep = 20;
		
		this.D = 1;
		this.Health = Tex.Health;
		this.Live = true;
		this.Visible = true;
		
		this.kUp = false;
		this.kDown = false;
		this.kLeft = false;
		this.kRigth = false;
		this.kAtack = false;

		this.AI = function() {}
		
		this.PersUpdate = function() {
			if (this.Visible) {
				if (this.Live) {
					
					var X = (this.kLeft? -1: 0) + (this.kRigth? 1: 0) ;
					var Y = (this.kUp? -1: 0) + (this.kDown? 0: 0) ;
					if (X != 0)
						this.D = X > 0? 1 : -1;
					if ((X != 0) | (Y != 0)) {
						if ((Y < 0) & (this.A2 < 5))
							this.A2 = 5;
						Map.Add_Force(this.Body, X/2, Y/2);
					}
					else
						this.A2 = 4;
					
					if (this.kAtack)
					  this.Atack();
					
					if (this.Sleep > 0) {
						this.Sleep--;
						if (this.Sleep == 10)
						  this.A = 0;
					}
				
					if (this.A2 > 4) {
					  this.A2++;
					  if (this.A2 > 7)
						this.A2 = 5;
					}	
					this.AI();	
				}
				else {
					this.Y+=5;
					if (this.Y > height + 20) 
						this.Visible = false;
				}
			}
		}
		this.Draw = function() {
			if (this.Visible) {
				if (this.Live)
				  this.Update();
				DrawPers(this.X, this.Y, this.Tex, this.D < 0, this.A, this.A2);
			}
		}
		this.Demage = function(APD) {
			Add_Force(this.Body, APD*10, 5);
			if ((this.A != 3) & (this.Sleep < 10)) {
				this.A = 3;
				this.Sleep = 20;
				this.Health -= 10;
				if (this.Health < 0) 
					this.Die();
			}
		}
		this.Die = function() {
			world.DestroyBody(this.Body);
			this.Live = false;
			this.A = 3;
			this.A2 = 4;
		}
		this.Atack = function() {
			if (this.Sleep == 0) {
				this.A = rand(1, 3);

				this.Sleep = this.ASleep;
				
				for (var I = Pers.length - 1; I > -1 ; --I)
				if ((Pers[I].Live) & (this != Pers[I]))
				if (this.Tex.ARect(this, Pers[I])) 
				//if (PointLength(this.X, this.Y, Pers[I].X, Pers[I].Y) < 32) {
					Pers[I].Demage(this.D);
			}
		}
	}
	extend(TDynamicPers, TObj);
	
	function TNazi(X, Y, Tex) {
		TNazi.superclass.constructor.call(this, X, Y, Tex);

		this.ASleep = 22;
		
		this.AI = function() {
			var FindA = false;
			var G = 0;	
			var Ln = 100 ;
			for (var I = GoodGuys.length - 1; I >= 0; --I) 
			if (GoodGuys[I].Live)	{
				var Lnt = PointLength(this.X, this.Y, GoodGuys[I].X, GoodGuys[I].Y);
				if (Lnt < Ln) { 
					Ln = Lnt;
					G = GoodGuys[I];
					FindA = true;
				}
			}
			if (FindA) {
				//this.D = (G.X < this.X)? -1 : 1;
				if (Ln < Tex.Sz + G.Tex.Sz)// alert(Lnt + ' ' +G.Tex.Sz);
					this.kAtack = true;
				 else {
					this.kAtack = false;
					this.kDown = false;
					this.kLeft = (G.X < this.X);
					this.kRigth = (G.X > this.X);
					this.kUp = (G.Y < this.Y);
				 }
			}
			else {
					this.kAtack = false;
					this.kDown = false;
					this.kLeft = false
					this.kRigth = false;
					this.kUp = false;				
			}
		}
	}
	extend(TNazi, TDynamicPers);
	
	function TButton(X, Y, Tex) {
		TButton.superclass.constructor.call(this, X, Y);
		
		this.Body = Add_ball(X, Y, Tex.Sz, true, 0.01, 0.5, 0.025);
		
		this.Tex = Tex;

		this.Live = true;
		this.Visible = true;

		this.AI = function() {alert('ai')}
		this.ActionTime = 0;
		this.PersUpdate = function() {
			if (this.ActionTime > 0) {
				this.ActionTime--;
				if ((this.Live) & (this.ActionTime == 1))
					this.Action();
			}	
		}
		this.Draw = function() {
			if (this.Visible) {
				this.Update();
				//DrawButton(this.X, this.Y, Tex, this.Live? (this.ActionTime > 0? 1 : 0) : 2);
				DrawButton(this.X, this.Y, Tex,  (this.ActionTime > 0? 1 : 0));
			}
		}
		this.Demage = function(APD) {
			Add_Force(this.Body, APD*20, -10);
			this.ActionTime = 20;
		}
		this.Click = function(mX, mY) {

			if (PointLength(this.X, this.Y, mX, mY) < this.Tex.Sz) {
				/*var Xd = this.X - mX;
				var Yd = this.Y - mY; 
				var A = 90*180/Math.PI - Math.atan2(Xd, Yd);
				var F = -Math.sqrt(Xd*Xd + Yd*Yd) * 2;
				var c = Math.cos(A);
				var s = Math.sin(A);
				alert(F);
				Add_Force(this.Body, c*F, s*F);
			*/
				this.Demage(this.X > mX? 2 : -2);
				return true;
			}
			return false;
		}
		this.Die = function() {alert('Die')};
		this.Atack = function() {alert('Atack')};
		this.Action = function() {};
	}
	extend(TButton, TObj);
		
	function TDynamicBox(X, Y, W, H, A, Color) {
		TDynamicBox.superclass.constructor.call(this, X, Y);

		this.Body = Add_box(X, Y, W, H, A, true, 1.0, 0.5, 0.25);

		this.Draw = function() {
			this.Update();
			DrawBoxA(this.X, this.Y, W, H, this.Body.GetAngle(), Color);
		}
	}	
	extend(TDynamicBox, TObj);
	
	function TStaticBox(X, Y, W, H, Color) {
		this.X = X;
		this.Y = Y;
		this.XC = X / M2Pix;
		this.YC = Y / M2Pix;	
		this.Body = Add_box(X + W/2, Y + H/2, W, H, 0, false, 1.0, 0.5, 0.25);
		this.Update = function() {};
		this.Draw = function() {
			this.Update();
			DrawBox(X, Y, W, H, Color);
		}
	}
	
	function TStaticBoxA(X, Y, W, H, A, Color) {
		this.X = X;
		this.Y = Y;
		this.XC = X / M2Pix;
		this.YC = Y / M2Pix;	
		this.Body = Add_box(X, Y, W, H, A, false, 1.0, 0.5, 0.25);
		this.A = A * Pi180d;
		this.Update = function() {};
		this.Draw = function() {
			this.Update();
			DrawBoxA(X, Y, W, H, this.A, Color);
		}
	}	
	
	var Rope = new Array();	
	var Obj = new Array();
	
	var Nazi = new Array();
	var Pers = new Array();
	var GoodGuys = new Array();
	var Danger = new Array();
	var Weapon = new Array();
	var WeaponBox = new Array();
	
	var Button = new Array();
	
	this.AddRope = function(X1, Y1, X2, Y2, L, Sg, Color) {
		var I = Rope.length;
		Rope[I] = new TRope(X1, Y1, X2, Y2, L, Sg, Color, false);
		return Rope[I];
	}
	
	this.AddRope2Obj = function(B1, B2, L, Sg, Color) {
		var I = Rope.length;
		Rope[I] = new TRope(B1.X, B1.Y, B2.X, B2.Y, L, Sg, Color, true);
		this.Add_RJoint(Rope[I].Start, B1.Body);
		this.Add_RJoint(Rope[I].End, B2.Body);
	
		return Rope[I];
	}
	
	this.AddButton = function(X, Y, Tex1) {
		var I = Button.length;
		Button[I] = new TButton(X, Y, Tex1);
		Obj[Obj.length] = Button[I];
		Pers[Pers.length] = Button[I];
		return Button[I];
	}	
	
	this.AddNazi = function(X, Y, Tex1) {
		var I = Nazi.length;
		Nazi[I] = new TNazi(X, Y, Tex1);
		Obj[Obj.length] = Nazi[I];
		Pers[Pers.length] = Nazi[I];
		return Nazi[I];
	}	
	this.NaziLive = function() {
		for (var N = Nazi.length - 1; N >= 0; --N) 
		if (Nazi[N].Visible) return false;
		return true;
	}
	
	this.AddMe = function(X, Y, Tex) {
		var R = Obj[Obj.push(new TDynamicPers(X, Y, Tex)) - 1];
		Pers.push(R);
		if (GoodGuys.length == 0) 
			this.keyMe = R;
		this.keyMe2 = R;
		GoodGuys[GoodGuys.length] = R;
		return R;
	}		
	
	this.AddStaticBox = function(X, Y, W, H, Color) {
		var I = Obj.length;
		Obj[I] = new TStaticBox(X, Y, W, H, Color);
		return Obj[I];
	}		
	this.AddStaticBoxFC = function(X, Y, W, H, Color) {
		var I = Obj.length;
		Obj[I] = new TStaticBox(X - W/2, Y - H/2, W, H, Color);
		return Obj[I];
	}	
	this.AddStaticBoxA = function(X, Y, W, H, A, Color) {
		var I = Obj.length;
		Obj[I] = new TStaticBoxA(X, Y, W, H, A, Color);
		return Obj[I];
	}		
	
	this.AddDynamicBox = function(X, Y, W, H, Color) {
		var I = Obj.length;
		Obj[I] = new TDynamicBox(X + W/2, Y + H/2, W, H, 0, Color);
		return Obj[I];
	}		
	this.AddDynamicBoxFC = function(X, Y, W, H, Color) {
		var I = Obj.length;
		Obj[I] = new TDynamicBox(X, Y, W, H, 0, Color);
		return Obj[I];
	}	
	this.AddDynamicBoxA = function(X, Y, W, H, A, Color) {
		var I = Obj.length;
		Obj[I] = new TDynamicBox(X, Y, W, H, A, Color);
		return Obj[I];
	}	
	this.AddDynamicBall = function(X, Y, Sz, Color) {
		var I = Obj.length;
		Obj[I] = new TDynamicBall(X, Y, Sz, Color) 
		return Obj[I];
	}	
	this.AddDynamicBallSprite = function(X, Y, Sz, Tex) {
		var I = Obj.length;
		Obj[I] = new TDynamicBallSprite(X, Y, Sz, Tex) 
		return Obj[I];
	}	
	
	this.AddDanger = function(A) {
		Danger[Danger.length] = A;
	}
	
	this.AddWeapon = function(A) {
		Weapon[Weapon.length] = A;
	}
		
this.Click = function(X, Y) {
	for (var I = Button.length - 1; I >= 0; --I) 
	if	(Button[I].Click(X, Y))
	  break;
}

this.Draw = function() {
	for (var I = Rope.length - 1; I >= 0; --I) 
		Rope[I].Draw();
	var L = Obj.length;
	for (var I = 0; I < L; I++) 
		Obj[I].Draw();
/*
	for (var I = Nazi.length - 1; I >= 0; --I) 	
	if (Nazi[I].Health < 0 )	
			Nazi.splice(I, 1);
	*/	

	
}

var MagnetForce = 1.2;

this.worldUpdate = function() {
	world.Step(1 / 60, 10, 10);
}

this.Update = function() {

	var L = Pers.length;

	for (var I = 0; I < L; I++) 
		Pers[I].PersUpdate();
	
	for (var I = Danger.length - 1; I >= 0; --I) {
		for (var N = Pers.length - 1; N >= 0; --N) 
		if ((Pers[N].Live) & (PointLength(Pers[N].X, Pers[N].Y, Danger[I].X, Danger[I].Y) < (Danger[I].Sz+Pers[N].Tex.Sz) ))
			Pers[N].Demage(0);
	}	
	
	for (var I = Weapon.length - 1; I >= 0; --I) {
		for (var N = Nazi.length - 1; N >= 0; --N) 
		if ((Nazi[N].Live) & (PointLength(Nazi[N].X, Nazi[N].Y, Weapon[I].X, Weapon[I].Y) < (Weapon[I].Sz+Nazi[N].Tex.Sz) ))
			Nazi[N].Demage(0);
	}	
	
	for (var I = WeaponBox.length - 1; I >= 0; --I) {
		for (var N = GoodGuys.length - 1; N >= 0; --N) 
		if ((GoodGuys[N].Live) & (PointLength(GoodGuys[N].X, GoodGuys[N].Y, WeaponBox[I].X, WeaponBox[I].Y) < (WeaponBox[I].Sz+GoodGuys[N].Tex.Sz) ))
			alert(N)
	}	
	
    world.ClearForces(); 
}


/*
	function someClear(some) {
		for (var I = some.length - 1; I >= 0; I--)
			world.DestroyBody(some[I].Body);
		some.splice(0, some.length);
	}
*/
	this.Clear = function() {
		/*someClear(Obj);
		
		for (var I = Rope.length - 1; I >= 0; I--)
			Rope[I].Clear();
			Rope.splice(0, Rope.length);
			*/
			
		var dbody = world.GetBodyList();
		while (dbody) {
		  world.DestroyBody(dbody);
		  dbody = dbody.GetNext (); 
		}
		
		Obj.splice(0, Obj.length);
		Rope.splice(0, Rope.length);
		Pers.splice(0, Pers.length);
		Nazi.splice(0, Nazi.length);
		GoodGuys.splice(0, GoodGuys.length);
		Danger.splice(0, Danger.length);
		Weapon.splice(0, Weapon.length);
		WeaponBox.splice(0, WeaponBox.length);
		Button.splice(0, Button.length);
	}

	this.ObjCount = function () {
		return Obj.length;
	}

	this.Prepare = function() {
		this.AddStaticBox(0, this.height-6, this.width, 6, '#000000');
		this.AddStaticBox(0, 0, this.width, 6, '#000000');
		this.AddStaticBox(0, 0, 6, this.height, '#000000');
		this.AddStaticBox(this.width-6, 0, 6, this.height, '#000000');	
	}

}