/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/xj56
*/
package {
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMdown);
stage.addEventListener(MouseEvent.MOUSE_UP, onMup);
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public function onMdown(e:MouseEvent):void { mdown = true; }
public function onMup(e:MouseEvent):void { mdown = false; }
public var mdown:Boolean = false;
public var cx:Number = 230;
public var cy:Number = 330;
public var vx:Number = 0;
public var vy:Number = 0;
public var wx:Number = 230;
public var wy:Number = 230;
public var rx:Number = 0;
public var ry:Number = 0;
public function onEnter(e:Event):void
{
graphics.clear();
graphics.lineStyle(2, 0);
var mx:Number; var my:Number;
mx = stage.mouseX;
my = stage.mouseY;
var ang:Number;
ang = Math.atan2(my-cy,mx-cx);
graphics.drawCircle(cx,cy,16);
graphics.moveTo(cx,cy); graphics.lineTo(cx+Math.cos(ang)*16,cy+Math.sin(ang)*16);
vx *=0.8; vy*=0.8;
if (mdown)
{
var ms:Number;ms =3;
vx = Math.cos(ang)*ms;
vy = Math.sin(ang)*ms;
}
cx+=vx; cy+=vy;
// var ang2:Number;
// ang2 = Math.atan2(wy-cy,wx-cx);
//graphics.moveTo(wx,wy); graphics.lineTo(wx+Math.cos(ang2)*16,wy+Math.sin(ang2)*16);
graphics.drawCircle(wx,wy, 16);
var d:Number;
d = getDist(wx-cx,wy-cy);
if (d < 32) { rx=vx; ry=vy; }
wx+=rx; wy+=ry;
rx *= 0.8; ry*=0.8;
}//onenter
public function getDist(ax:Number, ay:Number):Number
{ return Math.sqrt(ax*ax+ay*ay); }
}//classend
}