home *** CD-ROM | disk | FTP | other *** search
- fscommand("allowscale",false);
- _global.findPath = function(map, startY, startX, endY, endX)
- {
- var HV_COST = 10;
- var D_COST = 14;
- var ALLOW_DIAGONAL = false;
- var ALLOW_DIAGONAL_CORNERING = true;
- isOpen = function(y, x)
- {
- return mapStatus[y][x].open;
- };
- isClosed = function(y, x)
- {
- return mapStatus[y][x].closed;
- };
- nearerSquare = function()
- {
- var minimum = 999999;
- var indexFound = 0;
- var _loc2_ = undefined;
- var _loc3_ = undefined;
- var _loc1_ = openList.length;
- while(_loc1_-- > 0)
- {
- _loc3_ = mapStatus[openList[_loc1_][0]][openList[_loc1_][1]];
- _loc2_ = _loc3_.heuristic + _loc3_.movementCost;
- if(_loc2_ <= minimum)
- {
- minimum = _loc2_;
- indexFound = _loc1_;
- }
- }
- return indexFound;
- };
- closeSquare = function(y, x)
- {
- var _loc3_ = y;
- var _loc2_ = openList.length;
- var _loc1_ = 0;
- while(_loc1_ < _loc2_)
- {
- if(openList[_loc1_][0] == _loc3_)
- {
- if(openList[_loc1_][1] == x)
- {
- openList.splice(_loc1_,1);
- break;
- }
- }
- _loc1_ = _loc1_ + 1;
- }
- mapStatus[_loc3_][x].open = false;
- mapStatus[_loc3_][x].closed = true;
- };
- openSquare = function(y, x, parent, movementCost, heuristic, replacing)
- {
- var _loc1_ = y;
- var _loc2_ = x;
- if(!replacing)
- {
- openList.push([_loc1_,_loc2_]);
- mapStatus[_loc1_][_loc2_] = {heuristic:heuristic,open:true,closed:false};
- }
- mapStatus[_loc1_][_loc2_].parent = parent;
- mapStatus[_loc1_][_loc2_].movementCost = movementCost;
- };
- var mapH = map.length;
- var mapW = map[0].length;
- var mapStatus = new Array();
- var i = 0;
- while(i < mapH)
- {
- mapStatus[i] = new Array();
- i++;
- }
- if(startY == undefined || startX == undefined)
- {
- return null;
- }
- if(endY == undefined || endX == undefined)
- {
- return null;
- }
- var openList = new Array();
- openSquare(startY,startX,undefined,0);
- while(openList.length > 0 && !isClosed(endY,endX))
- {
- var i = nearerSquare();
- var nowY = openList[i][0];
- var nowX = openList[i][1];
- closeSquare(nowY,nowX);
- var _loc2_ = nowY - 1;
- while(_loc2_ < nowY + 2)
- {
- var _loc1_ = nowX - 1;
- while(_loc1_ < nowX + 2)
- {
- if(_loc2_ >= 0 && _loc2_ < mapH && _loc1_ >= 0 && _loc1_ < mapW && !(_loc2_ == nowY && _loc1_ == nowX) && (ALLOW_DIAGONAL || _loc2_ == nowY || _loc1_ == nowX) && (ALLOW_DIAGONAL_CORNERING || _loc2_ == nowY || _loc1_ == nowX || map[_loc2_][nowX] != 0 && map[nowY][_loc1_]))
- {
- if(map[_loc2_][_loc1_] != 0)
- {
- if(!isClosed(_loc2_,_loc1_))
- {
- var _loc3_ = mapStatus[nowY][nowX].movementCost + (!(_loc2_ == nowY || _loc1_ == nowX) ? D_COST : HV_COST) * map[_loc2_][_loc1_];
- if(isOpen(_loc2_,_loc1_))
- {
- if(_loc3_ < mapStatus[_loc2_][_loc1_].movementCost)
- {
- openSquare(_loc2_,_loc1_,[nowY,nowX],_loc3_,undefined,true);
- }
- }
- else
- {
- var heuristic = (Math.abs(_loc2_ - endY) + Math.abs(_loc1_ - endX)) * 10;
- openSquare(_loc2_,_loc1_,[nowY,nowX],_loc3_,heuristic,false);
- }
- }
- }
- }
- _loc1_ = _loc1_ + 1;
- }
- _loc2_ = _loc2_ + 1;
- }
- }
- var pFound = isClosed(endY,endX);
- delete isOpen;
- delete isClosed;
- delete nearerSquare;
- delete closeSquare;
- delete openSquare;
- if(pFound)
- {
- var returnPath = new Array();
- var nowY = endY;
- var nowX = endX;
- while(nowY != startY || nowX != startX)
- {
- returnPath.push([nowY,nowX]);
- var newY = mapStatus[nowY][nowX].parent[0];
- var newX = mapStatus[nowY][nowX].parent[1];
- nowY = newY;
- nowX = newX;
- }
- returnPath.push([startY,startX]);
- return returnPath;
- }
- return null;
- };
- ASSetPropFlags(_global,"findPath",1,0);
- playing = 0;
- klik = new Sound(_root.mySound);
- klik.attachSound("klik");
- wipe = new Sound(_root.mySound);
- wipe.attachSound("wipe");
- error = new Sound(_root.mySound);
- error.attachSound("error");
- blip = new Sound(_root.mySound);
- blip.attachSound("blip");
- stopAllSounds();
- stop();
-