RemoveBall

by s1190133
画面に現れたボールをひたすらクリックして消していくゲームです。
今のところ全部消し終えてもなにも起こりません。
♥0 | Line 76 | Modified 2011-12-04 21:01:07 | MIT License
play

ActionScript3 source code

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

//画面に現れたボールをひたすらクリックして消していくゲーム
//今のところ全部消し終えてもなにも起こりません。のちのち改良予定。
package
{
    import flash.filters.GlowFilter;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.events.MouseEvent;
    
    import mx.events.ModuleEvent;
    
    [SWF (backgroundColor="0x00000",width=512,height=512)]
    public class test01 extends Sprite
    {
        public var arr:Array=[];
        public var ball:Ball;
        private var sp_glow:Sprite=new Sprite;
        
        public function test01()
        {
            stage.scaleMode=StageScaleMode.NO_SCALE;
            stage.align=StageAlign.TOP_LEFT;
            
            for(var i:int=0;i<20;i++){
                ball=new Ball;
                //配列に入れとく
                arr[i]=ball;
                
                //ぼーるの最初の位置
                ball.x+=stage.stageWidth*Math.random();
                ball.y+=stage.stageHeight*Math.random();
                
                addChild(ball);
            }
            addEventListener(Event.ENTER_FRAME,onEnterFrame);
            stage.addEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
            stage.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
        }
        private function onEnterFrame(e:Event):void{
            for(var i:int=0;i<20;i++){
                //ここで速度足す
                arr[i].x+=arr[i].vx;
                arr[i].y+=arr[i].vy;
                
                if(arr[i].x-arr[i].r<0){
                    arr[i].x=arr[i].r;
                    arr[i].vx*=-1;
                }else if(arr[i].x+arr[i].r>stage.stageWidth){
                    arr[i].x=stage.stageWidth-arr[i].r;
                    arr[i].vx*=-1;
                }else if(arr[i].y-arr[i].r<0){
                    arr[i].y=arr[i].r;
                    arr[i].vy*=-1;
                }else if(arr[i].y+arr[i].r>stage.stageHeight){
                    arr[i].y=stage.stageHeight-arr[i].r;
                    arr[i].vy*=-1;
                }
            }
        }
        private function onMouseOver(e:MouseEvent):void{
            for(var i:int=0;i<20;i++){
                if(e.target==arr[i]){
                    sp_glow.filters=[new GlowFilter()];
                }
            }

        } 
        private function onMouseDown(e:MouseEvent):void{
            for(var i:int=0;i<20;i++){
                if(e.target==arr[i]){
                    removeChild(arr[i]);
                }
            }
        }
    }
}

import flash.display.Sprite;

class Ball extends Sprite{
    public var vx:Number=10*Math.random()+(-10)*Math.random();
    public var vy:Number=10*Math.random()+(-10)*Math.random();
    public var r:int=20*Math.random()+15;
    
    public function Ball(){
        graphics.beginFill(0xFFFFFF*Math.random(),0.6);
        graphics.drawCircle(0,0,r);
        graphics.endFill();
    }
}