QuickBox2D練習 その2

by Ryogo_Quberey forked from QuickBox2D練習 (diff: 24)
-memo-
最初は玉が積み上がっていき、突然弾けだす
上の風車?を回すと高速回転し始める
♥0 | Line 45 | Modified 2011-01-04 01:04:03 | MIT License
play

ActionScript3 source code

/**
 * 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/tLJb
 */

// forked from Ryogo_Quberey's QuickBox2D練習
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, lineAlpha:0, fillColor:0xffffff, restitution:2})  
        sim.addBox({x:sw, y:sh / 2, width:1, height:sh,  density:.0, lineAlpha:0, fillColor:0xffffff ,restitution:2})
        
        
        
        //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.addBox({x:6, y:4, width:2, height:0.3 ,  density:10, lineAlpha:0, fillColor:0x9400d3});
        var maru_B:QuickObject = sim.addBox({x:4, y:8.5, width:7, height:0.2,  density:10, fixedRotation:true, lineAlpha:0, fillColor:0x9400d3});
        maru_A.body.SetLinearVelocity(new b2Vec2(5, 0));    
        
        var area:QuickObject = sim.addBox({x:5, y:10, width:14, height:0.2,  density:0, angle:0.1, restitution:1.2, fixedRotation:true, lineAlpha:0, fillColor:0x9400d3});

         
        //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 j1:QuickObject = sim.addJoint({type:"revolute", a:sim.w.GetGroundBody(), b:maru_A.body, anchor:maru_A.body.GetWorldCenter()})
         //var j2:QuickObject = sim.addJoint({type:"distance", a:maru_A.body, b:auto4.body});
         var j1:QuickObject = sim.addJoint({type:"revolute", a:sim.w.GetGroundBody(), b:maru_A.body,  anchor:maru_A.body.GetWorldCenter()})
           
         var j2:QuickObject = sim.addJoint({type:"prismatic", a:sim.w.GetGroundBody(),enableMotor:true, maxMotorTorque:80, axis:new b2Vec2(1, 0), b:maru_B.body, anchor:maru_B.body.GetWorldCenter()})
         //var rev1:QuickObject = sim.addJoint({type:"revolute", a:sim.w.GetGroundBody(), b:maru_A.body, anchor:maru_A.body.GetWorldCenter()});
         sim.addJoint({type:"gear", a:maru_A.body, b:maru_B.body, joint1:j1.joint, joint2:j2.joint});
         //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 = 50;
for (i = 0; i<circleNum; i++){
    circles[i] = sim.addCircle({x: 6, y:-2 - i, radius:0.1 + Math.random()*0.4, fillColor:0x00ffff,  lineAlpha:0});
}
 

 
// 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 - 11) + 4;
            // access to Box2D b2Body methods
            circles[i].body.SetLinearVelocity(resetVec);
        }
     }
}
         //var resetVec:b2Vec2 = new b2Vec2();
         }
         
         
         
         }
        
                 
         
         
         
         
        
         
        
            // write as3 code here..
         
        }
        
        
    
        
    
  

Forked