From 8f7ce445146c981834bc0fc16c98812bc4f22a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=B5=A9=E4=B9=90?= <89932980@qq.com> Date: Thu, 7 Jan 2016 14:41:44 +0800 Subject: [PATCH] =?UTF-8?q?updated=20=E6=9D=A5=E5=9B=9E=E7=A9=BF=E8=B6=8A?= =?UTF-8?q?=EF=BC=8CNPC=E6=B6=88=E5=A4=B1=E9=97=AE=E9=A2=98=E8=A7=A3?= =?UTF-8?q?=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 6 +++--- index.js | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/game.js b/game.js index d3986a8..2e00591 100644 --- a/game.js +++ b/game.js @@ -100,8 +100,8 @@ function Game(id,options){ }; //画布坐标转地图坐标 Map.prototype.position2coord = function(x,y){ - var fx = (x-this.x)%this.size-this.size/2; - var fy = (y-this.y)%this.size-this.size/2; + var fx = Math.abs(x-this.x)%this.size-this.size/2; + var fy = Math.abs(y-this.y)%this.size-this.size/2; return { x:Math.floor((x-this.x)/this.size), y:Math.floor((y-this.y)/this.size), @@ -139,7 +139,7 @@ function Game(id,options){ var new_list = []; var next = function(from,to){ if(!finded){ - var value = typeof options.map[to.y][to.x] !='undefined'?options.map[to.y][to.x]:-1; + var value = options.map[to.y]&&typeof options.map[to.y][to.x] !='undefined'?options.map[to.y][to.x]:-1; if(value!=1){ //当前点是否可以走 if(value==-1){ to.x = (to.x+x_length)%x_length; diff --git a/index.js b/index.js index 7eeae3a..7ea7783 100644 --- a/index.js +++ b/index.js @@ -290,13 +290,13 @@ }); if(this.path.length){ 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.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){ this.orientation = 0;