ホーミング弾

by aaaaaz025 forked from flash on 2010-4-13 (diff: 2)
♥0 | Line 72 | Modified 2011-01-24 00:38:42 | 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/q3iP
 */

package
{
    import flash.display.Sprite;
    import flash.events.Event;
 
    public class Main extends Sprite
    {
        private var bullets:Array;
        private var frame:int = 0;
 
        public function Main()
        {
            bullets = new Array();
 
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
 
        private function onEnterFrame(event:Event):void
        {
            if (frame++ % 10 == 0)
            {
                var radian:Number = Math.atan2(mouseY - 232, mouseX - 232);
                var bullet:Bullet = new Bullet(200, 50, 232, 50, Math.cos(radian), Math.sin(radian), 5 + 5);
                addChild(bullet);
                bullets.push(bullet);
            }
 
            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;
import flash.filters.DropShadowFilter;
 
class Bullet extends Sprite
{
    public var px:Number;
    public var py:Number;
    public var vx:Number;
    public var vy:Number;
    public var speed:Number;
 
    public function Bullet(color:int, radius:int, x:int, y:int, vx:Number, vy:Number, speed:Number)
    {
        graphics.beginFill(color);
        graphics.drawCircle(0, 0, radius);
        graphics.endFill();
 
        this.filters = [new DropShadowFilter(2, 0, 0x0)];
 
        this.x = this.px = x;
        this.y = this.py = y;
        this.vx = vx;
        this.vy = vy;
        this.speed = speed;
    }
 
    public function move():void
    {    
        this.px += vx * speed;
        this.py += vy * speed;
 
        this.x = px;
        this.y = py;
    }
 
    public function check():Boolean
    {
        if (x < -50 || stage.stageWidth  + 50 < x ||
            y < -50 || stage.stageHeight + 50 < y)
        {
            return true;
        }
 
        return false;
    }
}

Forked