updated 多余的条件判断、代码去除
This commit is contained in:
parent
f1cac66518
commit
0144d9b226
16
game.js
16
game.js
@ -155,15 +155,14 @@ function Game(id,params){
|
||||
type:'path'
|
||||
};
|
||||
var options = _extend({},defaults,params);
|
||||
var result = [];
|
||||
if(options.map[options.start.y][options.start.x]||options.map[options.end.y][options.end.x]){ //当起点或终点设置在墙上
|
||||
return [];
|
||||
}
|
||||
var finded = false;
|
||||
var result = [];
|
||||
var y_length = options.map.length;
|
||||
var x_length = options.map[0].length;
|
||||
var steps = []; //步骤的映射
|
||||
var steps_length = 0;
|
||||
for(var y=y_length;y--;){
|
||||
steps[y] = [];
|
||||
for(var x=x_length;x--;){
|
||||
@ -208,13 +207,12 @@ function Game(id,params){
|
||||
}
|
||||
}
|
||||
};
|
||||
for(var i=0,len=list.length;i<len;i++){
|
||||
var current = list[i];
|
||||
list.forEach(function(current){
|
||||
next(current,{y:current.y+1,x:current.x});
|
||||
next(current,{y:current.y,x:current.x+1});
|
||||
next(current,{y:current.y-1,x:current.x});
|
||||
next(current,{y:current.y,x:current.x-1});
|
||||
}
|
||||
});
|
||||
if(!finded&&new_list.length){
|
||||
_render(new_list);
|
||||
}
|
||||
@ -341,12 +339,10 @@ function Game(id,params){
|
||||
stage.timeout--;
|
||||
}
|
||||
if(stage.update()!=false){ //update返回false,则不绘制
|
||||
if(stage.maps.length){
|
||||
stage.maps.forEach(function(map){
|
||||
if(!(f%map.frames)){
|
||||
map.times = f/map.frames; //计数器
|
||||
}
|
||||
map.update();
|
||||
if(map.cache){
|
||||
if(!map.imageData){
|
||||
_context.save();
|
||||
@ -357,16 +353,15 @@ function Game(id,params){
|
||||
_context.putImageData(map.imageData,0,0);
|
||||
}
|
||||
}else{
|
||||
map.update();
|
||||
map.draw(_context);
|
||||
}
|
||||
});
|
||||
}
|
||||
if(stage.items.length){
|
||||
stage.items.forEach(function(item){
|
||||
if(!(f%item.frames)){
|
||||
item.times = f/item.frames; //计数器
|
||||
}
|
||||
if(stage.status==1&&item.status!=2){ //对象及布景状态都处于正常状态下
|
||||
if(stage.status==1&&item.status!=2){ //对象及布景状态都不处于暂停状态
|
||||
if(item.location){
|
||||
item.coord = item.location.position2coord(item.x,item.y);
|
||||
}
|
||||
@ -378,7 +373,6 @@ function Game(id,params){
|
||||
item.draw(_context);
|
||||
});
|
||||
}
|
||||
}
|
||||
_hander = requestAnimationFrame(fn);
|
||||
};
|
||||
_hander = requestAnimationFrame(fn);
|
||||
|
Loading…
x
Reference in New Issue
Block a user