弾の速度・方向を決定

by aaaaaz025 forked from 弾を自然に消す? (diff: 10)
♥0 | Line 64 | Modified 2011-01-23 18:39:38 | MIT License
play

ActionScript3 source code

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

package
{
    import flash.display.AVM1Movie;
    import flash.display.Sprite;
    import flash.events.Event;
 
    public class Main extends Sprite
    {
        private var bullets:Array;
        private const MAX:int = 100; //省略化・上限       
 
        public function Main() 
        {            
            bullets = new Array();
            for (var i:int = 0; i < MAX; i++) //100の弾種を管理
            {
                var bullet:Bullet = new Bullet(0x0, 10, 232, 232);
                addChild(bullet);
                bullets.push(bullet);
            }
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
                        
         
        private function onEnterFrame(event:Event):void
        {
            for (var i:int = 0; i < bullets.length; i++)
            {
                bullets[i].move();
                if (bullets[i].check())
                {
                        removeChild(bullets[i]);
                        bullets.splice(i--, 1);
                        }
                      
                        
                        

            }
        }
    }
}

import flash.display.Sprite;
 
class Bullet extends Sprite
{
    public var vx:Number;
    public var vy:Number;
    
    public function Bullet(color:int, radius:int, x:int, y:int)
    {
        graphics.beginFill(color);
        graphics.drawCircle(0, 0, radius);
        graphics.endFill();
 
        this.x = x;
        this.y = y;
        this.vx = vx;
        this.vy = vy;

    }
 
    public function move():void
    {
        this.x += 3;
        this.y += 9;
    }
    
    public function out():Boolean
    {
        if (x < -50 || stage.stageWidth  + 50 < x ||
            y < -50 || stage.stageHeight + 50 < y)
        {
            return true;
        }
 
        return false;
    }
}