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

flash on 2011-6-1

Get Adobe Flash player
by hacker_cobulht0 01 Jun 2011
    Embed
//むかしかいたもの発掘
package {
import flash.display.Sprite
import flash.events.MouseEvent
import flash.events.Event
import flash.text.*;
import flash.geom.*;
[SWF(width = "465", height = "465", backgroundColor = 0xF2F2BB, frameRate = "30")]
public class Breakout extends Sprite {
    private const SPEED:int = 2; 
    
    private const _LEFT:int = 130; 
    private const _RIGHT:int = 330; 
    private const _UE:int = 130; 
    private const _SITA:int = 330;
    
    private const _LEFTbar:int = 150;
    private const _RIGHTbar:int = 312;
    
    private var mcBar:Sprite;
    private const maxBlock:uint = 12; 
    private var arrayBlock:Array=new Array();
    private var mcBall:Sprite;    
    private var mcMask:Sprite;    
    
    private var arrayLife:Array=new Array();
    private var ckLife:uint=0;
    private var cntLife:uint=0;
    private const maxLife:uint = 3; 
    
    private var xx:int=0;
    private var yy:int=1;
    
    function Breakout() {
        init();
    }
    private function init() {
        //背景----------------------------------------------------------------------------------------------------
            var bg:back_ground=new back_ground();
            addChildAt(bg,0);
        //----------------------------------------------------------------------------------------------------
        ckLife=1;
        funcMask();
        funcBar();
        funcBlock();
        funcBall();
        funcLife();
    }    
    //下準備--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    private function funcMask(){
        var arr:Array=[0x076571,0x018496,0x0AAA92];
        mcMask=new Sprite();
        for (var j:int=0; j <30; j++){
            mcMask.graphics.beginFill(arr[Math.floor(j%3)]);
            mcMask.graphics.drawRect(0,j*10,210,10);
            mcMask.graphics.endFill();
        }        
        mcMask.y=127;
        mcMask.x=127;
    };
    private function funcBar(){
        mcBar=new Sprite();
        mcBar.graphics.beginFill(0xF0F0B0,1);
        mcBar.graphics.drawRoundRect(0,0,50,12,5);
        mcBar.y=310;
        mcBar.x=127;
        addChild(mcBar);
        stage.addEventListener(MouseEvent.MOUSE_MOVE, function(e){
            if((_LEFTbar<mouseX)&&(mouseX<_RIGHTbar)){mcBar.x=mouseX-25;}
        });
        stage.addEventListener(MouseEvent.MOUSE_UP, function(e){
            if(ckLife==1){ckLife=0;}
        });
    }
    private function funcBlock(){
        for (var j:int=0; j <maxBlock; j++){        
            var mcBlock:Sprite=new Sprite();
            mcBlock.graphics.beginFill(0xF0F0B0,1);
            mcBlock.graphics.drawRoundRect(0,0,50,12,5);
            mcBlock.y=160+Math.floor(j/3)*18;
            mcBlock.x=150+j%3*60;
            mcBlock.name="bc"+j;
            arrayBlock.push(mcBlock);
            addChild(mcBlock);
        }
    }
    private function funcLife(){
        for (var j:int=0; j <maxLife; j++){        
            var mcLife:drawHeart=new drawHeart(j);
            mcLife.y=130+15;
            mcLife.x=280+j*16;
            arrayLife.push(mcLife);
            addChild(mcLife);
        }
    }
    private function funcBall(){
        mcBall=new Sprite();
        mcBall.graphics.beginFill(0xF0F0B0,1);
        mcBall.graphics.drawCircle(0,0,5);
        mcBall.y=300;
        mcBall.x=mcBar.x+25;
        addChild(mcMask);
        addChild(mcBall);
        mcMask.mask=mcBall;
    
        mcBall.addEventListener(Event.ENTER_FRAME, function(e){
            if(ckLife==0){
            ckWall();ckBar();ckBlock();
            mcBall.y+=(yy*SPEED);
            mcBall.x+=(xx*SPEED);
            }
            if(ckLife==1){
            mcBall.visible=false;
            mcBall.y=300;
            mcBall.x=mcBar.x+25;
            }
            if(ckLife==2){
            mcBall.y=mcBall.x=-10;
            }
        });        
    }
    //衝突判定--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    private function ckWall(){
        if(mcBall.y<_UE){yy=1;}
        else if(mcBall.y>_SITA){damage();}
        else if(mcBall.x<_LEFT){xx=1;}
        else if(mcBall.x>_RIGHT){xx=-1;}
    }
    private function ckBar(){
        if(mcBall.y>310&&mcBall.x>mcBar.x&&mcBall.x<mcBar.x+50){
            yy=-1;
            if(mcBall.x>mcBar.x+12){xx=-0.8;
                if(mcBall.x>mcBar.x+24){xx=0.8;
                    if(mcBall.x>mcBar.x+36){xx=1;}
                    }
            }
            else{xx=-1;}
        }
    }
    private function ckBlock(){
        for (var j:int=0; j <arrayBlock.length; j++){
            var bc=arrayBlock[j];
            if(bc.hitTestObject(mcBall)){
                if(mcBall.y>bc.y){yy=1;}else{yy=-1;}                
                if(mcBall.x>bc.x+12){xx=0.8;
                    if(mcBall.x>bc.x+24){xx=-0.8;
                        if(mcBall.x>bc.x+36){xx=-1;}
                    }
                }else{xx=1;}
                bc.visible=false;
                arrayBlock.splice(j,1);
                if(arrayBlock.length<1){ckMessage("Congratulations!!");}
            }
        }
    }
    //Life--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    private function ckMessage(arg:String){        
            //テキストフォーマット作成                
            var fmt:TextFormat = new TextFormat();
            fmt.align="center";
            fmt.size  = 20;
            fmt.color = 0x0AAA92;//84AF97
            fmt.font="Impact";
            //テキストフィールド作成
            var tf:TextField = new TextField();
            tf.defaultTextFormat = fmt;
            tf.text = arg;
            tf.selectable = false;
            tf.width=210;
            tf.x=125;
            tf.y=215;
            addChild(tf);
            ckLife=2;
    }
    private function damage(){        
        if(cntLife!=maxLife){
        arrayLife[cntLife].alpha=0;
        ckLife=1;
        cntLife++;
        }else{            
            ckMessage("GameOver...");
        }        
    }

}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import flash.display.Sprite;
class back_ground extends Sprite{
public function back_ground(){
    var bg:Sprite=new Sprite();
    bg.graphics.beginFill(0xF2F2BB,1);
    bg.graphics.drawRect(0,0,465,465);
    bg.graphics.endFill();
    bg.graphics.beginFill(0xE1E79F,1);
    bg.graphics.drawRect(127,127,210,42);
    bg.graphics.endFill();
    bg.graphics.beginFill(0xD3E4A2,1);
    bg.graphics.drawRect(127,169,210,42);
    bg.graphics.endFill();
    bg.graphics.beginFill(0xC9E2A5,1);
    bg.graphics.drawRect(127,211,210,42);
    bg.graphics.endFill();
    bg.graphics.beginFill(0xBCDEAC,1);
    bg.graphics.drawRect(127,253,210,42);
    bg.graphics.endFill();
    bg.graphics.beginFill(0xADDFAE,1);
    bg.graphics.drawRect(127,295,210,42);
    bg.graphics.endFill();
    addChild(bg);
}
}
class drawHeart extends Sprite{
public function drawHeart(arg:int){
    var arrCL:Array=[0x076571,0x018496,0x0AAA92];
    var arr:Array=[150,-150];
            for(var j:int=0; j < 2; j++){
                    var _sp:Sprite = new Sprite();                    
                    _sp.graphics.beginFill(arrCL[arg]);
                    _sp.graphics.drawEllipse(-2,-1,4,10);                    
                    _sp.graphics.endFill();                        
                    _sp.rotation=arr[j];
                    addChild(_sp);
            }        
    }
}