forked from: forked from: forked from: [QuickBox2D] Doll in space_2

by figma000 forked from ball in maze (diff: 1)
♥0 | Line 104 | Modified 2012-05-23 11:49:42 | MIT License
play

ActionScript3 source code

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

// forked from aduonety's forked from: forked from: [QuickBox2D] Doll in space_2
// forked from a24's forked from: [QuickBox2D] Doll in space
// forked from paq's [QuickBox2D] Doll in space

package 
{
    import Box2D.Common.Math.b2Vec2;
    import Box2D.Dynamics.b2Body;
    import com.actionsnippet.qbox.objects.CircleObject;
    import com.actionsnippet.qbox.QuickBox2D;
    import com.actionsnippet.qbox.QuickObject;
    import flash.display.MovieClip;
    import flash.display.StageScaleMode;
    import flash.events.Event;
      import frocessing.math.*;
    import flash.geom.Rectangle;
    import flash.events.MouseEvent;
    import jp.progression.commands.lists.*;
    import flash.display.Sprite;
    
    
   [SWF(width = 465, height = 465, backgroundColor = 0x333333, frameRate = 60)]
    
    public class Sample extends MovieClip
    {
        private var sim:QuickBox2D;
        private var fixedPoint:b2Vec2 = new b2Vec2(7.25, 7.25);
        private var scale:Number = 10;
        private var balls:Array = new Array();
        private var list:SerialList = new SerialList();
 var data:Array = new Array(10);
            
 
    
        public function Flag(fx:int, fy:int):Array
        {
            
            data[9][9] = 10;
            trace(data[9][9]); // 10
            return(data[fx][fy])
        }
    
        
        public function Sample():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            stage.scaleMode = StageScaleMode.NO_SCALE;
            
            sim = new QuickBox2D(this);
            sim.gravity = new b2Vec2(0, 30);
            sim.iterations = 10;
        // sim.createStageWalls();
            
            sim.setDefault( { fillColor:0xFFFFFF, lineColor:0x333333 } );
            
            for (var i:int = 0; i < 5; i++)  //玉の生成
            {
               
                balls.push(sim.addCircle( { x:Math.random() * 5, y:Math.random() * 4, radius:0.15 } ));
                
            }

          
                  {
             //枠生成
              for(var ix:int = 0; ix < 15; ix++){
                    for(var iy:int = 0; iy < 15; iy++){
                           if(ix == 0 || ix == 14 || iy == 0 || iy == 14){
                               sim.addBox( { x:ix, y:iy, width:1, height:1,density:0 } );
                           }
                    }
              }
             
        
        
              //枠の中身
              {
             for(var ix_d:int = 1; ix_d < 14; ix_d++){
                 for(var iy_d:int = 1; iy_d < 14; iy_d++){
                           if(ix_d % 2 == 0 && iy_d % 2 == 0){
                               sim.addBox( { x:ix_d, y:iy_d, width:1, height:1,density:0 } );
                               Flag(ix_d, iy_d);
                         switch (int(Math.random() * 4)) // 0~3のランダム値を生成
                                {
                                    case 0: ix_d++;  // 右に倒す
                                        sim.addBox( { x:ix_d, y:iy_d, width:1, height:1,density:0 } );
                                        ix_d--;
                                        break;
                                        
                                    case 1: ix_d--; // 左
                                    sim.addBox( { x:ix_d, y:iy_d, width:1, height:1,density:0 } );
                                        ix_d++;
                                         break;
                                         
                                    case 2: iy_d++; // 下
                                    sim.addBox( { x:ix_d, y:iy_d, width:1, height:1,density:0 } );
                                        iy_d--;
                                         break;
                                         
                                    case 3: iy_d--; // 上
                                    sim.addBox( { x:ix_d, y:iy_d, width:1, height:1,density:0 } );
                                        iy_d++;
                                         break;
                                }    
                           } 
                           
                    }
              }
              }
              
              
                  }
            sim.start();
            sim.mouseDrag();
           
        }



        
        private function loop(e:Event):void 
        {
            for ( var i:int = 0; i < balls.length; i ++ )
            {
               var ball:QuickObject = balls[i];
                var fp:b2Vec2 = fixedPoint.Copy();
               fp.Subtract(ball.body.GetPosition());
                fp.Normalize();
               fp.Multiply(50);
                balls.push(sim.addCircle( { x:Math.random() * 15.5, y:Math.random() * 7, radius:0.6 } ));
               ball.body.ApplyForce(fp, ball.body.GetWorldCenter());
                ball.body.ApplyForce(new b2Vec2(0, -30), ball.body.GetWorldCenter());
            }
       }
    }
}