Beautifl - Flash Gallery

Thumbnail : 虫姫さまのアレ
虫姫さまのアレ
nemu90kWw 2009-08-30 All rights reserved

再生するにはFlash Playerが必要です。デスクトップのブラウザでご覧ください。

package
{
	import flash.geom.*;
	import flash.display.*;
	import flash.events.*;
	import net.hires.debug.Stats;
	
	[SWF(width="465", height="465", backgroundColor="#405070", frameRate="60")]
	public class Aki extends Sprite
	{
		public function getVectorX(dir:Number, speed:Number):Number {return -Math.cos(Math.PI/128*(dir+64))*speed;}
		public function getVectorY(dir:Number, speed:Number):Number {return Math.sin(Math.PI/128*(dir+64))*speed;}
		
		private var num:Number = 100;
		private var shotlist:Vector.<Shot> = new Vector.<Shot>();
		private function shot(dir:Number, speed:Number, x:Number, y:Number):Shot
		{
			var fire:Shot = new Shot(x, y, getVectorX(dir, speed), getVectorY(dir, speed), dir);
			shotlist.push(fire);
			
			num++;
			return fire;
		}
		
		private var cnt:Number = 0;
		private var uchu_x:Number = 360/2;
		private var uchu_y:Number = 128;
		private var uchu_size:Number = 112;
		private var uchu_rot:Number = -0.8;
		private var uchu_maru:Array = new Array();
		
		private var buffer:BitmapData = new BitmapData(360, 420, false, 0);
		private var screen:Bitmap = new Bitmap(buffer);
		
		public function Aki()
		{
			stage.quality = StageQuality.HIGH;
			Shot.standby();
			Maru.standby();
			stage.quality = StageQuality.LOW;
			screen.x = 52;
			screen.y = 22;
			
			for(var i:int = 1; i <= 32; i++) {
				uchu_maru[i] = new Maru();
			}
			
			addChild(screen);
			addChild(new Stats());
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		
		public function onEnterFrame(event:Event):void
		{
			var i:int;
			var d:Number, bx:Number, by:Number;
			
			if(cnt % 260 == 259)
			{
				uchu_x = 360/2-40+Math.random()*80;
				uchu_y = 128;
				uchu_size = 112;
				uchu_rot = -0.8;
				
				for(i = 1; i <= 32; i++)
				{
					uchu_maru[i].alpha = 1;
					uchu_maru[i].visible = true;
				}
			}
			
			if(cnt % 260 < 80) {
				uchu_size = uchu_size-1.1;
			}
			else if(cnt % 260 < 128) {
				uchu_y = uchu_y + 1.2;
				uchu_size = uchu_size-0.5;
			}
			else if(cnt % 260 < 155) {
				uchu_y = uchu_y + 0.8;
			}
			else {
				uchu_size = uchu_size+1.25;
			}
			
			uchu_rot = uchu_rot-1.8;
			
			for(i = 1; i <= 32; i++)
			{
				d = i*(256/32)+uchu_rot;
				uchu_maru[i].x = uchu_x+getVectorX(d, uchu_size);
				uchu_maru[i].y = uchu_y+getVectorY(d, uchu_size/1.5);
			}
			
			if( (cnt % 260 > 15)&&(cnt % 260 < 255) )
			{
				if(cnt % 8 == 0)
				{
					for(i = 1; i <= 32; i++)
					{
						d = i*(256/32)+uchu_rot;
						bx = uchu_x+getVectorX(d, uchu_size);
						by = uchu_y+getVectorY(d, uchu_size/1.5);
						
						shot(d, 3.2, bx, by);
						shot(d+74.5, 3.2, bx, by);
						shot(d-74.5, 3.2, bx, by);
					}
				}
				
				if(cnt % 8 == 4)
				{
					for(i = 1; i <= 32; i++)
					{
						d = i*(256/32)+uchu_rot;
						bx = uchu_x+getVectorX(d, uchu_size);
						by = uchu_y+getVectorY(d, uchu_size/1.5);
						
						shot(d+101.5, 3.2, bx, by);
						shot(d-101.5, 3.2, bx, by);
					}
				}
				
				for(i = 1; i <= 32; i++) {
					uchu_maru[i].alpha -= 0.002;
				}
			}
			
			if(cnt % 260 == 255) {
				for(i = 1; i <= 32; i++) {
					uchu_maru[i].visible = false;
				}
			}
			
			run();
			cnt++;
		}
		
		public function run():void
		{
			buffer.fillRect(buffer.rect, 0x203050);
			
			for each(var maru:Maru in uchu_maru)
			{
				maru.draw(buffer);
			}
			
			for(var i:int = 0; i < shotlist.length; i++)
			{
				shotlist[i].main();
				shotlist[i].draw(buffer);
				
				if(shotlist[i].endflag == true) {
					shotlist.splice(i, 1); i--;
				}
			}
		}
	}
}

import flash.geom.*;
import flash.display.*;

class DisplayImage
{
	public var bmp:BitmapData;
	public var rect:Rectangle;
	public var cx:int;
	public var cy:int;
	
	public function DisplayImage(bmp:BitmapData, cx:int = 0, cy:int = 0)
	{
		this.bmp = bmp;
		this.rect = bmp.rect;
		this.cx = cx;
		this.cy = cy;
		
		trimming();
	}
	
	private function trimming():void
	{
		/*
		var x:int, y:int;
		var dx:int = 0, dy:int = 0, dw:int = bmp.width, dh:int = bmp.height;
		
		left: for(x = 0; x < bmp.width; x++) {
			for(y = 0; y < bmp.height; y++) {
				if(bmp.getPixel32(x, y) != 0x00000000) {break left;}
			}
			dx++;
			cx--;
		}
		right: for(x = bmp.width-1; x > 0; x--) {
			for(y = 0; y < bmp.height; y++) {
				if(bmp.getPixel32(x, y) != 0x00000000) {break right;}
			}
			dw--;
		}
		top: for(y = 0; y < bmp.height; y++) {
			for(x = 0; x < bmp.width; x++) {
				if(bmp.getPixel32(x, y) != 0x00000000) {break top;}
			}
			dy++;
			cy--;
		}
		bottom: for(y = bmp.height-1; y > 0; y--) {
			for(x = 0; x < bmp.width; x++) {
				if(bmp.getPixel32(x, y) != 0x00000000) {break bottom;}
			}
			dh--;
		}
		
		var temp:BitmapData = new BitmapData(dw, dh, true, 0x00000000);
		temp.copyPixels(bmp, new Rectangle(dx, dy, dw-dx, dh-dy), new Point(0, 0));
		bmp = temp;
		*/
		var rect:Rectangle = bmp.getColorBoundsRect(0xFF000000, 0x00000000);
		var temp:BitmapData = new BitmapData(rect.width, rect.height, true, 0x00000000);
		
		cx -= rect.x;
		cy -= rect.y;
		
		temp.copyPixels(bmp, rect, new Point(0, 0));
		bmp = temp;
		return;
	}
	
	public function clone():DisplayImage
	{
		return new DisplayImage(bmp.clone(), cx, cy);
	}
}

class ObjBase
{
	public var x:Number = 0;
	public var y:Number = 0;
	public var vx:Number = 0;
	public var vy:Number = 0;
}

class Shot extends ObjBase
{
	static private var cell:Vector.<Vector.<DisplayImage>> = new Vector.<Vector.<DisplayImage>>(256, true);
	private var anime:int = 0;
	private var pos:Point = new Point();
	public var dir:uint = 0;
	public var endflag:Boolean = false;
	
	public static function standby():void
	{
		var temp:Shape = new Shape();
		temp.graphics.beginFill(0xFFFFF0);
		temp.graphics.lineStyle(1, 0xC05090, 1);
		temp.graphics.drawPath(Vector.<int>([1,2,2,2,2]), Vector.<Number>([8, 1, 10, 10, 8, 14, 6, 10, 8, 1]));
		temp.graphics.endFill();
		
		var matrix:Matrix = new Matrix();
		for(var i:int = 0; i < 256; i++)
		{
			var bmp:BitmapData = new BitmapData(16, 16, true, 0);
			bmp.draw(temp, matrix);
			
			cell[i] = new Vector.<DisplayImage>(3, true);
			cell[i][0] = new DisplayImage(bmp, 8, 8);
			cell[i][1] = cell[i][0].clone();
			cell[i][2] = cell[i][0].clone();
			
			cell[i][0].bmp.colorTransform(cell[i][0].rect, new ColorTransform(1, 1, 1, 1, 48, 48, 48, 0));
			cell[i][2].bmp.colorTransform(cell[i][2].rect, new ColorTransform(1, 1, 1, 1, -24, -48, 0, 0));
			
			matrix.translate(-8, -8);
			matrix.rotate(-Math.PI/128);
			matrix.translate(8, 8);
		}
	}
	
	public function Shot(x:Number, y:Number, vx:Number, vy:Number, dir:Number)
	{
		this.x = x;
		this.y = y;
		this.vx = vx;
		this.vy = vy;
		this.dir = uint(dir)%256;
	}
	
	public function main():void
	{
		x += vx;
		y += vy;
		
		if(isOutSide()) {vanish();}
	}
	
	public function draw(buf:BitmapData):void
	{
		var currentFrame:DisplayImage = cell[dir][anime%3];
		pos.x = x-currentFrame.cx;
		pos.y = y-currentFrame.cy;
		buf.copyPixels(currentFrame.bmp, currentFrame.rect, pos);
		anime++;
	}
	
	public function isOutSide():Boolean
	{
		return (x < 0 || y < 0 || x > 360 || y > 420);
	}
	
	public function vanish():void
	{
		endflag = true;
	}
}

class Maru extends ObjBase
{
	static private var bitmap:BitmapData = new BitmapData(24, 24, true, 0);
	private var matrix:Matrix = new Matrix();
	private var pos:Point = new Point();
	
	public var visible:Boolean = true;
	public var alpha:Number = 1;
	
	public static function standby():void
	{
		var temp:Shape = new Shape();
		var matrix:Matrix = new Matrix();
		matrix.createGradientBox(24, 24, 0, 0, 0);
		temp.graphics.beginGradientFill(
			"radial",
			[0xFFFFFF, 0xFFFFFF],
			[100, 0],
			[0x70, 0xFF],
			matrix
		);
		temp.graphics.drawRect(0, 0, 24, 24);
		temp.graphics.endFill();
		
		bitmap.draw(temp, new Matrix());
	}
	
	public function draw(buf:BitmapData):void
	{
		if(visible == false) {return;}
		
		var temp:BitmapData = bitmap.clone();
		temp.colorTransform(temp.rect, new ColorTransform(1, 1, 1, alpha));
		pos.x = x-12;
		pos.y = y-12;
		buf.copyPixels(temp, temp.rect, pos);
	}
}