完全是由Flash Actionscript实现的一个迷宫图效果。
演示:
源文件: 迷宫图.rar
打开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); |
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |