green

by Scmiz
♥0 | Line 93 | Modified 2011-04-30 21:21:52 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
	import flash.events.Event;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            this.graphics.beginFill(0x000000);
			this.graphics.drawRect(0, 0, 465, 465);
			this.graphics.endFill();
			
			
			for (var i:uint = 0; i < 20; ++i) {
				if (i % 2 == 1) continue;
				this.graphics.lineStyle(1, Constant.COLOR, 1.0 - (i * 0.025));
				this.graphics.drawRect(Constant.L - i, Constant.U - i, Constant.WIDTH + (i * 2), Constant.HEIGHT + (i * 2));
			}
			
			var array:Array = new Array();
			for (var index:uint = 0; index < 200; ++index) {
				var b:Bullet = new Bullet();
				b.x = Math.random() * Constant.WIDTH + Constant.L;
				b.y = Math.random() * Constant.HEIGHT + Constant.U;
				
				var rad:Number = Math.PI * 2 * Math.random();
				var speed:Number = 4.0;
				b.setSpeed(Math.cos(rad) * speed, Math.sin(rad) * speed);
				this.addChild(b);
				array.push(b);
			}
			
			var proc:Function = function(e:Event):void {
				for each (var bullet:Bullet in array) {
					bullet.update();
				}
			}
			this.addEventListener(Event.ENTER_FRAME, proc);
        }
    }
}
import flash.display.Sprite;
import flash.geom.Point;

class Constant {
	static public const COLOR:uint = 0x00ff00;
	
	static public const L:uint = 32.5;
	static public const R:uint = 465 - L;
	static public const U:uint = L;
	static public const B:uint = R;
	
	static public const WIDTH:uint = R - L;
	static public const HEIGHT:uint = B - U;	
}

class Bullet extends Sprite {
	private var _speedX:Number = 0.0;
	private var _speedY:Number = 0.0;
	private var _prevPos:Array = new Array();
	
	public function Bullet() {
	}
	
	public function setSpeed(x:Number, y:Number):void {
		_speedX = x;
		_speedY = y;
	}
	
	public function update():void {
		var rate:Number = 1.0001;
		_speedX *= rate;
		_speedY *= rate;
		
		var max:Number = 8.0;
		if (_speedX > max) _speedX = max;
		if (_speedX < -max) _speedX = -max;
		if (_speedY > max) _speedY = max;
		if (_speedY < -max) _speedY = -max;
		
		this.x += _speedX;
		this.y += _speedY;
		
		if (this.x < Constant.L) {
			this.x = Constant.L;
			_speedX *= -1;
		}
		if (this.x > Constant.R) {
			this.x = Constant.R;
			_speedX *= -1;
		}
		if (this.y < Constant.U) {
			this.y = Constant.U;
			_speedY *= -1;
		}
		if (this.y > Constant.B) {
			this.y = Constant.B;
			_speedY *= -1;
		}
		
		_prevPos.push(new Point(this.x, this.y));
		if (_prevPos.length > 8) {
			_prevPos.splice(0, 1);
		}
		
		this.graphics.clear();
		for (var index:uint = 0; index < _prevPos.length; ++index) {
			this.graphics.beginFill(Constant.COLOR, 1.0 - ((_prevPos.length - index) * 0.1));
			this.graphics.drawCircle(_prevPos[index].x - this.x, _prevPos[index].y - this.y, 1);
			this.graphics.endFill();
		}
	}
}