flash on 2012-3-19

by MMMMMonchi
♥0 | Line 60 | Modified 2012-03-19 16:55:23 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import net.hires.debug.Stats;
    [SWF(frameRate="60")]
    public class Main extends Sprite {
        public var bullets:Array;
        private const MAX:int=400;   
        public function Main() {
           addChild(new Stats());
            bullets=new Array();
            for(var i:int=0;i<MAX;i++){
                bullets.push(new Ball(Math.random()*100000000, Math.random()*30, 250,250,Math.random()*10-5,Math.random()*10-5))
                addChild(bullets[i])
                }
            addEventListener(Event.ENTER_FRAME,onEnterFrame);           
            
        }
        public function onEnterFrame(e:Event):void{
            for(var i:int=0;i<MAX;i++){
            bullets[i].move();
            if (bullets[i].check())
        {
            removeChild(bullets[i]);
            bullets.splice(i--, 1);
        }
            }
             
            }
        
    }
    
}
import flash.display.Sprite;

class Ball extends Sprite{
    public var vx:Number;
    public var vy:Number;
    public var radius:int;
     public function Ball(color:uint,radius:int,x:int,y:int,vx:Number,vy:Number){
         graphics.beginFill(color);
         graphics.drawCircle(0,0,radius);
         graphics.endFill();
         this.x=x;
         this.y=y;
         this.vx=vx;
         this.vy=vy;
         this.radius=radius;
         
         }   
    public function move():void{
        this.x+=vx;
        this.y+=vy;
        if(this.x<radius||this.x>=stage.stageWidth-radius){vx=-vx};
         if(this.y<radius||this.y>=stage.stageHeight-radius){vy=-vy};
        }
    public function check():Boolean
    {
        if (x < -50 || stage.stageWidth+10< x ||
            y < -50 || stage.stageHeight+10< y)
        {
            return true;
        }
 
        return false;
    }
    }

Forked