From 8848cbf001df04a4596925ab40c8b55065ed501c 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 10:55:36 +0800 Subject: [PATCH] =?UTF-8?q?updated=20=E6=B7=BB=E5=8A=A0=E5=B8=83=E6=99=AF?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=B9=E6=B3=95=EF=BC=8C=E5=BD=93=E7=8E=A9?= =?UTF-8?q?=E5=AE=B6=E4=B8=8ENPC=E7=9B=B8=E9=81=87=E6=97=B6=E6=9A=82?= =?UTF-8?q?=E5=81=9C=E5=B8=83=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 6 ++++-- index.js | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/game.js b/game.js index 675c816..364a59c 100644 --- a/game.js +++ b/game.js @@ -200,6 +200,7 @@ function Game(id,options){ var fn = function(){ _context.clearRect(0,0,_.width,_.height); //清除画布 f++; + stage.update(); if(stage.map){ stage.map.update(); stage.map.draw(_context); @@ -241,9 +242,10 @@ function Game(id,options){ return item; }; //获取对象列表 - Stage.prototype.getItemsByType = function(type){ + Stage.prototype.getItemsByType = function(){ + var types = Array.prototype.slice.call(arguments,0); var items = this.items.filter(function(item){ - if(item.type==type){ + if(types.indexOf(item.type)>-1){ return item; } }); diff --git a/index.js b/index.js index 41c87d7..f4c92d2 100644 --- a/index.js +++ b/index.js @@ -104,7 +104,21 @@ (function(){ var stage = game.createStage({ update:function(){ - + if(this.map){ + var stage = this; + var items = this.getItemsByType(1,2); + var hash = {}; //当前对象位置分布 + 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; + } + }); + } } }); //绘制地图 @@ -358,5 +372,5 @@ }); })(); game.init(); - game.nextStage(); //测试游戏主布景 + game.nextStage(); //*测试*游戏主布景,完成后需关闭 })(); \ No newline at end of file