notice: Flash editor updated! Join the development! Thanks to MiniBuilder


embed

FORKED
  1. // forked from sake's 階段を上るやつ2
  2. /*
  3.    階段を上るやつ2。
  4.    定数kの値を変更すると、ジャンプする高さが変更できます。
  5. */
  6. package
  7. {
  8.     import flash.display.Graphics;
  9.     import flash.display.Sprite;
  10.     import flash.events.Event;
  11.     import flash.geom.Matrix3D;
  12.     [SWF(width="465", height="465", backgroundColor="0xFFFFFF", frameRate="40")]
  13.     public class stair2 extends Sprite
  14.     {
  15.         private var container:Sprite;
  16.         private var cube:Sprite;
  17.         private var xx:Number
  18.         private var nn:int;
  19.         
  20.         // ジャンプする度合いを制御する定数
  21.         private const k:Number = 6;
  22.         public function stair2()
  23.         {
  24.             container=new Sprite();
  25.             container.x=465 / 2;
  26.             container.y=465 / 2;
  27.             addChild(container);
  28.             container.scaleX=container.scaleY=container.scaleZ=1.8;
  29.             nn=xx=0;
  30.             cube=new Sprite;
  31.             container.addChild(cube);
  32.             cube.name="sp" + nn.toString();
  33.             nn++;
  34.             // Cubeを作る
  35.             var sp0:Sprite=new Sprite();
  36.             draw(sp0.graphics);
  37.             sp0.rotationY=90;
  38.             sp0.x=5;
  39.             cube.addChild(sp0);
  40.             sp0.name="plane0";
  41.             var sp1:Sprite=new Sprite();
  42.             draw(sp1.graphics);
  43.             sp1.rotationY=-90;
  44.             sp1.x=-5;
  45.             cube.addChild(sp1);
  46.             sp1.name="plane1";
  47.             var sp2:Sprite=new Sprite();
  48.             draw(sp2.graphics);
  49.             sp2.rotationX=-90;
  50.             sp2.y=-5;
  51.             cube.addChild(sp2);
  52.             sp2.name="plane2";
  53.             var sp3:Sprite=new Sprite();
  54.             draw(sp3.graphics);
  55.             sp3.rotationX=90;
  56.             sp3.y=5;
  57.             cube.addChild(sp3);
  58.             sp3.name="plane3";
  59.             var sp4:Sprite=new Sprite();
  60.             draw(sp4.graphics);
  61.             sp4.z=-5;
  62.             cube.addChild(sp4);
  63.             sp4.name="plane4";
  64.             var sp5:Sprite=new Sprite();
  65.             draw(sp5.graphics);
  66.             sp5.z=5;
  67.             cube.addChild(sp5);
  68.             sp5.name="plane5";
  69.             // 階段を作る
  70.                                 /*            
  71.                                 for(var i:int=-200; i < 200; i+=10)
  72.             {
  73.                 var sp6:Sprite=new Sprite;
  74.                 draw(sp6.graphics);
  75.                 container.addChild(sp6);
  76.                 sp6.x=i;
  77.                 sp6.y=-(i - 5);
  78.                 sp6.rotationX=90;
  79.                 sp6.name="sp" + nn.toString();
  80.                 nn++;
  81.                 var sp7:Sprite=new Sprite;
  82.                 draw(sp7.graphics);
  83.                 container.addChild(sp7);
  84.                 sp7.x=i + 5;
  85.                 sp7.y=-i;
  86.                 sp7.rotationY=90;
  87.                 sp7.name="sp" + nn.toString();
  88.                 nn++;
  89.             }
  90.                             */
  91.             addEventListener(Event.ENTER_FRAME, onFrame);
  92.         }
  93.         private function draw(g:Graphics):void
  94.         {
  95.             g.beginFill(0xFFFFFF * Math.random(), 0.6);
  96.             g.drawRect(-5, -51010);
  97.             g.endFill();
  98.         }
  99.         private function onFrame(e:Event):void
  100.         {
  101.             container.rotationY+=0.5;
  102.             // ここでCubeの座標を計算
  103.             cube.x=10 * xx;
  104.             cube.y = -10 *( -1*(2*k-1+2*Math.sqrt(k*k-k))*(xx - k + Math.sqrt(k*k-k)-Math.floor(xx))*(xx - k + Math.sqrt(k*k-k)-Math.floor(xx)) + k + Math.floor(xx));
  105.             xx+=0.1;
  106.             if (xx >= 18) xx=-18;
  107.             var array:Array=[];
  108.             for(var i:int=0; i < 6; i++)
  109.             {
  110.                 var sp:Sprite=cube.getChildByName("plane" + i.toString())as Sprite;
  111.                 var mat:Matrix3D=sp.transform.getRelativeMatrix3D(this);
  112.                 array.push({sp:sp, z:mat.position.z});
  113.             }
  114.             array.sortOn("z"Array.NUMERIC | Array.DESCENDING);
  115.             for(var i:int=0; i < 6; i++)
  116.             {
  117.                 var sp:Sprite=array[i].sp as Sprite;
  118.                 cube.setChildIndex(sp, i);
  119.             }
  120.             array=[];
  121.             for(var i:int=0; i < nn; i++)
  122.             {
  123.                 var sp:Sprite=container.getChildByName("sp" + i.toString())as Sprite;
  124.                 var mat:Matrix3D=sp.transform.getRelativeMatrix3D(this);
  125.                 array.push({sp:sp, z:mat.position.z});
  126.             }
  127.             array.sortOn("z"Array.NUMERIC | Array.DESCENDING);
  128.             for(var i:int=0; i < nn; i++)
  129.             {
  130.                 var sp:Sprite=array[i].sp as Sprite;
  131.                 container.setChildIndex(sp, i);
  132.             }
  133.         }
  134.     }
  135. }
