QuickBox2D練習
/**
* Copyright Ryogo_Quberey ( http://wonderfl.net/user/Ryogo_Quberey )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/3uUo
*/
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import com.actionsnippet.qbox.*;
import Box2D.Common.Math.*;
import Box2D.Common.Math.b2Vec2;
import Box2D.Dynamics.Joints.b2RevoluteJoint;
import flash.events.Event;
public class FlashTest extends MovieClip{
public function FlashTest() {
var sim:QuickBox2D = new QuickBox2D(this);
var sw:Number = stage.stageWidth / 30;
var sh:Number = stage.stageHeight / 30;
//var yuka:QuickObject = sim.addBox({x:sw / 2, y:sh, width:sw - 3, height:1, density:.0})
//sim.addBox({x:sw / 2, y:0, width:sw - 3, height:1, density:.0 })
sim.addBox({x:0, y:sh / 2, width:1, height:sh , density:.0})
sim.addBox({x:sw, y:sh / 2, width:1, height:sh, density:.0})
//var cup:QuickObject = sim.addPoly({x:9, y:9, wireframe:false, density:0,
//points:[0,0, .5, 0, .5,3, 4,3, 4,0, 4.5,0, 5, 3.5, 0, 3.5, 0,0]});
//var deleter:QuickObject = sim.addBox({x:8.2, y: 11.9, width:1.44, height:0.25, fillColor:0xFF0000});
//sim.addJoint({a:cup.body, b:deleter.body, x1:deleter.x, y1:deleter.y+0.5});
var maru_A:QuickObject = sim.addCircle({x:5, y:4, radius:.3 });
var maru_B:QuickObject = sim.addBox({x:5, y:6, width:7, height:0.5, fixedRotation:true});
var auto4:QuickObject = sim.addBox({x:5, y:2, width:1.33, height:1.33, angle: 0, density:0});
//var boxes:QuickObject = sim.addBox({width:.5, height:.5});
var j1:QuickObject = sim.addJoint({type:"distance", a:maru_A.body, b:maru_B.body});
var j2:QuickObject = sim.addJoint({type:"distance", a:maru_A.body, b:auto4.body});
//var j3:QuickObject = sim.addJoint({type:"distance", a:yuka.body, b:maru_B.body});
var i:int = 0;
// add some circles
var circles:Array = [];
var circleNum:int = 20;
for (i = 0; i<circleNum; i++){
circles[i] = sim.addCircle({x: 8, y:-2 - i, radius:0.1 + Math.random()*0.4, fillColor:0x000000});
}
// vector(0,0) used to reset velocity
var resetVec:b2Vec2 = new b2Vec2();
sim.start();
sim.mouseDrag();
addEventListener(Event.ENTER_FRAME, onLoop);
function onLoop(evt:Event):void {
// rotate all boxes
// move circles to top of sceen after they fall off bottom
for (i= 0; i<circleNum; i++){
if (circles[i].y> 20){
circles[i].y = -1;
circles[i].x = Math.random()*(stage.stageWidth / 30 - 9) + 4;
// access to Box2D b2Body methods
circles[i].body.SetLinearVelocity(resetVec);
}
}
}
var resetVec:b2Vec2 = new b2Vec2();
}
}
// write as3 code here..
}