From 1401c8c86157dc007f7a3701f6bf34f3b728a8ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=B5=A9=E4=B9=90?= <89932980@qq.com> Date: Fri, 8 Jan 2016 11:22:01 +0800 Subject: [PATCH] =?UTF-8?q?updated=20=E4=BF=AE=E6=94=B9=E6=B8=B8=E6=88=8F?= =?UTF-8?q?=E7=A2=B0=E6=92=9E=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 5 ++--- index.js | 15 ++++++--------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/game.js b/game.js index 364a59c..9d0f6a2 100644 --- a/game.js +++ b/game.js @@ -242,10 +242,9 @@ function Game(id,options){ return item; }; //获取对象列表 - Stage.prototype.getItemsByType = function(){ - var types = Array.prototype.slice.call(arguments,0); + Stage.prototype.getItemsByType = function(type){ var items = this.items.filter(function(item){ - if(types.indexOf(item.type)>-1){ + if(item.type==type){ return item; } }); diff --git a/index.js b/index.js index f4c92d2..03a992d 100644 --- a/index.js +++ b/index.js @@ -106,16 +106,13 @@ update:function(){ if(this.map){ var stage = this; - var items = this.getItemsByType(1,2); - var hash = {}; //当前对象位置分布 + var player = this.getItemsByType(1)[0]; + var items = this.getItemsByType(2); items.forEach(function(item){ - var key = 'x'+item.coord.x+'y'+item.coord.y; //坐标的标识 - if(hash[key]){ - if(hash[key]!=item.type){ //如果NPC与玩家相遇 - stage.status = 2; - } - }else{ - hash[key] = item.type; + var dx = item.x-player.x; + var dy = item.y-player.y; + if(dx*dx+dy*dy<750){ + stage.status = 2; } }); }