updated NPC随机时间点出发

This commit is contained in:
郑浩乐 2016-01-11 12:50:53 +08:00
parent 6a170fabcb
commit 7bce202206

View File

@ -277,17 +277,18 @@
stage.createItem({ stage.createItem({
width:30, width:30,
height:30, height:30,
orientation:3,
color:_COLOR[i], color:_COLOR[i],
location:map, location:map,
coord:{x:12+i,y:14}, coord:{x:12+i,y:14},
vector:{x:12+i,y:14},
type:2, type:2,
frames:10, frames:10,
speed:1, speed:1,
timeout:Math.floor(Math.random()*120), timeout:Math.floor(Math.random()*120),
update:function(){ update:function(){
console.log(this.timeout);
if(!this.timeout){
if(!this.coord.offset){ if(!this.coord.offset){
if(!this.timeout){
var new_map = JSON.parse(JSON.stringify(map.data)); var new_map = JSON.parse(JSON.stringify(map.data));
var items = stage.getItemsByType(2); var items = stage.getItemsByType(2);
var index = this.index; var index = this.index;
@ -304,7 +305,7 @@
if(this.path.length){ if(this.path.length){
this.vector = this.path[0]; this.vector = this.path[0];
} }
if(this.vector){ }
if(this.vector.change){ //是否转变方向 if(this.vector.change){ //是否转变方向
this.coord.x = this.vector.x; this.coord.x = this.vector.x;
this.coord.y = this.vector.y; this.coord.y = this.vector.y;
@ -322,12 +323,8 @@
this.orientation = 3; this.orientation = 3;
} }
} }
}
if(this.vector){
this.x += this.speed*_COS[this.orientation]; this.x += this.speed*_COS[this.orientation];
this.y += this.speed*_SIN[this.orientation]; this.y += this.speed*_SIN[this.orientation];
}
}
}, },
draw:function(context){ draw:function(context){
context.fillStyle = this.color; context.fillStyle = this.color;