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

エビフライミサイル

クリックで加速します
Get Adobe Flash player
by nemu90kWw 23 Jan 2009
//クリックで加速します
package
{
	import flash.display.*;
	import flash.events.*;
	
	[SWF(width="240", height="240", backgroundColor="0x188000", frameRate="60")]
	public class FLIFLIXX extends Sprite
	{
		private var ebifly:Ebifly = new Ebifly();
		public function FLIFLIXX()
		{
			Mouse.setListener(stage);
			
			ebifly.x = 120;
			ebifly.y = 120;
			
			addChild(ebifly);
		}
	}
}

import flash.display.*;
import flash.events.*;

class Ebifly extends Sprite
{
	private var count:int = 0;
	private var currentframe:int = 0;
	private var vx:Number = 0, vy:Number = 0;
	private var sx:Number = 0, sy:Number = 0;
	private var angle:Number, prevangle:Number;
	private var wait:Boolean = true;
	
	function Ebifly() {
		addEventListener(Event.ENTER_FRAME, onEnterFrame);
	}
	
	public function onEnterFrame(e:Event):void
	{
		if(count % 3 == 0)
		{
			nextFrame();
			
			var bearing:Number;
			prevangle = angle;
			
			if(getDistance(Mouse.x-x, Mouse.y-y) > 20)
			{
				angle = getAngle(Mouse.x-x, Mouse.y-y);
				
				//相対角度を取得
				bearing = MathEx.getBearing(prevangle, angle);
			}
			else {
				bearing = 0;
			}
			
			if(wait == true) {
				if(Mouse.isDown == true) {wait = false;}
			}
			else {
				//加速
				var speed:Number;
				if(Mouse.isDown) {speed = 1.7;}
				else {speed = 0.9;}
				
				vx += MathEx.getVectorX(angle, speed);
				vy += MathEx.getVectorY(angle, speed);
				
				//減速
				var brake:Number;
				if(Mouse.isDown) {brake = 1.05 + (Math.abs(bearing)/80);}
				else {brake = 1.12 + (Math.abs(bearing)/260);}
				
				vx /= brake;
				vy /= brake;
			}
			
			//煙
			if(count % 6 == 0 && Mouse.isDown)
			{
				var smoke:Smoke = new Smoke();
				smoke.x = x-4+Math.random()*8;
				smoke.y = y-4+Math.random()*8;
				smoke.angle = angle-8+Math.random()*16;
				smoke.speed = (-10-2+Math.random()*4)/3;
				smoke.ax = (vx / 2)/3;
				smoke.ay = (vy / 2)/3;
				parent.addChild(smoke);
			}
			
			sx = (sx * 3 + (1.1-getDistance(vx, vy)*0.02) + 1) / 5;
			sy = (sy * 3 + (0.8+getDistance(vx, vy)*0.04) + 1) / 5;
		}
		else if(getDistance(Mouse.x-x, Mouse.y-y) > 20) {
			angle = getAngle(Mouse.x-x, Mouse.y-y);
		}
		x += vx/3;
		y += vy/3;
		
		if(currentframe < 5) {scaleX = sx;}
		else {scaleX = -sx;}
		scaleY = sy;
		
		rotation = angle * (360/256);
		count++;
	}
	
	public function getAngle(x:Number, y:Number):Number
	{
		return (Math.atan2(y, x)*128/Math.PI)+64;
	}
	
	public function getDistance(x:Number, y:Number):Number
	{
		return Math.sqrt((x)*(x)+(y)*(y));
	}
	
