From dbd2649b919e5d729f8a1197d81b5e60412c5f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=B5=A9=E4=B9=90?= Date: Wed, 6 Jan 2016 23:40:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=8F=E5=B0=91=E4=BB=A3=E7=A0=81=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 44 ++++++++------------------------------------ 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/index.js b/index.js index ff55bd5..5db12d8 100644 --- a/index.js +++ b/index.js @@ -231,46 +231,18 @@ var coord = this.coord; if(!coord.offset){ if(typeof this.control.orientation!='undefined'){ - var x = coord.x+_COS[this.control.orientation]; - var y = coord.y+_SIN[this.control.orientation]; - if(!map.get(x,y)){ + if(!map.get(coord.x+_COS[this.control.orientation],coord.y+_SIN[this.control.orientation])){ this.orientation = this.control.orientation; } } this.control = {}; - switch(this.orientation){ - case 0: - var value = map.get(coord.x+1,coord.y); - if(value==0){ - this.x+=this.speed; - }else if(value<0){ - this.x -= map.size*(map.x_length-1); - } - break; - case 1: - var value = map.get(coord.x,coord.y+1); - if(value==0){ - this.y+=this.speed; - }else if(value<0){ - this.y -= map.size*(map.y_length-1); - } - break; - case 2: - var value = map.get(coord.x-1,coord.y); - if(value==0){ - this.x-=this.speed; - }else if(value<0){ - this.x += map.size*(map.x_length-1); - } - break; - case 3: - var value = map.get(coord.x,coord.y-1); - if(value==0){ - this.y-=this.speed; - }else if(value<0){ - this.y += map.size*(map.y_length-1); - } - break; + var value = map.get(coord.x+_COS[this.orientation],coord.y+_SIN[this.orientation]); + if(value==0){ + this.x += this.speed*_COS[this.orientation]; + this.y += this.speed*_SIN[this.orientation]; + }else if(value<0){ + this.x -= map.size*(map.x_length-1)*_SIN[this.orientation]; + this.y -= map.size*(map.y_length-1)*_COS[this.orientation]; } }else{ this.x += this.speed*_COS[this.orientation];