flash on 2014-10-22
/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/loRV
*/
package {
import flash.text.TextField;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
deb = new TextField();
deb.width=320;
deb.height=240;
deb.mouseEnabled=false;
addChild(deb);
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public var deb:TextField;
public var camx:Number = -230;
public var camy:Number = -230;
public var cx:Number = 0; public var cy:Number = 0;
public var ang:Number = 0;
public var vx:Number = 0; public var vy:Number = 0;
public function onEnter(e:Event):void
{
var mx:Number; var my:Number;
var wmx:Number; var wmy:Number;
mx = stage.mouseX;
my = stage.mouseY;
wmx = camx + mx;
wmy = camy + my;
ang = Math.atan2(wmy-cy, wmx-cx);
var d:Number;
var ms:Number;
d = getDist(wmx-cx,wmy-cy);
//deb.text = "d " + d ;
if (d > 80)
{
ms = 0.1;
if (d > 140) {ms=0.2;}
if (d > 210) {ms=0.3;}
vx += Math.cos(ang) * ms;
vy += Math.sin(ang) * ms;
} else if (d < 70) { vx *= 0.9; vy*=0.9; }
vx *= 0.99; vy*=0.99;
cx +=vx; cy+=vy;
camx = camx + (cx-(camx+230))*0.1;
camy = camy + (cy-(camy+230))*0.1;
graphics.clear();
graphics.lineStyle(2, 0);
graphics.lineStyle(1,0,0.5);
drawGrid(camx*0.5,camy*0.5);
drawGrid((camx+465)*0.5,(camy+465)*0.5);
graphics.lineStyle(2,0);
var kx:Number; var ky:Number;
kx = cx - camx;
ky = cy - camy;
graphics.drawCircle(kx,ky, 16);
graphics.moveTo(kx,ky);
graphics.lineTo(kx+Math.cos(ang)*16, ky+Math.sin(ang)*16);
graphics.moveTo(mx,my-8); graphics.lineTo(mx,my+8);
graphics.moveTo(mx-8,my); graphics.lineTo(mx+8,my);
drawGrid(camx,camy);
//deb.text = " "+cx+" "+cy+" "+kx;
//deb.text = " "+kx+" "+ky;
kx = int(cx / 465)+32;
ky = int(cy/465)+32;
graphics.drawRect(0,0,64,64);
graphics.drawCircle(kx,ky,4);
}//onenter
public function drawGrid(sx:Number, sy:Number):void
{
var kx:Number; var ky:Number;
kx = int(sx/465)*465;
kx -= sx; if (kx < 0) { kx+=465;} else if (kx > 465) {kx-=465;}
graphics.moveTo(kx, 0); graphics.lineTo(kx,465);
ky = int(sy/465)*465;
ky -= sy; if (ky < 0) { ky+=465;} else if (ky > 465) {ky-=465;}
graphics.moveTo(0, ky); graphics.lineTo(465, ky);
}//drawgrid
public function getDist(ax:Number, ay:Number):Number
{ return Math.sqrt(ax*ax+ay*ay); }
}//classend
}