ぱーてぃくる
// write as3 code here..
package {
import flash.display.*;
import flash.events.*;
import flash.geom.*;
public class BulletDemo extends Sprite {
private var SPEED_FO:Number = 0.8;
private var canvas_bd:BitmapData;
private var ctf:ColorTransform;
private var temp:Sprite;
public function BulletDemo () {
addEventListener( Event.ADDED_TO_STAGE, added );
}
private function added( e:Event ):void {
if ( e.target == this ) {
removeEventListener( e.type, arguments.callee );
setup();
}
}
private function setup():void {
canvas_bd = new BitmapData( stage.stageWidth, stage.stageHeight, false, 0x000000 );
addChild( new Bitmap( canvas_bd ) );
ctf = new ColorTransform( SPEED_FO, SPEED_FO, SPEED_FO, 1.0 );
temp = new Sprite();
addEventListener( Event.ENTER_FRAME, update, false, 10 );
}
private function update( e:Event ):void {
for ( var i:int = 0; i < 3; ++i ) {
fire();
}
canvas_bd.unlock();
canvas_bd.lock();
canvas_bd.colorTransform( canvas_bd.rect, ctf );
}
private function fire():void {
var x:Number = stage.stageWidth / 2;
var y:Number = stage.stageHeight / 2;
var v:Number = 3*Math.random();
var a:Number = 0.1;
var r:Number = 2*Math.PI * Math.random();
var vx:Number = v * Math.cos( r );
var vy:Number = v * Math.sin( r );
var vr:Number = 0.03;
var size:Number = 1 + 4*Math.random();
var color:uint = 0xffffff * Math.random();
var mtx:Matrix = new Matrix();
var bullet:Sprite = new Sprite();
bullet.graphics.beginFill( color );
bullet.graphics.drawCircle( 0, 0, size );
bullet.graphics.endFill();
temp.addChild( bullet );
bullet.addEventListener( Event.ENTER_FRAME, function( e:Event ):void {
v += a;
r += vr;
vx = v * Math.cos( r );
vy = v * Math.sin( r );
x += vx;
y += vy;
mtx.tx = x;
mtx.ty = y;
canvas_bd.draw( bullet, mtx );
if ( canvas_bd.rect.contains( x, y ) == false ) {
bullet.removeEventListener( e.type, arguments.callee );
bullet.graphics.clear();
temp.removeChild( bullet );
bullet = null;
}
}, false, 1 );
}
}
}