flash on 2015-3-1
♥0 |
Line 82 |
Modified 2015-03-01 23:24:54 |
MIT License
archived:2017-03-30 11:47:28
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/uGqb
*/
package {
import flash.text.TextField;
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.geom.Matrix;
import flash.events.Event;
import flash.display.BitmapData;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
deb = new TextField();
deb.width=320; deb.height=240;
deb.mouseEnabled=false;
deb.textColor=0xFFffFF;
addChild(deb);
pic = new BitmapData(32,32, false, 0x404040);
var i:int;
for (i = 0; i < 512; i++)
{
vecPal[i] = Math.random()*0xFFffFF;
}//nexti
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKdown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKup);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMdown);
stage.addEventListener(MouseEvent.MOUSE_UP, onMup);
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public var deb:TextField;
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; onKpress(e.keyCode); }
public function isKeyDown(k:int):Boolean { return vecKey[k];}
public function onMdown(e:MouseEvent):void { mdown = 1; }
public function onMup(e:MouseEvent):void { mdown = 0; }
public var mdown:int = 0;
public var pic:BitmapData;
public var mat:Matrix = new Matrix();
public var vecPal:Vector.<uint> = new Vector.<uint>(512,false);
//cursor
public var cx:int = 10;
public var cy:int = 10;
public function onKpress(k:int):void
{
if (k < 0) { return;} if (k > 512) { return; }
deb.text = ""+k+"\n"+cx+"\n"+cy;
if (k < 48) { return; } if (k > 90) { return;}
var c:uint;
c = vecPal[k];
pic.setPixel(cx,cy, c);
cx +=1;
if (cx >= pic.width) { cx =0; cy+=1; }
}//onkpress
public var gt:int = 0;
public function onEnter(e:Event):void
{
gt +=1;
if (gt % 2 != 0) { return; }
var cw:Number; var ch:Number;
var mx:Number; var my:Number;
var tx:int; var ty:int;
cw = 16; ch = 16;
mx = stage.mouseX; my = stage.mouseY;
tx = Math.floor(mx/cw); ty = Math.floor(my/ch);
mat.a = cw; mat.d = ch;
//if (mdown > 0) { pic.setPixel(tx,ty, 0xFF); }
if (mdown > 0) { cx = tx; cy = ty; }
if (isKeyDown(Keyboard.UP)) { cy-=1;}
if (isKeyDown(Keyboard.DOWN)) { cy+=1;}
if (isKeyDown(Keyboard.LEFT)) { cx-=1;}
if (isKeyDown(Keyboard.RIGHT)) { cx+=1;}
graphics.clear();
graphics.beginBitmapFill(pic, mat,false, false);
graphics.drawRect(0,0,465,465);
graphics.endFill();
graphics.lineStyle(2, 0x000FFF,0.5);
graphics.drawRect(tx*cw,ty*ch,cw,ch);
graphics.lineStyle(2, 0x00FF00,0.5);
graphics.drawRect(cx*cw,cy*ch,cw,ch);
graphics.lineStyle(2, 0,0.5);
graphics.drawRect(cx*cw-1,cy*ch-1,cw+2,ch+2);
}//onenter
}//classend
}