CGArt-中国CGer中的绿色家园
首页 信息动态 原创排行 互动教程 资源千寻 CG人才 CGArt杂志 艺术设计 CG画廊 CG论坛 酷站欣赏 CG搜索 会员中心
Flash AS实现的迷宫视觉效果
来源:网页教学网 作者:闪电儿 编辑:浪漫的季节 发布时间:2007年07月02日 15:44:46

完全是由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<cell_count; 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<cell_count) {
 // 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)<cell_count) and (maze[pos+dim_x][0] == 0)) {
  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<cell_count; 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);

测试吧!

共有评论0条
更多评论..
作者信息 详细信息
评论人:
验证码:
内容:
 
about us advertisement publish conformity service cooperate associate link site map contact us help jump to the top of page