updated 多余的条件判断、代码去除

This commit is contained in:
mumuy 2016-05-13 14:29:46 +08:00
parent f1cac66518
commit 0144d9b226

16
game.js
View File

@ -155,15 +155,14 @@ function Game(id,params){
type:'path' type:'path'
}; };
var options = _extend({},defaults,params); var options = _extend({},defaults,params);
var result = [];
if(options.map[options.start.y][options.start.x]||options.map[options.end.y][options.end.x]){ //当起点或终点设置在墙上 if(options.map[options.start.y][options.start.x]||options.map[options.end.y][options.end.x]){ //当起点或终点设置在墙上
return []; return [];
} }
var finded = false; var finded = false;
var result = [];
var y_length = options.map.length; var y_length = options.map.length;
var x_length = options.map[0].length; var x_length = options.map[0].length;
var steps = []; //步骤的映射 var steps = []; //步骤的映射
var steps_length = 0;
for(var y=y_length;y--;){ for(var y=y_length;y--;){
steps[y] = []; steps[y] = [];
for(var x=x_length;x--;){ for(var x=x_length;x--;){
@ -208,13 +207,12 @@ function Game(id,params){
} }
} }
}; };
for(var i=0,len=list.length;i<len;i++){ list.forEach(function(current){
var current = list[i];
next(current,{y:current.y+1,x:current.x}); next(current,{y:current.y+1,x:current.x});
next(current,{y:current.y,x:current.x+1}); next(current,{y:current.y,x:current.x+1});
next(current,{y:current.y-1,x:current.x}); next(current,{y:current.y-1,x:current.x});
next(current,{y:current.y,x:current.x-1}); next(current,{y:current.y,x:current.x-1});
} });
if(!finded&&new_list.length){ if(!finded&&new_list.length){
_render(new_list); _render(new_list);
} }
@ -341,12 +339,10 @@ function Game(id,params){
stage.timeout--; stage.timeout--;
} }
if(stage.update()!=false){ //update返回false,则不绘制 if(stage.update()!=false){ //update返回false,则不绘制
if(stage.maps.length){
stage.maps.forEach(function(map){ stage.maps.forEach(function(map){
if(!(f%map.frames)){ if(!(f%map.frames)){
map.times = f/map.frames; //计数器 map.times = f/map.frames; //计数器
} }
map.update();
if(map.cache){ if(map.cache){
if(!map.imageData){ if(!map.imageData){
_context.save(); _context.save();
@ -357,16 +353,15 @@ function Game(id,params){
_context.putImageData(map.imageData,0,0); _context.putImageData(map.imageData,0,0);
} }
}else{ }else{
map.update();
map.draw(_context); map.draw(_context);
} }
}); });
}
if(stage.items.length){
stage.items.forEach(function(item){ stage.items.forEach(function(item){
if(!(f%item.frames)){ if(!(f%item.frames)){
item.times = 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){ if(item.location){
item.coord = item.location.position2coord(item.x,item.y); item.coord = item.location.position2coord(item.x,item.y);
} }
@ -378,7 +373,6 @@ function Game(id,params){
item.draw(_context); item.draw(_context);
}); });
} }
}
_hander = requestAnimationFrame(fn); _hander = requestAnimationFrame(fn);
}; };
_hander = requestAnimationFrame(fn); _hander = requestAnimationFrame(fn);