updated 对象允许穿越

This commit is contained in:
郑浩乐 2016-01-06 14:27:25 +08:00
parent 99f8b482d2
commit 6ad13f8bd4
2 changed files with 68 additions and 19 deletions

22
game.js
View File

@ -138,13 +138,21 @@ function Game(id,options){
var _render = function(list){ var _render = function(list){
var new_list = []; var new_list = [];
var next = function(from,to){ var next = function(from,to){
if(_self.get(to.x,to.y)==0&&!finded){ //当前点是否可以走 if(!finded){
if(to.x==options.end.x&&to.y==options.end.y){ var value = _self.get(to.x,to.y);
steps[to.y][to.x] = from; if(value!=1){ //当前点是否可以走
finded = true; if(value==-1){
}else if(!steps[to.y][to.x]){ to.x = (to.x+x_length)%x_length;
steps[to.y][to.x] = from; to.y = (to.y+y_length)%y_length;
new_list.push(to); to.change = 1;
}
if(to.x==options.end.x&&to.y==options.end.y){
steps[to.y][to.x] = from;
finded = true;
}else if(!steps[to.y][to.x]){
steps[to.y][to.x] = from;
new_list.push(to);
}
} }
} }
}; };

View File

@ -356,6 +356,13 @@
}); });
if(this.path.length){ if(this.path.length){
this.vector = this.path[0]; this.vector = this.path[0];
if(this.vector.change){ //是否转变方向
this.coord.x = this.vector.x;
this.coord.y = this.vector.y;
var pos = map.coord2position(this.coord.x,this.coord.y);
this.x = pos.x;
this.y = pos.y;
}
} }
if(this.vector.x>this.coord.x){ if(this.vector.x>this.coord.x){
this.orientation = 1; this.orientation = 1;
@ -386,10 +393,19 @@
context.fillStyle = '#F00'; context.fillStyle = '#F00';
context.beginPath(); context.beginPath();
context.arc(this.x,this.y,this.width*.5,0,Math.PI,true); context.arc(this.x,this.y,this.width*.5,0,Math.PI,true);
context.lineTo(this.x-this.width*.5,this.y+this.height*.4); switch(this.times%2){
context.quadraticCurveTo(this.x-this.width*.4,this.y+this.height*.5,this.x-this.width*.2,this.y+this.height*.3); case 0:
context.quadraticCurveTo(this.x,this.y+this.height*.5,this.x+this.width*.2,this.y+this.height*.3); context.lineTo(this.x-this.width*.5,this.y+this.height*.4);
context.quadraticCurveTo(this.x+this.width*.4,this.y+this.height*.5,this.x+this.width*.5,this.y+this.height*.4); context.quadraticCurveTo(this.x-this.width*.4,this.y+this.height*.5,this.x-this.width*.2,this.y+this.height*.3);
context.quadraticCurveTo(this.x,this.y+this.height*.5,this.x+this.width*.2,this.y+this.height*.3);
context.quadraticCurveTo(this.x+this.width*.4,this.y+this.height*.5,this.x+this.width*.5,this.y+this.height*.4);
break;
case 1:
context.lineTo(this.x-this.width*.5,this.y+this.height*.3);
context.quadraticCurveTo(this.x-this.width*.25,this.y+this.height*.5,this.x,this.y+this.height*.3);
context.quadraticCurveTo(this.x+this.width*.25,this.y+this.height*.5,this.x+this.width*.5,this.y+this.height*.3);
break;
}
context.fill(); context.fill();
context.closePath(); context.closePath();
context.fillStyle = '#FFF'; context.fillStyle = '#FFF';
@ -402,14 +418,39 @@
context.fill(); context.fill();
context.closePath(); context.closePath();
context.fillStyle = '#00F'; context.fillStyle = '#00F';
context.beginPath(); switch(this.times%4){
context.arc(this.x-this.width*.15,this.y-this.height*.28,this.width*.07,0,2*Math.PI,false); case 2:
context.fill(); case 0:
context.closePath(); context.beginPath();
context.beginPath(); context.arc(this.x-this.width*.15,this.y-this.height*.27,this.width*.07,0,2*Math.PI,false);
context.arc(this.x+this.width*.15,this.y-this.height*.28,this.width*.07,0,2*Math.PI,false); context.fill();
context.fill(); context.closePath();
context.closePath(); context.beginPath();
context.arc(this.x+this.width*.15,this.y-this.height*.27,this.width*.07,0,2*Math.PI,false);
context.fill();
context.closePath();
break;
case 1:
context.beginPath();
context.arc(this.x-this.width*.17,this.y-this.height*.25,this.width*.07,0,2*Math.PI,false);
context.fill();
context.closePath();
context.beginPath();
context.arc(this.x+this.width*.13,this.y-this.height*.25,this.width*.07,0,2*Math.PI,false);
context.fill();
context.closePath();
break;
case 3:
context.beginPath();
context.arc(this.x-this.width*.13,this.y-this.height*.25,this.width*.07,0,2*Math.PI,false);
context.fill();
context.closePath();
context.beginPath();
context.arc(this.x+this.width*.17,this.y-this.height*.25,this.width*.07,0,2*Math.PI,false);
context.fill();
context.closePath();
break;
}
} }
}); });
stage.bind('keydown',function(e){ stage.bind('keydown',function(e){