flash on 2010-4-13

by kihon
♥0 | Line 63 | Modified 2010-04-13 22:59:57 | MIT License
play

ActionScript3 source code

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

package
{
	import flash.display.Sprite;
	import flash.events.Event;
 
	public class Main extends Sprite
	{
		private var bullets:Array;
 
		public function Main()
		{
			bullets = new Array();
			var bullet:Bullet = new Bullet(0x0, 5, 232, 232, Math.cos(45 * Math.PI / 180), Math.sin(45 * Math.PI / 180));
			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 px:Number;
	public var py:Number;
	public var vx:Number;
	public var vy:Number;
 
	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.x = this.px = x;
		this.y = this.py = y;
		this.vx = vx;
		this.vy = vy;
	}
 
	public function move():void
	{	
		this.px += vx;
		this.py += vy;
 
		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;
	}
}