In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

[INFINITY TANK BATTLE] FIRE BULLET

@author Takashi Murai(KAYAC)
Get Adobe Flash player
by Murai 22 Oct 2009
    Embed
/**
 * Copyright Murai ( http://wonderfl.net/user/Murai )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/jRo3
 */

package {
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.geom.*;

	import net.wonderfl.game.infinity_tank.development.*;

	/*
	   @author Takashi Murai(KAYAC)
	 */
	[SWF( width="465", height="465", backgroundColor="0x000000", frameRate="30" )]

	public class BulletRenderer extends BulletRendererBase {

		private var _bulletPt:Point
		private var _ctfFader:ColorTransform

		private var fire:Fire

		public function BulletRenderer() {
			_ctfFader = new ColorTransform( 1, 1, 1, 0 );
			_bulletPt = new Point();

			fire = new Fire();
		}

		override public function draw( $bitmapData:BitmapData ):void {

			$bitmapData.lock();

			$bitmapData.colorTransform( $bitmapData.rect, _ctfFader );

			var bmd:BitmapData
			var m:Matrix = new Matrix()

			// myBulletListが自分の弾のリスト。このようにfor文で回す
			for ( var i:BoundBox = _scene.myBulletList; i; i = i.next ) {
				bmd = fire.getBMD();
				m.identity();
				m.translate( -bmd.width / 2, -bmd.height / 2 );
				m.rotate( i.rotation );
				m.translate( i.position.x, i.position.y );

				$bitmapData.draw( bmd, m, null, null, null, true );

			}
			$bitmapData.unlock();
		}
	}
}

import flash.display.*;
import flash.events.*;
import flash.filters.*;
import flash.geom.*;

internal class Fire extends Sprite {
	private const FADE:Number = 0.2;
	private const SCALE:Number = 0.35;
	private const DISTORTION:Number = 0.7;
	private const AMOUNT:Number = 0.45;
	private const SPREAD:Number = 0.6;
	private const SMOKE:Number = 0.9;

	private var src:*
	private var canvas:Bitmap
	private var main_bmp:BitmapData;
	private var tmp_bmp:BitmapData;
	private var perlin_bmp:BitmapData;

	private var _matrix:Matrix;
	private var _Pt:Point;
	private var _ctf:ColorTransform;
	private var _cmf:ColorMatrixFilter;
	private var _dmf:DisplacementMapFilter;
	private var _blur:BlurFilter;

	private var _target:DisplayObject;

	private var originalW:Number
	private var originalH:Number

	public function Fire( _src:DisplayObject = null ) {
		if ( !_src ) {
			src = new Sprite();
			src.graphics.beginFill( 0xFFFFFF, 1 );
			src.graphics.drawEllipse( 0, 0, 30, 15 )
			src.graphics.endFill();
		} else {
			src = _src
		}

		canvas = new Bitmap()
		_target = src;

		_matrix = new Matrix();
		_Pt = new Point();

		init()
		start();
	}

	public function getBMD():BitmapData {
		return this.canvas.bitmapData
	}

	private function start():void {
		addEventListener( Event.ENTER_FRAME, burn );
	}

	private function init():void {
		if ( main_bmp ) {
			main_bmp.dispose();
			main_bmp = null;
			tmp_bmp.dispose();
			tmp_bmp = null;
			perlin_bmp.dispose();
			perlin_bmp = null;
		}

		originalW = _target.width
		originalH = _target.height

		var w:Number = originalW * 6;
		var h:Number = originalH * 6;

		main_bmp = new BitmapData( w, h, true, 0 );
		tmp_bmp = main_bmp.clone();
		perlin_bmp = new BitmapData( w * 3, h * 3, false, 0 );
		canvas.bitmapData = main_bmp;

		perlin_bmp.perlinNoise( 30 * SCALE, 20 * SCALE, 1, -Math.random() * 1000 | 0, false, true, 1 | 2, false );
		perlin_bmp.colorTransform( perlin_bmp.rect, new ColorTransform( 1, 1 - AMOUNT * 0.5, 1, 1, 0, 0, 0, 0 ));

		_cmf = new ColorMatrixFilter([ 0.96-0.35*FADE,0.1,0,0,-1,   0,0.9-0.45*FADE,0,0,0,   0,0,0.8-0.55*FADE,0,0,   0,0.1,0,1,-25+SMOKE*24 ]);
		_ctf = new ColorTransform( 0, 0, 0, 1, 255, 255, 210, 0 );
		_dmf = new DisplacementMapFilter( perlin_bmp, _Pt, 2, 1, -30, 14 * DISTORTION, DisplacementMapFilterMode.CLAMP );
		_blur = new BlurFilter( 32 * SPREAD, 32 * SPREAD, 1 );
	}

	private function burn( e:Event ):void {

		var dM:Matrix = _target.transform.matrix;
		dM.tx = originalW * 6 / 2 - originalW / 2
		dM.ty = originalH * 6 / 2 - originalH / 2

		tmp_bmp.fillRect( tmp_bmp.rect, 0 );
		_ctf.alphaOffset = -Math.random() * 200 | 0;
		tmp_bmp.draw( _target, dM, _ctf, BlendMode.ADD );
		tmp_bmp.applyFilter( tmp_bmp, tmp_bmp.rect, _Pt, _blur );
		main_bmp.draw( tmp_bmp, _matrix, null, BlendMode.ADD );

		_dmf.mapPoint = new Point( -Math.random() * ( perlin_bmp.width - main_bmp.width ) | 0, -Math.random() * ( perlin_bmp.height - main_bmp.height ) | 0 );
		main_bmp.applyFilter( main_bmp, main_bmp.rect, _Pt, _dmf );
		main_bmp.applyFilter( main_bmp, main_bmp.rect, _Pt, _cmf );

	}
}