NPC跟踪行为

This commit is contained in:
郑浩乐
2016-01-06 00:29:33 +08:00
parent 7e8d45f058
commit 2b3d86f979
2 changed files with 57 additions and 29 deletions

View File

@@ -348,10 +348,39 @@
type:2,
speed:10,
update:function(){
this.path = map.finder({
start:[this.coord.y,this.coord.x],
end:[player.coord.y,player.coord.x]
});
if(!this.coord.offset){
this.path = map.finder({
start:this.coord,
end:player.coord
});
if(this.path.length){
this.vector = this.path[0];
}
if(this.vector.x>this.coord.x){
this.orientation = 1;
}else if(this.vector.x<this.coord.x){
this.orientation = 3;
}else if(this.vector.y>this.coord.y){
this.orientation = 2;
}else if(this.vector.y<this.coord.y){
this.orientation = 0;
}
}
var steps = 1;
switch(this.orientation){
case 0:
this.y-=steps;
break;
case 1:
this.x+=steps;
break;
case 2:
this.y+=steps;
break;
case 3:
this.x-=steps;
break;
}
},
draw:function(context){
context.fillStyle = '#F00';