flash on 2011-7-13
/**
* Copyright phi16 ( http://wonderfl.net/user/phi16 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/iknW
*/
package {
import flash.ui.Mouse;
import flash.display.Sprite;
import flash.events.*;
import Box2D.Common.Math.b2Vec2;
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
import Box2D.Dynamics.*;
import Box2D.Dynamics.Joints.*;
public class Postfix extends Sprite{
public var world:b2World;
public var mj:b2MouseJoint;
public var obj:Array=new Array();
public var spr:Sprite=new Sprite();
public var sh:b2Shape;
public function Postfix(){
this.x=465/2;
this.y=465/2;
var worldAABB:b2AABB=new b2AABB();
worldAABB.lowerBound.Set(-300,-300);
worldAABB.upperBound.Set(300,300);
world=new b2World(worldAABB,new b2Vec2(1,1),false);
var circle:b2CircleDef=new b2CircleDef;
circle.radius=0.2;
circle.density=1;
circle.restitution=0.2;
var bodyd:b2BodyDef=new b2BodyDef();
bodyd.position.Set(0,0);
var box:b2Body=world.CreateBody(bodyd);
sh=box.CreateShape(circle);
box.SetMassFromShapes();
var walldef0:b2PolygonDef=new b2PolygonDef();
walldef0.SetAsBox(4.65/2,0.1/2);
var walldef1:b2PolygonDef=new b2PolygonDef();
walldef1.SetAsBox(0.1/2,4.65/2);
var wall:b2BodyDef=new b2BodyDef();
wall.position.Set(0,-4.65/2+0.05);
world.CreateBody(wall).CreateShape(walldef0);
wall=new b2BodyDef();
wall.position.Set(0,4.65/2-0.05);
world.CreateBody(wall).CreateShape(walldef0);
wall=new b2BodyDef();
wall.position.Set(-4.65/2+0.05,0);
world.CreateBody(wall).CreateShape(walldef1);
wall=new b2BodyDef();
wall.position.Set(4.65/2-0.05,0);
world.CreateBody(wall).CreateShape(walldef1);
wall=new b2BodyDef();
wall.position.Set(4.65/2-0.55,4.65/4);
world.CreateBody(wall).CreateShape(walldef1);
spr.graphics.lineStyle(1,0xffffff);
addChild(spr);
addEventListener(Event.ENTER_FRAME,Loop);
}
public var ti:Number=0;
public function Loop(e:Event):void{
world.Step(0.1,10);
ti=Math.atan2(mouseY,mouseX);
world.SetGravity(new b2Vec2(Math.cos(ti),Math.sin(ti)));
spr.graphics.clear();
spr.graphics.beginFill(0x000000);
spr.graphics.drawRect(-465/2,-465/2,465,465);
spr.graphics.endFill();
spr.graphics.lineStyle(1,0xffffff);
spr.graphics.drawCircle(sh.GetBody().GetPosition().x*100,sh.GetBody().GetPosition().y*100,20);
spr.graphics.drawRect(-465/2,-465/2,465,10);
spr.graphics.drawRect(-465/2,465/2,465,-10);
spr.graphics.drawRect(-465/2,-465/2,10,465);
spr.graphics.drawRect(465/2,-465/2,-10,465);
spr.graphics.drawRect(465/2-60,-465/4,10,465);
}
}
}