flash on 2016-2-9
♥0 |
Line 60 |
Modified 2016-02-09 04:59:12 |
MIT License
archived:2017-03-30 11:40:01
ActionScript3 source code
/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/aFYC
*/
package {
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
stage.addEventListener(KeyboardEvent.KEY_DOWN,onKdown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKup);
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public var vecKey:Vector.<Boolean>=new Vector.<Boolean>(512,false);
public function onKdown(e:KeyboardEvent):void { vecKey[e.keyCode]=true; }
public function onKup(e:KeyboardEvent):void { vecKey[e.keyCode]=false; }
public function isKey(k:int):Boolean { return vecKey[k]; }
public var tx:int = 8;
public var ty:int = 8;
public var gt:int = 0;
public var vecPrev:Vector.<int> = new Vector.<int>(0,false);
public function onEnter(e:Event):void
{
gt+=1;
if (gt%4==0)
{
var i:int; i = 0;
if (isKey(Keyboard.UP)) { ty-= 1; i=1; }
if (isKey(Keyboard.DOWN)) { ty+= 1;i=1; }
if (isKey(Keyboard.LEFT)) { tx-= 1;i=1; }
if (isKey(Keyboard.RIGHT)) { tx+= 1;i=1; }
if (i > 0)
{ vecPrev.push(tx); vecPrev.push(ty);
if (vecPrev.length>32) { vecPrev.shift(); vecPrev.shift(); }
}//endif2
}//endif
graphics.clear();
graphics.lineStyle(2, 0);
graphics.drawCircle(tx*16,ty*16, 16);
var ax:int; var ay:int;
var num:int;
num = vecPrev.length;
for (i=0;i<num;i+=2)
{
ax = vecPrev[i];
ay = vecPrev[i+1];
graphics.drawCircle(ax*16,ay*16, 16);
}//nexti
var bx:int; var by:int;
//bx=tx;by=ty;
num = vecPrev.length;
for (i=0;i<num;i+=2)
{
ax = vecPrev[i];
ay = vecPrev[i+1];
if (i ==0) { bx=ax;by=ay; continue; }
graphics.moveTo(ax*16,ay*16);
graphics.lineTo(bx*16,by*16);
bx=ax;by=ay;
}//nexti
}//onenter
}//classend
}