noswf
  1. // forked from sake's 階段を上るやつ2
  2. /*
  3.    階段を上るやつ2。
  4.    定数kの値を変更すると、ジャンプする高さが変更できます。
  5. */
  6. package
  7. {
  8.     import flash.display.Graphics;
  9.     import flash.display.Sprite;
  10.     import flash.events.Event;
  11.     import flash.geom.Matrix3D;
  12.     [SWF(width="465", height="465", backgroundColor="0xFFFFFF", frameRate="40")]
  13.     public class stair2 extends Sprite
  14.     {
  15.         private var container:Sprite;
  16.         private var cube:Sprite;
  17.         private var xx:Number
  18.         private var nn:int;
  19.         
  20.         // ジャンプする度合いを制御する定数
  21.         private const k:Number = 6;
  22.         public function stair2()
  23.         {
  24.             container=new Sprite();
  25.             container.x=465 / 2;
  26.             container.y=465 / 2;
  27.             addChild(container);
  28.             container.scaleX=container.scaleY=container.scaleZ=1.8;
  29.             nn=xx=0;
  30.             cube=new Sprite;
  31.             container.addChild(cube);
  32.             cube.name="sp" + nn.toString();
  33.             nn++;
  34.             // Cubeを作る
  35.             var sp0:Sprite=new Sprite();
  36.             draw(sp0.graphics);
  37.             sp0.rotationY=90;
  38.             sp0.x=5;
  39.             cube.addChild(sp0);
  40.             sp0.name="plane0";
  41.             var sp1:Sprite=new Sprite();
  42.             draw(sp1.graphics);
  43.             sp1.rotationY=-90;
  44.             sp1.x=-5;
  45.             cube.addChild(sp1);
  46.             sp1.name="plane1";
  47.             var sp2:Sprite=new Sprite();
  48.             draw(sp2.graphics);
  49.             sp2.rotationX=-90;
  50.             sp2.y=-5;
  51.             cube.addChild(sp2);
  52.             sp2.name="plane2";
  53.             var sp3:Sprite=new Sprite();
  54.             draw(sp3.graphics);
  55.             sp3.rotationX=90;
  56.             sp3.y=5;
  57.             cube.addChild(sp3);
  58.             sp3.name="plane3";
  59.             var sp4:Sprite=new Sprite();
  60.             draw(sp4.graphics);
  61.             sp4.z=-5;
  62.             cube.addChild(sp4);
  63.             sp4.name="plane4";
  64.             var sp5:Sprite=new Sprite();
  65.             draw(sp5.graphics);
  66.             sp5.z=5;
  67.             cube.addChild(sp5);
  68.             sp5.name="plane5";
  69.             // 階段を作る
  70.             for(var i:int=-200; i < 200; i+=10)
  71.             {
  72.                 var sp6:Sprite=new Sprite;
  73.                 draw(sp6.graphics);
  74.                 container.addChild(sp6);
  75.                 sp6.x=i;
  76.                 sp6.y=-(i - 5);
  77.                 sp6.rotationX=90;
  78.                 sp6.name="sp" + nn.toString();
  79.                 nn++;
  80.                 var sp7:Sprite=new Sprite;
  81.                 draw(sp7.graphics);
  82.                 container.addChild(sp7);
  83.                 sp7.x=i + 5;
  84.                 sp7.y=-i;
  85.                 sp7.rotationY=90;
  86.                 sp7.name="sp" + nn.toString();
  87.                 nn++;
  88.             }
  89.             addEventListener(Event.ENTER_FRAME, onFrame);
  90.         }
  91.         private function draw(g:Graphics):void
  92.         {
  93.             g.beginFill(0xFFFFFF * Math.random(), 0.6);
  94.             g.drawRect(-5, -51010);
  95.             g.endFill();
  96.         }
  97.         private function onFrame(e:Event):void
  98.         {
  99.             container.rotationY+=0.5;
  100.             // ここでCubeの座標を計算
  101.             cube.x=10 * xx;
  102.             cube.y = -10 *( -1*(2*k-1+2*Math.sqrt(k*k-k))*(xx - k + Math.sqrt(k*k-k)-Math.floor(xx))*(xx - k + Math.sqrt(k*k-k)-Math.floor(xx)) + k + Math.floor(xx));
  103.             xx+=0.1;
  104.             if (xx >= 18) xx=-18;
  105.             var array:Array=[];
  106.             for(var i:int=0; i < 6; i++)
  107.             {
  108.                 var sp:Sprite=cube.getChildByName("plane" + i.toString())as Sprite;
  109.                 var mat:Matrix3D=sp.transform.getRelativeMatrix3D(this);
  110.                 array.push({sp:sp, z:mat.position.z});
  111.             }
  112.             array.sortOn("z"Array.NUMERIC | Array.DESCENDING);
  113.             for(var i:int=0; i < 6; i++)
  114.             {
  115.                 var sp:Sprite=array[i].sp as Sprite;
  116.                 cube.setChildIndex(sp, i);
  117.             }
  118.             array=[];
  119.             for(var i:int=0; i < nn; i++)
  120.             {
  121.                 var sp:Sprite=container.getChildByName("sp" + i.toString())as Sprite;
  122.                 var mat:Matrix3D=sp.transform.getRelativeMatrix3D(this);
  123.                 array.push({sp:sp, z:mat.position.z});
  124.             }
  125.             array.sortOn("z"Array.NUMERIC | Array.DESCENDING);
  126.             for(var i:int=0; i < nn; i++)
  127.             {
  128.                 var sp:Sprite=array[i].sp as Sprite;
  129.                 container.setChildIndex(sp, i);
  130.             }
  131.         }
  132.     }
  133. }
noswf
Get Adobe Flash Player