Wit scherm, dit is mijn .swf code:
voorbeeld.swf
function getTarget() {
if(game["t_"+game.ymouse+"_"+game.xmouse].walkable){
game.targetx=game.xmouse;
game.targety=game.ymouse;
if(!char.moving){
findPath(char.xtile, char.ytile, game.targetx, game.targety);
}else{
game.clicked=true;
}
}
}
function findPath(startx, starty, targetx, targety){
path={};
path.Unchecked_Neighbours=[];
path.done = false;
path.name="node_"+starty+"_"+startx;
path[path.name]={x:startx, y:starty, visited:true, parentx:null, parenty:null};
path.Unchecked_Neighbours[path.Unchecked_Neighbours.length]=path[path.name];
while(path.Unchecked_Neighbours.length>0) {
var N = path.Unchecked_Neighbours.shift();
if (N.x == targetx and N.y == targety) {
make_path(N);
path.done = true;
break;
}else {
N.visited=true;
addNode (N, N.x+1, N.y);
addNode (N, N.x-1, N.y);
addNode (N, N.x, N.y+1);
addNode (N, N.x, N.y-1);
}
}
delete path;
if (path.done) {
return true;
}else {
return false;
}
}
function addNode (ob, x, y){
path.name="node_"+y+"_"+x;
if(game["t_"+y+"_"+x].walkable){
if (path[path.name].visited != true) {
path[path.name]={x:x, y:y, visited:false, parentx:ob.x, parenty:ob.y};
path.Unchecked_Neighbours[path.Unchecked_Neighbours.length]=path[path.name];
}
}
}
function make_path(ob){
game.path=[];
while (ob.parentx!=null){
game.path[game.path.length]=ob.x;
game.path[game.path.length]=ob.y;
ob=path["node_"+ob.parenty+"_"+ob.parentx];
}
char.moving=true;
}
if(game.clicked){
game.clicked=false;
findPath(char.xtile, char.ytile, game.targetx, game.targety);
return;
}
if(game.path.length>0){
game.targety=game.path.pop();
game.targetx=game.path.pop();
if(game.targetx>ob.xtile){
ob.dirx=1;
ob.diry=0;
}else if(game.targetx<ob.xtile){
ob.dirx=-1;
ob.diry=0;
}else if(game.targety>ob.ytile){
ob.dirx=0;
ob.diry=1;
}else {
ob.dirx=0;
ob.diry=-1;
}
}else{
ob.moving=false;
return;
}
Fouten? Ik krijg wit scherm dus..
Index.php:
http://habbo-ster.nl/all/projects/voorbeelden/