階段を上るやつ2 forked from: 階段を上るやつ2
- // forked from sake's 階段を上るやつ2
- /*
- 階段を上るやつ2。
- 定数kの値を変更すると、ジャンプする高さが変更できます。
- */
- package
- {
- import flash.display.Graphics;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.geom.Matrix3D;
- [SWF(width="465", height="465", backgroundColor="0xFFFFFF", frameRate="40")]
- public class stair2 extends Sprite
- {
- private var container:Sprite;
- private var cube:Sprite;
- private var xx:Number
- private var nn:int;
- // ジャンプする度合いを制御する定数
- private const k:Number = 6;
- public function stair2()
- {
- container=new Sprite();
- container.x=465 / 2;
- container.y=465 / 2;
- addChild(container);
- container.scaleX=container.scaleY=container.scaleZ=1.8;
- nn=xx=0;
- cube=new Sprite;
- container.addChild(cube);
- cube.name="sp" + nn.toString();
- nn++;
- // Cubeを作る
- var sp0:Sprite=new Sprite();
- draw(sp0.graphics);
- sp0.rotationY=90;
- sp0.x=5;
- cube.addChild(sp0);
- sp0.name="plane0";
- var sp1:Sprite=new Sprite();
- draw(sp1.graphics);
- sp1.rotationY=-90;
- sp1.x=-5;
- cube.addChild(sp1);
- sp1.name="plane1";
- var sp2:Sprite=new Sprite();
- draw(sp2.graphics);
- sp2.rotationX=-90;
- sp2.y=-5;
- cube.addChild(sp2);
- sp2.name="plane2";
- var sp3:Sprite=new Sprite();
- draw(sp3.graphics);
- sp3.rotationX=90;
- sp3.y=5;
- cube.addChild(sp3);
- sp3.name="plane3";
- var sp4:Sprite=new Sprite();
- draw(sp4.graphics);
- sp4.z=-5;
- cube.addChild(sp4);
- sp4.name="plane4";
- var sp5:Sprite=new Sprite();
- draw(sp5.graphics);
- sp5.z=5;
- cube.addChild(sp5);
- sp5.name="plane5";
- // 階段を作る
- /*
- for(var i:int=-200; i < 200; i+=10)
- {
- var sp6:Sprite=new Sprite;
- draw(sp6.graphics);
- container.addChild(sp6);
- sp6.x=i;
- sp6.y=-(i - 5);
- sp6.rotationX=90;
- sp6.name="sp" + nn.toString();
- nn++;
- var sp7:Sprite=new Sprite;
- draw(sp7.graphics);
- container.addChild(sp7);
- sp7.x=i + 5;
- sp7.y=-i;
- sp7.rotationY=90;
- sp7.name="sp" + nn.toString();
- nn++;
- }
- */
- addEventListener(Event.ENTER_FRAME, onFrame);
- }
- private function draw(g:Graphics):void
- {
- g.beginFill(0xFFFFFF * Math.random(), 0.6);
- g.drawRect(-5, -5, 10, 10);
- g.endFill();
- }
- private function onFrame(e:Event):void
- {
- container.rotationY+=0.5;
- // ここでCubeの座標を計算
- cube.x=10 * xx;
- 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));
- xx+=0.1;
- if (xx >= 18) xx=-18;
- var array:Array=[];
- for(var i:int=0; i < 6; i++)
- {
- var sp:Sprite=cube.getChildByName("plane" + i.toString())as Sprite;
- var mat:Matrix3D=sp.transform.getRelativeMatrix3D(this);
- array.push({sp:sp, z:mat.position.z});
- }
- array.sortOn("z", Array.NUMERIC | Array.DESCENDING);
- for(var i:int=0; i < 6; i++)
- {
- var sp:Sprite=array[i].sp as Sprite;
- cube.setChildIndex(sp, i);
- }
- array=[];
- for(var i:int=0; i < nn; i++)
- {
- var sp:Sprite=container.getChildByName("sp" + i.toString())as Sprite;
- var mat:Matrix3D=sp.transform.getRelativeMatrix3D(this);
- array.push({sp:sp, z:mat.position.z});
- }
- array.sortOn("z", Array.NUMERIC | Array.DESCENDING);
- for(var i:int=0; i < nn; i++)
- {
- var sp:Sprite=array[i].sp as Sprite;
- container.setChildIndex(sp, i);
- }
- }
- }
- }
階段を上るやつ2 forked from: 階段を上るやつ2
- // forked from sake's 階段を上るやつ2
- /*
- 階段を上るやつ2。
- 定数kの値を変更すると、ジャンプする高さが変更できます。
- */
- package
- {
- import flash.display.Graphics;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.geom.Matrix3D;
- [SWF(width="465", height="465", backgroundColor="0xFFFFFF", frameRate="40")]
- public class stair2 extends Sprite
- {
- private var container:Sprite;
- private var cube:Sprite;
- private var xx:Number
- private var nn:int;
- // ジャンプする度合いを制御する定数
- private const k:Number = 6;
- public function stair2()
- {
- container=new Sprite();
- container.x=465 / 2;
- container.y=465 / 2;
- addChild(container);
- container.scaleX=container.scaleY=container.scaleZ=1.8;
- nn=xx=0;
- cube=new Sprite;
- container.addChild(cube);
- cube.name="sp" + nn.toString();
- nn++;
- // Cubeを作る
- var sp0:Sprite=new Sprite();
- draw(sp0.graphics);
- sp0.rotationY=90;
- sp0.x=5;
- cube.addChild(sp0);
- sp0.name="plane0";
- var sp1:Sprite=new Sprite();
- draw(sp1.graphics);
- sp1.rotationY=-90;
- sp1.x=-5;
- cube.addChild(sp1);
- sp1.name="plane1";
- var sp2:Sprite=new Sprite();
- draw(sp2.graphics);
- sp2.rotationX=-90;
- sp2.y=-5;
- cube.addChild(sp2);
- sp2.name="plane2";
- var sp3:Sprite=new Sprite();
- draw(sp3.graphics);
- sp3.rotationX=90;
- sp3.y=5;
- cube.addChild(sp3);
- sp3.name="plane3";
- var sp4:Sprite=new Sprite();
- draw(sp4.graphics);
- sp4.z=-5;
- cube.addChild(sp4);
- sp4.name="plane4";
- var sp5:Sprite=new Sprite();
- draw(sp5.graphics);
- sp5.z=5;
- cube.addChild(sp5);
- sp5.name="plane5";
- // 階段を作る
- for(var i:int=-200; i < 200; i+=10)
- {
- var sp6:Sprite=new Sprite;
- draw(sp6.graphics);
- container.addChild(sp6);
- sp6.x=i;
- sp6.y=-(i - 5);
- sp6.rotationX=90;
- sp6.name="sp" + nn.toString();
- nn++;
- var sp7:Sprite=new Sprite;
- draw(sp7.graphics);
- container.addChild(sp7);
- sp7.x=i + 5;
- sp7.y=-i;
- sp7.rotationY=90;
- sp7.name="sp" + nn.toString();
- nn++;
- }
- addEventListener(Event.ENTER_FRAME, onFrame);
- }
- private function draw(g:Graphics):void
- {
- g.beginFill(0xFFFFFF * Math.random(), 0.6);
- g.drawRect(-5, -5, 10, 10);
- g.endFill();
- }
- private function onFrame(e:Event):void
- {
- container.rotationY+=0.5;
- // ここでCubeの座標を計算
- cube.x=10 * xx;
- 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));
- xx+=0.1;
- if (xx >= 18) xx=-18;
- var array:Array=[];
- for(var i:int=0; i < 6; i++)
- {
- var sp:Sprite=cube.getChildByName("plane" + i.toString())as Sprite;
- var mat:Matrix3D=sp.transform.getRelativeMatrix3D(this);
- array.push({sp:sp, z:mat.position.z});
- }
- array.sortOn("z", Array.NUMERIC | Array.DESCENDING);
- for(var i:int=0; i < 6; i++)
- {
- var sp:Sprite=array[i].sp as Sprite;
- cube.setChildIndex(sp, i);
- }
- array=[];
- for(var i:int=0; i < nn; i++)
- {
- var sp:Sprite=container.getChildByName("sp" + i.toString())as Sprite;
- var mat:Matrix3D=sp.transform.getRelativeMatrix3D(this);
- array.push({sp:sp, z:mat.position.z});
- }
- array.sortOn("z", Array.NUMERIC | Array.DESCENDING);
- for(var i:int=0; i < nn; i++)
- {
- var sp:Sprite=array[i].sp as Sprite;
- container.setChildIndex(sp, i);
- }
- }
- }
- }
notice: 