	private function nextFrame():void
	{
		if(currentframe == 7) {currentframe = 0;}
		else {currentframe++;}
		
		var g:Graphics = graphics;
		g.clear();
		
		//後ろ
		switch(currentframe)
		{
		case 0:
			g.beginFill(0xF83038);
			g.drawPath(Vector.<int>([1,2,2]),
				Vector.<Number>([-6.3, -2.0, -13.2, 11.8, -4, 3.8]));
			g.endFill();
			g.beginFill(0xF83038);
			g.drawPath(Vector.<int>([1,2,2]),
				Vector.<Number>([6.3, -2.0, 13.2, 11.8, 4, 3.8]));
			g.endFill();
			break;
		case 1:
		case 7:
			g.beginFill(0xF83038);
			g.drawPath(Vector.<int>([1,2,2]),
				Vector.<Number>([-8.5, -2.0, -15, 11, -5.7, 3.5]));
			g.endFill();
			g.beginFill(0xE02030);
			g.drawPath(Vector.<int>([1,2,2]),
				Vector.<Number>([4.8, -2.0, 10.7, 12, 2.6, 4.0]));
			g.endFill();
			break;
		case 2:
		case 6:
			break;
		case 3:
		case 5:
			g.beginFill(0xE02030);
			g.drawPath(Vector.<int>([1,2,2]),
				Vector.<Number>([1.8, -2.0, 4.7, 13.2, 0, 4.5]));
			g.endFill();
			break;
		case 4:
			g.beginFill(0xE02030);
			g.drawPath(Vector.<int>([1,2,2,2]),
				Vector.<Number>([0, 2, -1.1, 4.4, 0, 13.2, 1.1, 4.4]));
			g.endFill();
			break;
		}
		
		//本体
		g.beginFill(0xF8FF80);
		g.drawPath(Vector.<int>([1,2,2,2,2,2,2,2,2]),
			Vector.<Number>([0, -12, 5, -8.4, 6, 1.9, 4.2, 5.2, 1.4, 6.5, -1.4, 6.5, -4.2, 5.2, -6, 1.9, -5, -8.4]));
		g.endFill();
		
		//前側
		switch(currentframe)
		{
		case 0:
			g.beginFill(0xFF4840);
			g.drawPath(Vector.<int>([1,2,2,2]),
				Vector.<Number>([0, 1.5, -1.5, 4.4, 0, 13.2, 1.5, 4.4]));
			g.endFill();
			break;
		case 1:
		case 7:
			g.beginFill(0xFF4840);
			g.drawPath(Vector.<int>([1,2,2]),
				Vector.<Number>([1.8, -1.4, -0.3, 4.5, 4.7, 13.2]));
			g.endFill();
			break;
		case 2:
		case 6:
			g.beginFill(0xFF4840);
			g.drawPath(Vector.<int>([1,2,2]),
				Vector.<Number>([-9.3, -2.1, -16.2, 10.6, -6.5, 3.1]));
			g.endFill();
			g.beginFill(0xFF4840);
			g.drawPath(Vector.<int>([1,2,2]),
				Vector.<Number>([3.1, -1.4, 8.4, 12.9, 1.1, 4.5]));
			g.endFill();
			break;
		case 3:
		case 5:
			g.beginFill(0xFF4840);
			g.drawPath(Vector.<int>([1,2,2]),
				Vector.<Number>([-8.5, -2, -15.7, 10.9, -5.7, 3.5]));
			g.endFill();
			g.beginFill(0xFF4840);
			g.drawPath(Vector.<int>([1,2,2]),
				Vector.<Number>([4.8, -1.7, 10.7, 12, 2.6, 4]));
			g.endFill();
			break;
		case 4:
			g.beginFill(0xFF4840);
			g.drawPath(Vector.<int>([1,2,2]),
				Vector.<Number>([-6.3, -2.0, -13.8, 11.8, -4, 3.8]));
			g.endFill();
			g.beginFill(0xFF4840);
			g.drawPath(Vector.<int>([1,2,2]),
				Vector.<Number>([6.3, -2.0, 13.8, 11.8, 4, 3.8]));
			g.endFill();
			break;
		}
	}
}

class Smoke extends Sprite
{
	private var count:int = 0;
	private var currentframe:int = 0;
	public var angle:Number = 0, speed:Number = 0;
	public var ax:Number = 0, ay:Number = 0;
	
	function Smoke() {
		addEventListener(Event.ENTER_FRAME, onEnterFrame);
	}
	
	public function onEnterFrame(e:Event):void
	{
		x += MathEx.getVectorX(angle, speed) + ax;
		y += MathEx.getVectorY(angle, speed) + ay;
		
		if(count % 3 == 0)
		{
			nextFrame();
			if(currentframe == 7)
			{
				removeEventListener(Event.ENTER_FRAME, onEnterFrame);
				parent.removeChild(this);
				return;
			}
		}
		count++;
	}
	
	private function nextFrame():void
	{
		var g:Graphics = graphics;
		g.clear();
		
		switch(currentframe)
		{
		case 0:
			g.beginFill(0xFFFFFF);
			g.drawCircle(0, 0, 6);
			g.endFill();
			break;
		case 1:
			g.beginFill(0xFFFFFF);
			g.drawCircle(0, 0, 4);
			g.endFill();
			break;
		case 2:
			g.lineStyle(4.5, 0xFFFFFF);
			g.drawCircle(0, 0, 3.75);
			break;
		case 3:
			g.lineStyle(2.5, 0xFFFFFF);
			g.drawCircle(0, 0, 5.75);
			break;
		case 4:
			g.lineStyle(1.5, 0xFFFFFF);
			g.drawCircle(0, 0, 7.25);
			break;
		case 5:
			g.lineStyle(0.75, 0xFFFFFF);
			g.drawCircle(0, 0, 8);
			break;
		}
		
		currentframe++;
	}
}

class MathEx
{
	public static function getVectorX(dir:Number, speed:Number):Number {
		return Math.cos(Math.PI/128*(dir+192))*speed;
	}
	public static function getVectorY(dir:Number, speed:Number):Number {
		return Math.sin(Math.PI/128*(dir+192))*speed;
	}
	public static function getBearing(dir1:Number, dir2:Number):Number {
		var d1:Number = normalizeAngle(dir1);
		var d2:Number = normalizeAngle(dir2);
		if(d2-128 > d1) {d1 += 256;}
		if(d2+128 < d1) {d1 -= 256;}
		return d1-d2;
	}
	public static function normalizeAngle(dir:Number):Number {
		if (dir < -128) {dir = 256 - (-dir % 256);}
		return (dir + 128) % 256 - 128;
	}
}

class Mouse
{
	public static var x:Number = 0;
	public static var y:Number = 0;
	public static var isDown:Boolean = false;
	
	public static function setListener(stage:Stage):void
	{
		stage.mouseChildren = false;
		stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
		stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
		stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
	}
	
	private static function onMouseMove(event:Event):void
	{
		x = event.target.mouseX;
		y = event.target.mouseY;
	}
	
	private static function onMouseDown(event:Event):void {isDown = true;}
	private static function onMouseUp(event:Event):void {isDown = false;}
}