/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/k0cW
*/
package {
import flash.text.TextField;
import flash.events.MouseEvent;
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);
var i:int; var k:int; var num:int;
var a:xTile; var yt:int;
mw=13;mh=13;
num=mw*mh;
vecGrid = new Vector.<xTile>(num,false);
for(i=0;i<num;i+=1){ vecGrid[i] = new xTile(); }
for(i=0;i<32;i+=1)
{ setTile(Math.random()*mw, Math.random()*mh, 0x808080); }
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 { mbutton = 1; }
public function onMup(e:MouseEvent):void { mbutton = 0; }
public var deb:TextField;
public var mbutton:int = 0;
public var mx:Number = 0;
public var my:Number = 0;
public var mhold:int = 0;
public var vecGrid:Vector.<xTile>;
public var mw:int = 16;
public var mh:int = 16;
public var cw:Number = 32;
public var ch:Number = 32;
public function setTile(ax:int, ay:int, t:int):void
{ if (ax<0||ax>=mw||ay<0||ay>=mh){return;} vecGrid[ax+(ay*mw)].col = t; }
public function getTile(ax:int, ay:int):xTile
{ if (ax<0||ax>=mw||ay<0||ay>=mh){return null;} return vecGrid[ax+(ay*mw)]; }
public var mode:int = 0;
public function getNoisex(ax:Number, ay:Number):Number
{ return ax + Math.cos(ay*0.08)*4; }
public function getNoisey(ax:Number ,ay:Number):Number
{ return ay + Math.sin(ax*0.06)*4; }
public function onEnter(e:Event):void
{
graphics.clear();
graphics.lineStyle(1,0);
graphics.drawRect(0,0, mw*cw, mh*ch);
mx = stage.mouseX;
my = stage.mouseY;
var tx:int; var ty:int;
tx = Math.floor(mx/cw);
ty = Math.floor(my/ch);
var a:xTile;
var yt:int; var t:int;
var i:int; var k:int;
for (i=0;i<mh;i+=1)
{
yt = mw * i;
for (k=0;k<mw;k+=1)
{
//graphics.drawRect(k*cw, i*ch, cw, ch);
a = getTile(k,i);
if (a.col>0)
{
graphics.lineStyle();
graphics.beginFill(a.col,1);
var ax:Number; var ay:Number;
ax = k*cw; ay = i*ch;
graphics.moveTo(getNoisex(ax,ay), getNoisey(ax,ay));
graphics.lineTo(getNoisex(ax+cw,ay), getNoisey(ax+cw,ay));
graphics.lineTo(getNoisex(ax+cw,ay+ch), getNoisey(ax+cw,ay+ch));
graphics.lineTo(getNoisex(ax,ay+ch), getNoisey(ax,ay+ch));
graphics.lineTo(getNoisex(ax,ay), getNoisey(ax,ay));
//graphics.drawRect(k*cw, i*ch, cw, ch);
graphics.endFill();
}//endif
}//nextk
}//nexti
graphics.lineStyle(4, 0xFF);
//graphics.drawRect(tx*cw,ty*ch,cw,ch);
ax = tx*cw; ay = ty*ch;
graphics.moveTo(getNoisex(ax,ay), getNoisey(ax,ay));
graphics.lineTo(getNoisex(ax+cw,ay), getNoisey(ax+cw,ay));
graphics.lineTo(getNoisex(ax+cw,ay+ch), getNoisey(ax+cw,ay+ch));
graphics.lineTo(getNoisex(ax,ay+ch), getNoisey(ax,ay+ch));
graphics.lineTo(getNoisex(ax,ay), getNoisey(ax,ay));
if (mbutton > 0) { mhold += 1; }
else { mhold = 0; }
a = getTile(tx,ty);
if (a != null && mhold == 1)
{
mhold = 3;
if (a.col == 0)
{
mode =0x808080;
a.col = 0x808080 ;
}
else
{
a.col=0;
mode =0;
}//endif2
}//endif
if (a!=null && mhold>3)
{ a.col=mode; }
}//onenter
}//classend
}
internal class xTile
{
public var col:int = 0;
public var test:int = 0;
}//xtile