From 1aae941c2379da434e5f872dd41a2b60775b623a 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 13:26:33 +0800 Subject: [PATCH] =?UTF-8?q?updated=20=E7=B3=BB=E7=BB=9F=E5=90=84=E4=B8=AA?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E4=B9=8B=E9=97=B4=E7=9A=84=E5=85=B3=E8=81=94?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E4=BF=AE=E6=94=B9=EF=BC=8Citem=E5=92=8Cmap?= =?UTF-8?q?=E6=9C=89stage=E5=BB=BA=E9=80=A0=EF=BC=8Citem=E5=8F=AF=E7=BB=91?= =?UTF-8?q?=E5=AE=9Amap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 35 ++++++++++++++++++++--------------- index.js | 24 ++++++++++++------------ 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/game.js b/game.js index 9d0f6a2..dd1e2bd 100644 --- a/game.js +++ b/game.js @@ -32,15 +32,18 @@ function Game(id,options){ color:'#F00', //标识颜色 status:1, //对象状态,1表示正常,0表示隐藏,2表示暂停 orientation:0, //当前定位方向,0表示右,1表示下,2表示左,3表示上 - vector:{}, //目标坐标 - coord:{}, //如果对象与地图绑定,获得坐标值 speed:0, //移动速度 + //地图相关 + location:null, //定位地图,Map对象 + path:[], //NPC自动行走的路径 + coord:{}, //如果对象与地图绑定,获得坐标值 + vector:{}, //目标坐标 + //布局相关 + stage:null, //绑定对象与所属布景绑定 + index:0, //对象索引 frames:1, //速度等级,内部计算器times多少帧变化一次 times:0, //计数 control:{}, //控制缓存,到达定位点时处理 - path:[], //NPC自动行走的路径 - index:0, //对象索引 - stage:null, //绑定对象与所属布景绑定 update:function(){}, //更新参数信息 draw:function(){} //绘制 }; @@ -111,7 +114,7 @@ function Game(id,options){ //寻址算法 Map.prototype.finder = function(param){ var defaults = { - map:null,//this.data, + map:null, start:{}, end:{} }; @@ -182,7 +185,7 @@ function Game(id,options){ options = options||{}; var settings = { status:1, //布景状态,1表示正常,0表示非活动 - map:null, //布景地图对象 + maps:[], //地图队列 audio:[], //音频资源 images:[], //图片资源 items:[], //对象队列 @@ -201,9 +204,11 @@ function Game(id,options){ _context.clearRect(0,0,_.width,_.height); //清除画布 f++; stage.update(); - if(stage.map){ - stage.map.update(); - stage.map.draw(_context); + if(stage.maps.length){ + stage.maps.forEach(function(map,index){ + map.update(); + map.draw(_context); + }); } if(stage.items.length){ stage.items.forEach(function(item,index){ @@ -211,8 +216,8 @@ function Game(id,options){ if(!(f%item.frames)){ item.times = f/item.frames; //计数器 } - if(stage.map&&item.type){ - item.coord = stage.map.position2coord(item.x,item.y); + if(item.location){ + item.coord = item.location.position2coord(item.x,item.y); } item.update(); } @@ -235,8 +240,8 @@ function Game(id,options){ //动态属性 item.stage = this; item.index = this.items.length; - if(this.map&&item.type){ - item.coord = this.map.position2coord(item.x,item.y); + if(item.location){ + item.coord = item.location.position2coord(item.x,item.y); } this.items.push(item); return item; @@ -254,10 +259,10 @@ function Game(id,options){ Stage.prototype.createMap = function(options){ var map = new Map(options); //动态属性 - this.map = map; map.stage = this; map.y_length = map.data.length; map.x_length = map.data[0].length; + this.maps.push(map); return map; }; //绑定事件 diff --git a/index.js b/index.js index 03a992d..5529a72 100644 --- a/index.js +++ b/index.js @@ -104,18 +104,16 @@ (function(){ var stage = game.createStage({ update:function(){ - if(this.map){ - var stage = this; - var player = this.getItemsByType(1)[0]; - var items = this.getItemsByType(2); - items.forEach(function(item){ - var dx = item.x-player.x; - var dy = item.y-player.y; - if(dx*dx+dy*dy<750){ - stage.status = 2; - } - }); - } + var stage = this; + var player = this.getItemsByType(1)[0]; + var items = this.getItemsByType(2); + items.forEach(function(item){ + var dx = item.x-player.x; + var dy = item.y-player.y; + if(dx*dx+dy*dy<750){ + stage.status = 2; + } + }); } }); //绘制地图 @@ -224,6 +222,7 @@ width:30, height:30, type:1, + location:map, orientation:2, speed:2, frames:10, @@ -271,6 +270,7 @@ width:30, height:30, color:_COLOR[i], + location:map, type:2, frames:10, speed:1,