In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: [quickbox2d] ピタゴラ

/**
 * Copyright Tinker201 ( http://wonderfl.net/user/Tinker201 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/x0NP
 */

// forked from applicott's [quickbox2d] ピタゴラ
package
{
    import Box2D.Common.Math.b2Vec2;
    import Box2D.Dynamics.Joints.b2RevoluteJoint;
    
    import com.actionsnippet.qbox.QuickBox2D;
    import com.actionsnippet.qbox.QuickObject;
    
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    
    [SWF (width=450, height=450)]
    public class quick0 extends Sprite
    {
        var revJointA:QuickObject;
        var revJointB:QuickObject;
        private var mv:MovieClip=new MovieClip;
        public function quick0()
        {
            
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            
            graphics.beginFill(0xffffff);
            graphics.drawRect(0,0,500,500);
            graphics.endFill();
            
            //初期化
            addChild(mv);
            var sim:QuickBox2D = new QuickBox2D(mv,{gravityX:0.0, gravityY:20.2});
            //地面を作る
            sim.addBox( { x:10, y:0, width:30, height:0.1, density:0 } );
            sim.addBox( { x:10, y:15, width:30, height:0.1, density:0 } );
            sim.addBox( { x:0, y:15, width:0.1, height:30, density:0 } );
            sim.addBox( { x:15, y:15, width:0.1, height:30, density:0 } );
            sim.addBox( { x:0.5, y:1.8, width:0.1, height:1, density:0,angle:-1.5 } );
            sim.addBox( { x:2, y:2, width:23.1, height:0.1, density:0,angle:0,friction:1 } );
            sim.addBox( { x:9.39, y:4, width:15, height:0.1, density:0,angle:0,friction:1 } );
            
            
            //sim.createStageWalls({bottom:false});
            
            
            var circleB:QuickObject = sim.addCircle({x:0.7, y:0.7, radius:0.5, mass:50, friction:0.2, fillColor:0});
            //domino
            for (var j:int = 0; j<24; j++){
                var curr:QuickObject = sim.addBox({x: 2+j*0.5, y:1.3, width:.1, height:0.8+0.02*j, angularDamping:1,mass:2});
            }
            for (j= 0; j<25; j++){
                var curr:QuickObject = sim.addBox({x: 2+j*0.5, y:3.2, width:.18, height:1.2-0.02*j,mass:3, angularDamping:1});
            }
            
            for (j= 0; j<9; j++)
            var circleB:QuickObject = sim.addCircle({x:13, y:13, radius:0.5, mass:50, friction:0.2, fillColor:0});
            
            /*kassya
            var boxA:QuickObject = sim.addBox({x:1, y:7, fixedRotation:true});
            var boxB:QuickObject = sim.addBox({x:3, y:7, width:1,  fixedRotation:true});
            sim.addJoint({type:"pulley", a:boxA.body, b:boxB.body, groundAnchor1:new b2Vec2(boxA.y,1)});
*/
            
            var boxA:QuickObject = sim.addBox({x:3, y:8, width:4, height:0.1, angularDamping:1});
            var    rev:QuickObject  = sim.addJoint({type:"revolute", a:boxA.body, b:sim.w.GetGroundBody()});
            with (boxA.userData.graphics) lineStyle(), beginFill(0xFF0000), drawCircle(0,0,5);
            var boxA:QuickObject = sim.addBox({x:6, y:7.5, width:4, height:0.1, angularDamping:1});
            var    rev:QuickObject  = sim.addJoint({type:"revolute", a:boxA.body, b:sim.w.GetGroundBody()});
            with (boxA.userData.graphics) lineStyle(), beginFill(0xFF0000), drawCircle(0,0,5);
            
            var boxA:QuickObject = sim.addBox({x:8.2, y:8.5, width:4, height:0.1, angularDamping:1});
            var    rev:QuickObject  = sim.addJoint({type:"revolute", a:boxA.body, b:sim.w.GetGroundBody()});
            with (boxA.userData.graphics) lineStyle(), beginFill(0xFF0000), drawCircle(0,0,5);
            var boxA:QuickObject = sim.addBox({x:10.3, y:7.7, width:4, height:0.1, angularDamping:1});
            var    rev:QuickObject  = sim.addJoint({type:"revolute", a:boxA.body, b:sim.w.GetGroundBody()});
            with (boxA.userData.graphics) lineStyle(), beginFill(0xFF0000), drawCircle(0,0,5);
            
            
            var circleB:QuickObject = sim.addCircle({x:10.3, y:6.5, radius:0.1, mass:5, friction:0.2, fillColor:0});
            
            var plank:QuickObject = sim.addBox({x:4, y:13, width:7, height:0.5, angle:0});
            var fulcrum:QuickObject = sim.addPoly({x:4, y:13, verts:[[0,0, 1,2, -1,2]], density:0})
            sim.addJoint({type:"revolute", a:plank.body, b:fulcrum.body, collideConnected:false});
            
            
            sim.addBox( { x:7.2, y:11.9, width:1, height:1, density:1,angle:0,friction:1,mass:10 } );
            sim.addBox( { x:0.8, y:11.9, width:1, height:1, density:1,angle:0,friction:1,mass:10 } );
            
            
            
            //うにょ
//            var legA:QuickObject = sim.addBox({x:5, y:11, width:2, height:0.2,groupIndex:-2});
//            var three:QuickObject = sim.addBox({x:6.8 + 1.8, y:11, width:2, height:0.2,groupIndex:-2});
//            var legB:QuickObject = sim.addBox({x:6.8, y:11, width:2, height:0.5,groupIndex:-2});
//            sim.setDefault({type:"revolute"});
//            var anchorX:Number = legA.x + (legB.x - legA.x) / 2;
//            var anchorY:Number = legA.y;
//            revJointA = sim.addJoint({a:legA.body, b:legB.body, x1:anchorX, y1:anchorY,enableMotor:true, maxMotorTorque:80});
//            anchorX = legB.x + (three.x - legB.x) / 2;
//            revJointB = sim.addJoint({a:legB.body, b:three.body, x1:anchorX, y1:anchorY, enableMotor:true, maxMotorTorque:80});

        //    setWalkDir(10);

            
            sim.start();
            sim.mouseDrag();     
        }
        private function setWalkDir(dir:Number):void{
            var j:b2RevoluteJoint;
            j = revJointA.joint as b2RevoluteJoint
            j.SetMotorSpeed(dir);
            j = revJointB.joint as b2RevoluteJoint
            j.SetMotorSpeed(dir * -1);
        }

    }
}