Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as text by robson ( 18 years ago )
tw = 20;
th = 20;
sx = int(500/tw);
sy = int(400/th);
W = 0.8;
trace(cp)
//this.createEmptyMovieClip("cp", -2); //Clip Port
cp.d = 0; //Depth Counter
function resetTiles(){
for(y=0;y<sy;y++)for(x=0;x<sx;x++){
tile = cp["t"+x+"_"+y];
tile.isSet = false;
tile.fl = tile.fr = tile.ft = tile.fb = false;
}
}
function initTile(tile){
flags = (tile.fl*8 + tile.fr*4 + tile.ft*2 + tile.fb).toString(2);
while(flags.length<4)flags = "0"+flags;
tile.gotoAndStop("f"+flags);
}
function initScene(){
startx = random(sx);
starty = random(sy);
cux = startx;
cuy = starty;
start._x = startx*tw + field._x;
start._y = starty*th + field._y;
start._xscale = tw/20*100;
start._yscale = th/20*100;
finish._xscale = tw/20*100;
finish._yscale = th/20*100;
startTile = cp["t"+startx+"_"+starty];
startTile.isSet = true;
toSpread = [startTile];
nextSpread = [];
lastTile = startTile;
}
function createTiles(){
//Setup tiles
for(y=0;y<sy;y++)for(x=0;x<sx;x++){
tile = cp.attachMovie("tile", "t"+x+"_"+y, cp.d++);
tile._x = field._x + x*tw;
tile._y = field._y + y*th;
tile.x = x;
tile.y = y;
tile._xscale = tw/20*100;
tile._yscale = th/20*100;
}
}
function spread(){
spread1 = false;
for(i in toSpread){
tile = toSpread[i];
al = tile.x!=0 && !gtile(tile, -1, 0).isSet;
ar = tile.x!=sx-1 && !gtile(tile, 1, 0).isSet;
at = tile.y!=0 && !gtile(tile, 0, -1).isSet;
ab = tile.y!=sy-1 && !gtile(tile, 0, 1).isSet;
if(al || ar || at || ab){
do{
l = Math.random()>W && al;
r = Math.random()>W && ar;
t = Math.random()>W && at;
b = Math.random()>W && ab;
}while(!(l||r||t||b));
if(l)wayTo(tile, -1, 0);
if(r)wayTo(tile, 1, 0);
if(t)wayTo(tile, 0, -1);
if(b)wayTo(tile, 0, 1);
spread1 = true;
}
}
toSpread = nextSpread;
nextSpread = [];
if(!spread1){
fix = lastTile.x;
fiy = lastTile.y;
finish._x = field._x + lastTile.x*tw;
finish._y = field._y + lastTile.y*tw;
for(y=0;y<sy;y++)for(x=0;x<sx;x++){
tile = cp["t"+x+"_"+y];
initTile(tile);
}
}else{
spread();
}
}
function wayTo(tile, x, y){
ntile = cp["t"+(tile.x+x)+"_"+(tile.y+y)];
ntile.isSet = true;
if(x<0)tile.fl = 1;
if(x>0)tile.fr = 1;
if(y<0)tile.ft = 1;
if(y>0)tile.fb = 1;
if(x>0)ntile.fl = 1;
if(x<0)ntile.fr = 1;
if(y>0)ntile.ft = 1;
if(y<0)ntile.fb = 1;
nextSpread.push(ntile);
lastTile = ntile;
}
function gtile(tile, dx, dy){
return cp["t"+(tile.x+dx)+"_"+(tile.y+dy)];
}
createTiles();
initScene();
resetTiles();
spread();
Key.addListener(l={
onKeyDown:function(){
if(Key.getCode()==Key.LEFT && cp["t"+cux+"_"+cuy].fl)cux--;
else if(Key.getCode()==Key.RIGHT && cp["t"+cux+"_"+cuy].fr)cux++;
else if(Key.getCode()==Key.UP && cp["t"+cux+"_"+cuy].ft)cuy--;
else if(Key.getCode()==Key.DOWN && cp["t"+cux+"_"+cuy].fb)cuy++;
start._x = cux*tw + field._x;
start._y = cuy*th + field._y;
if(fix==cux && fiy==cuy)rebuildMaze();
}
});
function rebuildMaze(){
initScene();
resetTiles();
spread();
}
Revise this Paste