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: MiniGame2

Get Adobe Flash player
by yd_niku 23 Nov 2010
/**
 * Copyright yd_niku ( http://wonderfl.net/user/yd_niku )
 * GNU General Public License, v3 ( http://www.gnu.org/licenses/quick-guide-gplv3.html )
 * Downloaded from: http://wonderfl.net/c/xa3G
 */

// forked from wsapl's MiniGame2
package
{
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.text.TextField;
    [SWF(frameRate=30)]
    public class Test extends Sprite
    {
        //落ちる物
        private var fall_obj:Sprite;
        //プレイヤー
        private var player:Player;
        //地面
        private var ground:Shape;
        //上から落ちる地面(ハンマーにした理由はそれしか思いつかなかったからです)
        private var hunmer:Shape;
        //にげられる空間
        private var space:Shape;
        //空間のある位置のid
        private var space_pos:int;
        //区切り
        private var solid:int;
        //間隔
        private var interval:Number;
        //プレーヤーの存在できる位置
        private var positions:Array;
        //プレイヤーの現在いる位置のid
        private var ppos:int;
        //落ちる速度
        private var speed:Number;
        //一回落ちたかどうか(trueになると上に上がる)
        //private var ok:Boolean;
        private var _direction:Boolean = false;
        //スコアを表示
        private var score:Score;
        
        
        private var _work:Function;
        private var groundLine:int;
        
        public function Test()
        {
            //区切り(都合上+1する)
            solid=6+1;
            //区切りから、間隔を算出
            interval=(stage.stageWidth)/solid;
            positions=new Array();
            //初期スピード
            speed=7;
            //初期の位置
            ppos=0;
            
            groundLine = stage.stageHeight-170;
            
            //それぞれ
            //上から落ちる物体の作成
            hunmer = new Hunmer(stage.stageWidth,groundLine);
            addChild(hunmer);
            //地面作成
            ground = new Ground(stage.stageWidth,170);
            addChild(ground);
            //スペースの作成
            space = new Space(interval,40);
            addChild(space);
            //キャラ
            player = new Player();
            addChild(player);
            //スコアの初期化
            score = new Score();
            addChild(score);
            
            //ハンマー&スペースの初期位置
            ground.y = groundLine;
            player.x = interval;
            player.y = groundLine;//※数値が他の要素そろう
            score.x  = groundLine+70;
            
            //プレイヤーのポジションを格納
            for(var i:int=1;i<solid;i++){
                positions.push(interval*i);
            }
           // _debug();
            
            next();
            
            _work = _down;
            //エンターフレーム
            addEventListener(Event.ENTER_FRAME,_enterFrame);
        }
        private function _debug():void {
            graphics.clear();
            graphics.lineStyle(1,0xFF0000);
            for each( var p:Number in positions ){
                graphics.moveTo(p,0);
                graphics.lineTo(p,stage.stageHeight);
                
            }
        }
        
        // _work を_up と _down で切り替える。
        private function _down():void{
            //下へ下ろす
            hunmer.y += speed;
            space.y  += speed;
            
            if( hunmer.y >= groundLine ){
                reverse();
                return;
            }
            
            //一番下へ付いたときにプレーヤーはスペースにいたら場合にokをtrueへ
            if( hunmer.y >= groundLine - 30 && ppos != space_pos ) {
                _end();
                return;
            }
        }
        private function _up():void {
            //一度下へ付いたかどうか
            if(hunmer.y < 0 ){
                next();
                return;
            }
        
            //上へ行くまで引き返す。
            hunmer.y -= speed*3;
            space.y  -= speed*3;
        }
        
        private function _enterFrame(event:Event):void{
            //マウスに一番近いポイントを算出しプレイヤーの現在一を決定
            //var i:int = Math.floor(mouseX/interval);
            //ppos = i;
            
            for(var i:int;i<solid-1;i++){
                if(Math.abs(positions[ppos]-mouseX)>Math.abs(positions[i]-mouseX)){
                    ppos=i;
                }
            }
            
            //プレイヤーを移動
            player.x = positions[ppos];
            
            _work();
        }
        
        private function next():void{
            //上についたら再び位置の決定
            //スコアの増加
            //スピードの増加
            //下へ付いたかどうかをfalseに
            hunmer.y   = 0;
            space.y    = 0;
            space_pos  = Math.floor(Math.random()*(solid-1));
            space.x    = space_pos*interval+interval/2;
            speed      += 0.3;
            
            score.point++;
            
            _work = _down;
        }
        private function reverse():void{
           _work = _up;
        }
        
        private function _end():void{
            //終わり
            removeEventListener(Event.ENTER_FRAME,_enterFrame);
            score.x=stage.stageWidth/2;
            score.y=stage.stageHeight/2;
            
            player.dead();
        }
    }
}

//_mmakeなんとか系をクラスに分離
import flash.display.*;
import flash.text.*;
class Space extends Shape{
    private var _w:int;
    private var _h:int;
    public function Space(w:int,h:int){
        _w = w;
        _h = h;
        draw();
    }
    public function draw():void{
        graphics.clear();
        graphics.lineStyle(1,0x999999);
        graphics.beginFill(0xffffff);
        graphics.drawRect(0,-_h,_w,_h);
        graphics.endFill();
        
        graphics.lineStyle(1,0xffffff);
        graphics.moveTo(0, 0);
        graphics.lineTo(_w, 0);
    }
}

class Hunmer extends Shape{
    private var _w:int;
    private var _h:int;
    public function Hunmer(w:int,h:int){
        _w = w;
        _h = h;
        draw();
    }
    public function draw():void{
        graphics.clear();
        graphics.lineStyle(1,0x999999);
        graphics.beginFill(0xf4f4f4);
        graphics.drawRect(0,-_h,_w,_h);
        graphics.endFill();
    
    }
}

class Ground extends Shape{
    private var _w:int;
    private var _h:int;
    public function Ground(w:int,h:int){
        _w = w;
        _h = h;
        draw();
    }
    public function draw():void{
        graphics.clear();
        graphics.lineStyle(1,0x999999);
        graphics.beginFill(0xf4f4f4);
        graphics.drawRect(0,0,_w,_h);
        graphics.endFill();
    
    }
}
class Player extends Sprite{
    private var _color:uint = 0x333333;
    public function Player(){
        draw();
    }
    public function draw():void{
        // ※足元に原点をもってくる(0,-30)
        graphics.clear();
        graphics.lineStyle(3,_color);
        graphics.drawCircle(0,0-30,5);
        //体
        graphics.moveTo(0,5-30);
        graphics.lineTo(0,20-30);
        //腕
        graphics.moveTo(-10,9-30);
        graphics.lineTo(10,9-30);
        //足
        graphics.moveTo(-10,30-30);
        graphics.lineTo(0,20-30);
        graphics.lineTo(10,30-30);
    }
    public function dead():void {
        _color = 0xFF0000;
        draw();
    }
}

class Score extends TextField{
    private var _point:int = 0;
    public function Score():void {
        draw();
    }
    public function set point (value:int):void {
        _point = 0;
        draw();
    }
    public function get point():int{ return _point; }
    public function draw():void{
        this.text = "score:"+String(_point);
    }
}