Flash AS实现的迷宫视觉效果_Flash教程

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!

推荐:用Flash 8 制作简单的Flash相册
本文适合初学者,涉及到的知识包括:遮罩的运用,简单的ActionScript的写法。欢迎转载本站文章,但是转载必须注明出处,并且保留文章中的所有链接,谢谢支持!

完全是由Flash Actionscript实现的一个迷宫图效果。

演示:

源文件:点击这里下载源文件

打开Flash,新建立一个文档,然后修改属性,把帧频调整到25。

然后直接在第一帧输入下面Action:

// maze width
dim_x = 48;
// maze height
dim_y = 28;
// wall lenght
wall_size = 10;
cell_count = dim_x*dim_y;
var maze = new Array();
var mymoves = new Array();
for (x=0; x maze[x] = new Array(0, 1, 1, 1);
// array contains VISITED (0 = not visited), MORTH WALL (1=up;0=down), SOUTH WALL, EAST WALL, WEST WALL
}
// start position
pos = Math.round(Math.random()*(cell_count-1));
// cells visited
visited = 1;
// mark first cell as visited
maze[pos][0] = 1;
while (visited // check for possible moves
possible = "";
if ((Math.floor(pos/dim_x) == Math.floor((pos-1)/dim_x)) and (maze[pos-1][0] == 0)) {
possible = possible "W";
}
if ((Math.floor(pos/dim_x) == Math.floor((pos 1)/dim_x)) and (maze[pos 1][0] == 0)) {
possible = possible "E";
}
if (((pos dim_x) possible = possible "S";
}
if (((pos-dim_x)>=0) and (maze[pos-dim_x][0] == 0)) {
possible = possible "N";
}
// if a move exists, crash a wall and mark new cell as visited
if (possible) {
visited ;
mymoves.push(pos);
way = possible.charAt(Math.round(Math.random()*(possible.length-1)));
switch (way) {
case "N" :
maze[pos][1] = 0;
maze[pos-dim_x][2] = 0;
pos -= dim_x;
break;
case "S" :
maze[pos][2] = 0;
maze[pos dim_x][1] = 0;
pos = dim_x;
break;
case "E" :
maze[pos][3] = 0;
maze[pos 1][4] = 0;
pos ;
break;
case "W" :
maze[pos][4] = 0;
maze[pos-1][3] = 0;
pos--;
break;
}
maze[pos][0] = 1;
// else backtrack to previous visited cell
} else {
pos = mymoves.pop();
}
}
// maze drawing
this.createEmptyMovieClip("drawmaze", 10);
drawmaze.lineStyle(0, 0x000000, 100);
drawmaze.moveTo(10, 10);
start_y = 10-wall_size;
start_x = 0;
for (x=0; x start_x = wall_size;
if ((x%dim_x) == 0) {
start_y = wall_size;
start_x = 10;
}
if (maze[x][2] == 1) {
// south
drawmaze.moveTo(start_x, start_y wall_size);
drawmaze.lineTo(start_x wall_size, start_y wall_size);
//drawmaze.moveTo(start_x, start_y);
}
if (maze[x][3] == 1) {
// east
drawmaze.moveTo(start_x wall_size, start_y);
drawmaze.lineTo(start_x wall_size, start_y wall_size);
//drawmaze.moveTo(start_x, start_y);
}
}
drawmaze.lineStyle(0, 0xff0000, 100);
drawmaze.moveTo(10, 10);
drawmaze.lineTo(10 wall_size*dim_x, 10);
drawmaze.lineTo(10 wall_size*dim_x, 10 wall_size*dim_y);
drawmaze.lineTo(10, 10 wall_size*dim_y);
drawmaze.lineTo(10, 10);

测试吧!

分享:Flash轻松实现五彩变换多边形鼠标轨迹特效
本教程完全是利用Flash的ActionScript指令来实现了!利用Flash画图大家已经知道了!这个教程就当给大家复习一下FlashActionscript的绘图功能吧!这个教程制

/所属分类:Flash教程/更新时间:2008-03-05
相关Flash教程