flash素材、flash片头、flash特效、flash源码,flash相册等flash资源都是本站的重要flash素材请大家支持新丁flash素材网!
首页 | 片头欣赏 | Banner 欣赏 | Flash 特效 | 网站欣赏 | 黄色笑话 | 技术文档 | 视频教程 | 网页模板 | flash小游戏 | 源码下载 | 相关下载 | 声音下载 |
flash Action应用 您当前的位置是:首页 >> 技术文档 >> flash Action应用 >> 详细内容
Flash AS实现的迷宫视觉效果
加入时间:2007-8-3 浏览:23 录入:Flash资源网 来源:网络

完全是由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);

测试吧!

关于我们 | 联系方式 | 广告赞助 | 免责声明 | 站点留言 | 友情链接 | 推荐站点
Copyright 2007-2008 新丁flash资源(flash素材)网 All Rights Reserved
新丁flash资源(flash素材)网 保留所有权利 未经许可请勿任意转载或复制使用 
请使用1024*768分辨率浏览本站以达到浏览新丁flash资源(flash素材)网的最佳视觉效果
新丁flash资源(flash素材)网中所有的解压密码均为:www.qnflash.com
粤ICP备08010396号