flash on 2012-3-19
/**
* Copyright MMMMMonchi ( http://wonderfl.net/user/MMMMMonchi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/xaNd
*/
package
{
import flash.display.Sprite;
import flash.events.Event;
[SWF(frameRate=100)]
public class Main extends Sprite
{
private var bullets:Array;
private var frame:int = 0;
private var degree:int = 0;
public function Main()
{
bullets = new Array();
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void
{
if (frame++ % 0.5== 0)
{
var bullet:Bullet = new Bullet(0x0, 3, 232, 232, Math.cos(degree * Math.PI / 180), Math.sin(degree * Math.PI / 180));
addChild(bullet);
bullets.push(bullet);
degree += 2;
}
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
{
private var _x:Number = 0;
private var _y:Number = 0;
public var vx:Number;
public var vy:Number;
override public function get x():Number { return _x; }
override public function get y():Number { return _y; }
override public function set x(value:Number):void
{
super.x = _x = value;
}
override public function set y(value:Number):void
{
super.y = _y = value;
}
public function Bullet(color:int, radius:int, x:int, y:int, vx:Number, vy:Number)
{
graphics.beginFill(color);
graphics.drawCircle(0, 0, radius);
graphics.endFill();
this.filters = [new DropShadowFilter(2, 0, 0x0)];
this.x = x;
this.y = y;
this.vx = vx;
this.vy = vy;
}
public function move():void
{
this.x += vx;
this.y += vy;
if(this.x<0||this.x>=stage.stageWidth){vx=-vx}
if(this.y<0||this.y>=stage.stageHeight){vy=-vy}
}
public function check():Boolean
{
if (x < -50 || stage.stageWidth + 50 < x ||
y < -50 || stage.stageHeight + 50 < y)
{
return true;
}
return false;
}
}