From 557e045e614a0ddb19a549a1cd6d253613538f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=B5=A9=E4=B9=90?= Date: Thu, 31 Dec 2015 08:09:47 +0800 Subject: [PATCH 01/27] =?UTF-8?q?=E5=BC=80=E5=A7=8B=E5=B7=A5=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit start --- index.html | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 index.html diff --git a/index.html b/index.html new file mode 100644 index 0000000..e29e8c8 --- /dev/null +++ b/index.html @@ -0,0 +1,99 @@ + + + + + Eat Beans - 吃豆游戏 + + + + + + + \ No newline at end of file From 103e166072605f78ac0450be9b47ef52f28f71a3 Mon Sep 17 00:00:00 2001 From: Haole Zheng Date: Thu, 31 Dec 2015 08:11:02 +0800 Subject: [PATCH 02/27] Create README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..64f2658 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# eatbeans +Eat Beans. 吃豆游戏 + +项目建造中…… From e2965f8b770fb1f9c6aa4303da4a9ff1edd3a28b 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, 31 Dec 2015 14:42:42 +0800 Subject: [PATCH 03/27] =?UTF-8?q?updated=20=E6=B7=BB=E5=8A=A0=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 91 ++---------------------------------------- index.js | 5 +++ pacman.js | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 87 deletions(-) create mode 100644 index.js create mode 100644 pacman.js diff --git a/index.html b/index.html index e29e8c8..b0e3a1f 100644 --- a/index.html +++ b/index.html @@ -5,95 +5,12 @@ Eat Beans - 吃豆游戏 - - + Canvas not supported + + \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..a19ed68 --- /dev/null +++ b/index.js @@ -0,0 +1,5 @@ +//主程序,业务逻辑 +(function(){ + var game = new Game('canvas'); + game.launch(); +})(); \ No newline at end of file diff --git a/pacman.js b/pacman.js new file mode 100644 index 0000000..15063d7 --- /dev/null +++ b/pacman.js @@ -0,0 +1,113 @@ +'use strict'; +//活动对象构造 +function Item(options){ + options = options||{}; + var _ = this; + var settings = { + x:0, //横坐标 + y:0, //纵坐标 + width:20, //宽 + height:20, //高 + type:1, //对象类型 + status:1, //对象状态,1表示正常 + orientation:0, //当前定位方向,0表示上,1表示右,2表示下,3表示左 + vector:{ //目标坐标 + x:0, + y:0 + }, + speed:1, //速度等级,1表示与刷新频率一致 + update:function(){}, //更新参数信息 + draw:function(){} //绘制 + }; + for(var i in settings){ + _[i] = options[i]||settings[i]; + } +} +//游戏对象 +function Game(id,options){ + var _ = this; + var _settings = { + name:'Eat Beans', //游戏名称 + width:960, //画布宽度 + height:640, //画布高度 + map:{ //地图信息 + x:0, //地图起点坐标 + y:0, + size:20, //地图单元的宽度 + data:[] + }, + fresh:100, //画布刷新频率,一秒10帧 + audio:[], //音频资源 + images:[], //图片资源 + }; + for(i in options){ + _settings[i] = options[i]; + } + var $canvas = document.getElementById(id); + $canvas.width = _settings.width; + $canvas.height = _settings.height; + var _context = $canvas.getContext('2d'); //画布上下文环境 + var _items = []; //动画对象队列 + var _status = 0; //页面状态 + var _t = 0; //内部计算器,交替帧数更新动画 + var _hander = null; //画布更新 + + //开始画面 + this.launch = function(){ + _hander = setInterval(function(){ + _t++; + var s = _t%4; + //清除画布 + _context.clearRect(0,0,_settings.width,_settings.height); + //logo + _context.fillStyle = '#FC3'; + _context.beginPath(); + if(s<2){ + _context.arc(_settings.width/2,_settings.height*.45,50,.20*Math.PI,1.80*Math.PI,false); + _context.lineTo(_settings.width/2,_settings.height*.45); + }else{ + _context.arc(_settings.width/2,_settings.height*.45,50,.01*Math.PI,1.99*Math.PI,false); + _context.lineTo(_settings.width/2,_settings.height*.45); + } + _context.closePath(); + _context.fill(); + _context.fillStyle = '#000'; + _context.beginPath(); + _context.arc(_settings.width/2+5,_settings.height*.45-27,7,0,2*Math.PI,false); + _context.closePath(); + _context.fill(); + //游戏名 + _context.font = 'bold 42px Helvetica'; + _context.textAlign = 'center'; + _context.textBaseline = 'middle'; + _context.fillStyle = '#FFF'; + _context.fillText(_settings.name,_settings.width/2,_settings.height*.618); + },_settings.fresh); + }; + //动画停止 + this.stop = function(){ + _hander&&clearInterval(_hander); + }; + //动画开始 + this.start = function(){ + _.stop(); + _hander = setInterval(function(){ //定时刷新画布 + _t++; + _items.forEach(function(item,index){ + item.update(_t); + }); + },_settings.fresh); + }; + //添加对象 + this.addItem = function(item){ + _items.push(item); + }; + //条件嗅探 + this.render = function(){ + + }; + //绘图 + this.draw = function(){ + + }; +} \ No newline at end of file From b0f5969d39adc469ac041b8363bde98f9fa82a4b Mon Sep 17 00:00:00 2001 From: Haole Zheng Date: Thu, 31 Dec 2015 14:45:58 +0800 Subject: [PATCH 04/27] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 64f2658..a904476 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -# eatbeans -Eat Beans. 吃豆游戏 +# Pacman +Pacman. 吃豆游戏 + +building.... 项目建造中…… From 8f997ece4ca5585563429e2fb14fc9d2c356b0d8 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, 31 Dec 2015 14:52:52 +0800 Subject: [PATCH 05/27] =?UTF-8?q?updated=20=E8=A7=84=E8=8C=83=E6=B8=B8?= =?UTF-8?q?=E6=88=8F=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 2 +- pacman.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index b0e3a1f..92d84a9 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,7 @@ - Eat Beans - 吃豆游戏 + Pac-Man . 吃豆游戏 - Canvas not supported + Canvas not supported diff --git a/index.js b/index.js index 4c3694e..8ea3d9f 100644 --- a/index.js +++ b/index.js @@ -63,40 +63,47 @@ }); })(); //游戏主程序 - var map_data = [ - [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], - [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1], - [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], - [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], - [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], - [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], - [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], - [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], - [1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1], - [1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1], - [0,0,0,0,0,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,0,0,0,0,0], - [0,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0], - [0,0,0,0,0,1,0,1,1,0,1,1,1,0,0,1,1,1,0,1,1,0,1,0,0,0,0,0], - [1,1,1,1,1,1,0,1,1,0,1,0,0,0,0,0,0,1,0,1,1,0,1,1,1,1,1,1], - [0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0], - [1,1,1,1,1,1,0,1,1,0,1,0,0,0,0,0,0,1,0,1,1,0,1,1,1,1,1,1], - [0,0,0,0,0,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,0,0,0,0,0], - [0,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0], - [0,0,0,0,0,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,0,0,0,0,0], - [1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1], - [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1], - [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], - [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], - [1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1], - [1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1], - [1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1], - [1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1], - [1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1], - [1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1], - [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], - [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] -]; //地图数据 (function(){ + var MAP_ORIENTATION = { //地图方向 + '38':0, + '39':1, + '40':2, + '37':3 + }, + MAP_DATA = [ //地图数据 + [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], + [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1], + [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], + [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], + [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], + [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], + [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], + [1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1], + [1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1], + [1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1], + [0,0,0,0,0,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,0,0,0,0,0], + [0,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0], + [0,0,0,0,0,1,0,1,1,0,1,1,1,0,0,1,1,1,0,1,1,0,1,0,0,0,0,0], + [1,1,1,1,1,1,0,1,1,0,1,0,0,0,0,0,0,1,0,1,1,0,1,1,1,1,1,1], + [0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0], + [1,1,1,1,1,1,0,1,1,0,1,0,0,0,0,0,0,1,0,1,1,0,1,1,1,1,1,1], + [0,0,0,0,0,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,0,0,0,0,0], + [0,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0], + [0,0,0,0,0,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,0,0,0,0,0], + [1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1], + [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1], + [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], + [1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1], + [1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1], + [1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1], + [1,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1], + [1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1], + [1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1], + [1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1], + [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], + [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] + ], + MAP_SIZE = 20; //地图大小 var stage = game.createStage(); stage.bind('keydown',function(e){ switch(e.keyCode){ @@ -107,96 +114,95 @@ } }); //绘制地图 - stage.createMap({ - x:60, - y:15, - data:map_data, + var map = stage.createMap({ + x:50, + y:10, + data:MAP_DATA, draw:function(context){ - var x_length = this.data[0].length; var y_length = this.data.length; - for(var i=0; i Date: Mon, 4 Jan 2016 17:03:04 +0800 Subject: [PATCH 19/27] =?UTF-8?q?updated=20=E4=B8=BB=E8=A7=92=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 14 ++++++---- index.js | 83 +++++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 76 insertions(+), 21 deletions(-) diff --git a/game.js b/game.js index 55179ec..8e02983 100644 --- a/game.js +++ b/game.js @@ -36,6 +36,7 @@ function Game(id,options){ y:0 }, speed:1, //速度等级,内部计算器times多少帧变化一次 + control:{}, //控制缓存,到达定位点时处理 update:function(){}, //更新参数信息 draw:function(){} //绘制 }; @@ -83,17 +84,20 @@ function Game(id,options){ return -1; }; //地图坐标转画布坐标 - Map.prototype.coord2position = function(x,y){ + Map.prototype.coord2position = function(cx,cy){ return { - x:this.x+x*this.size+this.size/2, - y:this.y+y*this.size+this.size/2 + x:this.x+cx*this.size+this.size/2, + y:this.y+cy*this.size+this.size/2 }; }; //画布坐标转地图坐标 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; return { - x:Math.floor((x-this.x)/this.size-.5), - y:Math.floor((y-this.y)/this.size-.5) + x:Math.floor((x-this.x)/this.size), + y:Math.floor((y-this.y)/this.size), + offset:Math.sqrt(fx*fx+fy*fy) }; }; //布景对象构造器 diff --git a/index.js b/index.js index 8ea3d9f..b36b6bc 100644 --- a/index.js +++ b/index.js @@ -175,34 +175,32 @@ context.closePath(); break; default: - if(Math.floor(code/1000)){ + var arr = String.prototype.split.call(code,''); + if(+arr.pop()){ context.beginPath(); context.moveTo(pos.x,pos.y); - context.lineTo(pos.x,pos.y-this.size/2); + context.lineTo(pos.x-this.size/2,pos.y); context.stroke(); context.closePath(); } - code %= 1000; - if(Math.floor(code/100)){ - context.beginPath(); - context.moveTo(pos.x,pos.y); - context.lineTo(pos.x+this.size/2,pos.y); - context.stroke(); - context.closePath(); - } - code %= 100; - if(Math.floor(code/10)){ + if(+arr.pop()){ context.beginPath(); context.moveTo(pos.x,pos.y); context.lineTo(pos.x,pos.y+this.size/2); context.stroke(); context.closePath(); } - code %= 10; - if(Math.floor(code/1)){ + if(+arr.pop()){ context.beginPath(); context.moveTo(pos.x,pos.y); - context.lineTo(pos.x-this.size/2,pos.y); + context.lineTo(pos.x+this.size/2,pos.y); + context.stroke(); + context.closePath(); + } + if(+arr.pop()){ + context.beginPath(); + context.moveTo(pos.x,pos.y); + context.lineTo(pos.x,pos.y-this.size/2); context.stroke(); context.closePath(); } @@ -222,6 +220,59 @@ height:30, orientation:3, speed:10, + update:function(){ + var coord = map.position2coord(this.x,this.y); + var inPlace = !coord.offset; + if(inPlace){ + if(this.control.orientation){ + switch(this.control.orientation){ + case 0: + if(!map.get(coord.x,coord.y-1)){ + this.orientation = this.control.orientation; + } + break; + case 1: + if(!map.get(coord.x+1,coord.y)){ + this.orientation = this.control.orientation; + } + break; + case 2: + if(!map.get(coord.x,coord.y+1)){ + this.orientation = this.control.orientation; + } + break; + case 3: + if(!map.get(coord.x-1,coord.y)){ + this.orientation = this.control.orientation; + } + break; + } + } + this.control.orientation = null; + } + switch(this.orientation){ + case 0: + if(!(map.get(coord.x,coord.y-1)&&inPlace)){ + this.y-=1; + } + break; + case 1: + if(!(map.get(coord.x+1,coord.y)&&inPlace)){ + this.x+=1; + } + break; + case 2: + if(!(map.get(coord.x,coord.y+1)&&inPlace)){ + this.y+=1; + } + break; + case 3: + if(!(map.get(coord.x-1,coord.y)&&inPlace)){ + this.x-=1; + } + break; + } + }, draw:function(context){ context.fillStyle = '#FC3'; context.beginPath(); @@ -261,7 +312,7 @@ } }); stage.bind('keydown',function(e){ - player.orientation = MAP_ORIENTATION[e.keyCode]; + player.control = {orientation:MAP_ORIENTATION[e.keyCode]}; }); })(); game.init(); From 2b8b237a562860ce85fd2cae8042f813af8fb415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=B5=A9=E4=B9=90?= <89932980@qq.com> Date: Mon, 4 Jan 2016 17:10:29 +0800 Subject: [PATCH 20/27] =?UTF-8?q?updated=20=E6=96=B9=E5=90=91=E6=8E=A7?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b36b6bc..83797f7 100644 --- a/index.js +++ b/index.js @@ -224,7 +224,7 @@ var coord = map.position2coord(this.x,this.y); var inPlace = !coord.offset; if(inPlace){ - if(this.control.orientation){ + if(typeof this.control.orientation!='undefined'){ switch(this.control.orientation){ case 0: if(!map.get(coord.x,coord.y-1)){ @@ -248,7 +248,7 @@ break; } } - this.control.orientation = null; + this.control = {}; } switch(this.orientation){ case 0: From f01db8304a911f4e799e246c47dc5fc8c6998818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=B5=A9=E4=B9=90?= <89932980@qq.com> Date: Mon, 4 Jan 2016 18:01:06 +0800 Subject: [PATCH 21/27] =?UTF-8?q?updated=20=E6=B7=BB=E5=8A=A0=E5=9C=B0?= =?UTF-8?q?=E5=9B=BE=E7=A9=BF=E8=B6=8A=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 6 +++++ index.js | 79 +++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 59 insertions(+), 26 deletions(-) diff --git a/game.js b/game.js index 8e02983..453204a 100644 --- a/game.js +++ b/game.js @@ -69,6 +69,9 @@ function Game(id,options){ y:0, size:20, //地图单元的宽度 data:[], //地图数据 + stage:null, //布景 + x_length:0, //二维数组x轴长度 + y_length:0, //二维数组y轴长度 update:function(){}, //更新地图数据 draw:function(){}, //绘制地图 }; @@ -159,8 +162,11 @@ 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; return map; }; //绑定事件 diff --git a/index.js b/index.js index 83797f7..72fe8e5 100644 --- a/index.js +++ b/index.js @@ -121,8 +121,8 @@ draw:function(context){ var y_length = this.data.length; var x_length = this.data[0].length; - for(var j=0; j Date: Tue, 5 Jan 2016 11:17:49 +0800 Subject: [PATCH 22/27] =?UTF-8?q?updated=20=E7=BB=98=E5=88=B6=E5=87=BANPC?= =?UTF-8?q?=E5=BD=A2=E8=B1=A1=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=AF=BB=E5=BE=84?= =?UTF-8?q?=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 35 +++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/game.js b/game.js index 453204a..f1dc44b 100644 --- a/game.js +++ b/game.js @@ -57,6 +57,7 @@ function Game(id,options){ } } }); + e.preventDefault(); }); } _events[eventType]['s'+this.stage.index+'i'+this.index] = callback.bind(this); //绑定作用域 @@ -103,6 +104,68 @@ function Game(id,options){ offset:Math.sqrt(fx*fx+fy*fy) }; }; + //寻址算法 + Map.prototype.finder = function(param){ + var defaults = { + map :this.data, + start:[0,0], + end:[0,0] + }; + var options = (function(target, params) { + for (var prop in params) { + target[prop] = params[prop]; + } + return target; + })(defaults,param); + var result = []; + if(options.map[options.start[0]][options.start[1]]||options.map[options.end[0]][options.end[1]]){ //当起点或终点设置在墙上 + return []; + } + var finded = false; + var length_x = options.map.length; + var steps = new Array(length_x); //步骤的映射 + for(var x=length_x;x--;){ + var length_y = options.map[x].length; + steps[x] = new Array(length_y); + for(var y=length_y;y--;){ + steps[x][y] = 0; + } + } + (function(list){ + var new_list = []; + var next = function(from,to){ + var x = to[0],y = to[1]; + if(typeof steps[x]!= 'undefined'&&typeof steps[x][y] != 'undefined'&&!options.map[x][y]&&!finded){ //当前点是否可以走 + if(x==options.end[0]&&y==options.end[1]){ + steps[x][y] = from; + finded = true; + }else if(!steps[x][y]){ + steps[x][y] = from; + new_list.push(to); + } + } + }; + for(var i=0,len=list.length;i Date: Tue, 5 Jan 2016 18:00:22 +0800 Subject: [PATCH 23/27] =?UTF-8?q?updated=20=E5=86=85=E9=83=A8=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 29 +++++++++++++++++------------ index.js | 16 +++++++++++++--- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/game.js b/game.js index f1dc44b..65d2be0 100644 --- a/game.js +++ b/game.js @@ -28,15 +28,16 @@ function Game(id,options){ y:0, //纵坐标 width:20, //宽 height:20, //高 - type:1, //对象类型 + type:0, //对象类型,0表示普通对象(不与地图绑定),1表示玩家控制对象,2表示程序控制对象 status:1, //对象状态,1表示正常,0表示隐藏 orientation:0, //当前定位方向,0表示上,1表示右,2表示下,3表示左 - vector:{ //目标坐标 - x:0, - y:0 - }, + vector:{}, //目标坐标 + coord:{}, //如果对象与地图绑定,获得坐标值 speed:1, //速度等级,内部计算器times多少帧变化一次 control:{}, //控制缓存,到达定位点时处理 + path:[], //NPC自动行走的路径 + index:0, //对象索引 + stage:null, //绑定对象与所属布景绑定 update:function(){}, //更新参数信息 draw:function(){} //绘制 }; @@ -107,7 +108,7 @@ function Game(id,options){ //寻址算法 Map.prototype.finder = function(param){ var defaults = { - map :this.data, + map:this.data, start:[0,0], end:[0,0] }; @@ -131,7 +132,7 @@ function Game(id,options){ steps[x][y] = 0; } } - (function(list){ + var _render = function(list){ var new_list = []; var next = function(from,to){ var x = to[0],y = to[1]; @@ -154,9 +155,10 @@ function Game(id,options){ next(current,[x,y-1]); } if(!finded&&new_list.length){ - arguments.callee(new_list); + _render(new_list); } - })([options.start]); + }; + _render([options.start]); if(finded){ var current=options.end; while(current[0]!=options.start[0]||current[1]!=options.start[1]){ @@ -198,6 +200,9 @@ function Game(id,options){ if(!(f%item.speed)){ item.frames = f/item.speed; //计数器 } + if(stage.map&&item.type){ + item.coord = stage.map.position2coord(item.x,item.y); + } item.update(); } item.draw(_context); @@ -216,9 +221,9 @@ function Game(id,options){ //添加对象 Stage.prototype.createItem = function(options){ var item = new Item(options); - //对象动态属性 - item.stage = this; //绑定对象与所属布景绑定 - item.index = this.items.length; //对象层级 + //动态属性 + item.stage = this; + item.index = this.items.length; this.items.push(item); return item; }; diff --git a/index.js b/index.js index 25da65b..ade14aa 100644 --- a/index.js +++ b/index.js @@ -218,10 +218,11 @@ y:pos.y, width:30, height:30, + type:1, orientation:3, speed:10, update:function(){ - var coord = map.position2coord(this.x,this.y); + var coord = this.coord; var steps = 2; if(!coord.offset){ if(typeof this.control.orientation!='undefined'){ @@ -338,11 +339,20 @@ context.fill(); } }); + var pos = map.coord2position(12,14); stage.createItem({ - x:650, - y:100, + x:pos.x, + y:pos.y, width:30, height:30, + type:2, + speed:10, + update:function(){ + this.path = map.finder({ + start:[this.coord.y,this.coord.x], + end:[player.coord.y,player.coord.x] + }); + }, draw:function(context){ context.fillStyle = '#F00'; context.beginPath(); From 2b3d86f97904a3dea16b4742c6d611969ad5a01f 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 00:29:33 +0800 Subject: [PATCH 24/27] =?UTF-8?q?NPC=E8=B7=9F=E8=B8=AA=E8=A1=8C=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 49 ++++++++++++++++++++++++------------------------- index.js | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 29 deletions(-) diff --git a/game.js b/game.js index 65d2be0..03fd748 100644 --- a/game.js +++ b/game.js @@ -29,7 +29,7 @@ function Game(id,options){ width:20, //宽 height:20, //高 type:0, //对象类型,0表示普通对象(不与地图绑定),1表示玩家控制对象,2表示程序控制对象 - status:1, //对象状态,1表示正常,0表示隐藏 + status:1, //对象状态,1表示正常,0表示隐藏,2表示暂停 orientation:0, //当前定位方向,0表示上,1表示右,2表示下,3表示左 vector:{}, //目标坐标 coord:{}, //如果对象与地图绑定,获得坐标值 @@ -109,8 +109,8 @@ function Game(id,options){ Map.prototype.finder = function(param){ var defaults = { map:this.data, - start:[0,0], - end:[0,0] + start:{}, + end:{} }; var options = (function(target, params) { for (var prop in params) { @@ -119,40 +119,39 @@ function Game(id,options){ return target; })(defaults,param); var result = []; - if(options.map[options.start[0]][options.start[1]]||options.map[options.end[0]][options.end[1]]){ //当起点或终点设置在墙上 + if(options.map[options.start.y][options.start.x]||options.map[options.end.y][options.end.x]){ //当起点或终点设置在墙上 return []; } var finded = false; - var length_x = options.map.length; - var steps = new Array(length_x); //步骤的映射 - for(var x=length_x;x--;){ - var length_y = options.map[x].length; - steps[x] = new Array(length_y); - for(var y=length_y;y--;){ - steps[x][y] = 0; + var _self = this; + var y_length = options.map.length; + var x_length = options.map[0].length; + var steps = []; //步骤的映射 + for(var y=y_length;y--;){ + steps[y] = []; + for(var x=x_length;x--;){ + steps[y][x] = 0; } } var _render = function(list){ var new_list = []; var next = function(from,to){ - var x = to[0],y = to[1]; - if(typeof steps[x]!= 'undefined'&&typeof steps[x][y] != 'undefined'&&!options.map[x][y]&&!finded){ //当前点是否可以走 - if(x==options.end[0]&&y==options.end[1]){ - steps[x][y] = from; + if(_self.get(to.x,to.y)==0&&!finded){ //当前点是否可以走 + if(to.x==options.end.x&&to.y==options.end.y){ + steps[to.y][to.x] = from; finded = true; - }else if(!steps[x][y]){ - steps[x][y] = from; + }else if(!steps[to.y][to.x]){ + steps[to.y][to.x] = from; new_list.push(to); } } - }; + }; for(var i=0,len=list.length;ithis.coord.x){ + this.orientation = 1; + }else if(this.vector.xthis.coord.y){ + this.orientation = 2; + }else if(this.vector.y Date: Wed, 6 Jan 2016 10:49:38 +0800 Subject: [PATCH 25/27] =?UTF-8?q?updated=20=E9=83=A8=E5=88=86=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 8 +++++--- index.js | 44 ++++++++++++++++++++++---------------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/game.js b/game.js index 03fd748..94fb232 100644 --- a/game.js +++ b/game.js @@ -33,7 +33,9 @@ function Game(id,options){ orientation:0, //当前定位方向,0表示上,1表示右,2表示下,3表示左 vector:{}, //目标坐标 coord:{}, //如果对象与地图绑定,获得坐标值 - speed:1, //速度等级,内部计算器times多少帧变化一次 + speed:0, //移动速度 + frames:1, //速度等级,内部计算器times多少帧变化一次 + times:0, //计数 control:{}, //控制缓存,到达定位点时处理 path:[], //NPC自动行走的路径 index:0, //对象索引 @@ -196,8 +198,8 @@ function Game(id,options){ if(stage.items.length){ stage.items.forEach(function(item,index){ if(stage.status!=2&&item.status!=2){ //对象及布景状态不为暂停 - if(!(f%item.speed)){ - item.frames = f/item.speed; //计数器 + if(!(f%item.frames)){ + item.times = f/item.frames; //计数器 } if(stage.map&&item.type){ item.coord = stage.map.position2coord(item.x,item.y); diff --git a/index.js b/index.js index 7c50ba1..a28e13b 100644 --- a/index.js +++ b/index.js @@ -18,11 +18,11 @@ y:game.height*.45, width:100, height:100, - speed:10, + frames:10, draw:function(context){ context.fillStyle = '#FC3'; context.beginPath(); - if(this.frames%2){ + if(this.times%2){ context.arc(this.x,this.y,this.width/2,.20*Math.PI,1.80*Math.PI,false); }else{ context.arc(this.x,this.y,this.width/2,.01*Math.PI,1.99*Math.PI,false); @@ -220,10 +220,10 @@ height:30, type:1, orientation:3, - speed:10, + speed:2, + frames:10, update:function(){ var coord = this.coord; - var steps = 2; if(!coord.offset){ if(typeof this.control.orientation!='undefined'){ switch(this.control.orientation){ @@ -254,7 +254,7 @@ case 0: var value = map.get(coord.x,coord.y-1); if(value==0){ - this.y-=steps; + this.y-=this.speed; }else if(value<0){ this.y += map.size*(map.y_length-1); } @@ -262,7 +262,7 @@ case 1: var value = map.get(coord.x+1,coord.y); if(value==0){ - this.x+=steps; + this.x+=this.speed; }else if(value<0){ this.x -= map.size*(map.x_length-1); } @@ -270,7 +270,7 @@ case 2: var value = map.get(coord.x,coord.y+1); if(value==0){ - this.y+=steps; + this.y+=this.speed; }else if(value<0){ this.y -= map.size*(map.y_length-1); } @@ -278,7 +278,7 @@ case 3: var value = map.get(coord.x-1,coord.y); if(value==0){ - this.x-=steps; + this.x-=this.speed; }else if(value<0){ this.x += map.size*(map.x_length-1); } @@ -287,16 +287,16 @@ }else{ switch(this.orientation){ case 0: - this.y-=steps; + this.y-=this.speed; break; case 1: - this.x+=steps; + this.x+=this.speed; break; case 2: - this.y+=steps; + this.y+=this.speed; break; case 3: - this.x-=steps; + this.x-=this.speed; break; } } @@ -306,28 +306,28 @@ context.beginPath(); switch(this.orientation){ case 0: - if(this.frames%2){ + if(this.times%2){ context.arc(this.x,this.y,this.width/2,1.70*Math.PI,1.30*Math.PI,false); }else{ context.arc(this.x,this.y,this.width/2,1.51*Math.PI,1.49*Math.PI,false); } break; case 1: - if(this.frames%2){ + if(this.times%2){ context.arc(this.x,this.y,this.width/2,.20*Math.PI,1.80*Math.PI,false); }else{ context.arc(this.x,this.y,this.width/2,.01*Math.PI,1.99*Math.PI,false); } break; case 2: - if(this.frames%2){ + if(this.times%2){ context.arc(this.x,this.y,this.width/2,.70*Math.PI,.30*Math.PI,false); }else{ context.arc(this.x,this.y,this.width/2,.51*Math.PI,.49*Math.PI,false); } break; case 3: - if(this.frames%2){ + if(this.times%2){ context.arc(this.x,this.y,this.width/2,1.20*Math.PI,.80*Math.PI,false); }else{ context.arc(this.x,this.y,this.width/2,1.01*Math.PI,.99*Math.PI,false); @@ -346,7 +346,8 @@ width:30, height:30, type:2, - speed:10, + frames:10, + speed:1, update:function(){ if(!this.coord.offset){ this.path = map.finder({ @@ -366,19 +367,18 @@ this.orientation = 0; } } - var steps = 1; switch(this.orientation){ case 0: - this.y-=steps; + this.y-=this.speed; break; case 1: - this.x+=steps; + this.x+=this.speed; break; case 2: - this.y+=steps; + this.y+=this.speed; break; case 3: - this.x-=steps; + this.x-=this.speed; break; } }, From 6ad13f8bd40a57c6e4716175ce311ff454af9fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=B5=A9=E4=B9=90?= <89932980@qq.com> Date: Wed, 6 Jan 2016 14:27:25 +0800 Subject: [PATCH 26/27] =?UTF-8?q?updated=20=E5=AF=B9=E8=B1=A1=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E7=A9=BF=E8=B6=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 22 +++++++++++++------ index.js | 65 +++++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 68 insertions(+), 19 deletions(-) diff --git a/game.js b/game.js index 94fb232..1937fe6 100644 --- a/game.js +++ b/game.js @@ -138,13 +138,21 @@ function Game(id,options){ var _render = function(list){ var new_list = []; var next = function(from,to){ - if(_self.get(to.x,to.y)==0&&!finded){ //当前点是否可以走 - if(to.x==options.end.x&&to.y==options.end.y){ - steps[to.y][to.x] = from; - finded = true; - }else if(!steps[to.y][to.x]){ - steps[to.y][to.x] = from; - new_list.push(to); + if(!finded){ + var value = _self.get(to.x,to.y); + if(value!=1){ //当前点是否可以走 + if(value==-1){ + to.x = (to.x+x_length)%x_length; + to.y = (to.y+y_length)%y_length; + to.change = 1; + } + if(to.x==options.end.x&&to.y==options.end.y){ + steps[to.y][to.x] = from; + finded = true; + }else if(!steps[to.y][to.x]){ + steps[to.y][to.x] = from; + new_list.push(to); + } } } }; diff --git a/index.js b/index.js index a28e13b..db3ccff 100644 --- a/index.js +++ b/index.js @@ -356,6 +356,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.x>this.coord.x){ this.orientation = 1; @@ -386,10 +393,19 @@ context.fillStyle = '#F00'; context.beginPath(); context.arc(this.x,this.y,this.width*.5,0,Math.PI,true); - context.lineTo(this.x-this.width*.5,this.y+this.height*.4); - context.quadraticCurveTo(this.x-this.width*.4,this.y+this.height*.5,this.x-this.width*.2,this.y+this.height*.3); - context.quadraticCurveTo(this.x,this.y+this.height*.5,this.x+this.width*.2,this.y+this.height*.3); - context.quadraticCurveTo(this.x+this.width*.4,this.y+this.height*.5,this.x+this.width*.5,this.y+this.height*.4); + switch(this.times%2){ + case 0: + context.lineTo(this.x-this.width*.5,this.y+this.height*.4); + context.quadraticCurveTo(this.x-this.width*.4,this.y+this.height*.5,this.x-this.width*.2,this.y+this.height*.3); + context.quadraticCurveTo(this.x,this.y+this.height*.5,this.x+this.width*.2,this.y+this.height*.3); + context.quadraticCurveTo(this.x+this.width*.4,this.y+this.height*.5,this.x+this.width*.5,this.y+this.height*.4); + break; + case 1: + context.lineTo(this.x-this.width*.5,this.y+this.height*.3); + context.quadraticCurveTo(this.x-this.width*.25,this.y+this.height*.5,this.x,this.y+this.height*.3); + context.quadraticCurveTo(this.x+this.width*.25,this.y+this.height*.5,this.x+this.width*.5,this.y+this.height*.3); + break; + } context.fill(); context.closePath(); context.fillStyle = '#FFF'; @@ -402,14 +418,39 @@ context.fill(); context.closePath(); context.fillStyle = '#00F'; - context.beginPath(); - context.arc(this.x-this.width*.15,this.y-this.height*.28,this.width*.07,0,2*Math.PI,false); - context.fill(); - context.closePath(); - context.beginPath(); - context.arc(this.x+this.width*.15,this.y-this.height*.28,this.width*.07,0,2*Math.PI,false); - context.fill(); - context.closePath(); + switch(this.times%4){ + case 2: + case 0: + context.beginPath(); + context.arc(this.x-this.width*.15,this.y-this.height*.27,this.width*.07,0,2*Math.PI,false); + context.fill(); + context.closePath(); + context.beginPath(); + context.arc(this.x+this.width*.15,this.y-this.height*.27,this.width*.07,0,2*Math.PI,false); + context.fill(); + context.closePath(); + break; + case 1: + context.beginPath(); + context.arc(this.x-this.width*.17,this.y-this.height*.25,this.width*.07,0,2*Math.PI,false); + context.fill(); + context.closePath(); + context.beginPath(); + context.arc(this.x+this.width*.13,this.y-this.height*.25,this.width*.07,0,2*Math.PI,false); + context.fill(); + context.closePath(); + break; + case 3: + context.beginPath(); + context.arc(this.x-this.width*.13,this.y-this.height*.25,this.width*.07,0,2*Math.PI,false); + context.fill(); + context.closePath(); + context.beginPath(); + context.arc(this.x+this.width*.17,this.y-this.height*.25,this.width*.07,0,2*Math.PI,false); + context.fill(); + context.closePath(); + break; + } } }); stage.bind('keydown',function(e){ From ec1289d3f4d94caf5c889c0b3bd1558ac5fdfe77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=B5=A9=E4=B9=90?= <89932980@qq.com> Date: Wed, 6 Jan 2016 16:12:22 +0800 Subject: [PATCH 27/27] =?UTF-8?q?updated=20=E6=B7=BB=E5=8A=A04=E4=B8=AANPC?= =?UTF-8?q?=E8=A7=92=E8=89=B2=EF=BC=8C=E5=AE=9E=E7=8E=B0=E5=A4=9ANPC?= =?UTF-8?q?=E5=8C=85=E6=8A=84=E7=8E=A9=E5=AE=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 20 ++++- index.js | 240 ++++++++++++++++++++++++++++++------------------------- 2 files changed, 146 insertions(+), 114 deletions(-) diff --git a/game.js b/game.js index 1937fe6..62453e3 100644 --- a/game.js +++ b/game.js @@ -29,6 +29,7 @@ function Game(id,options){ width:20, //宽 height:20, //高 type:0, //对象类型,0表示普通对象(不与地图绑定),1表示玩家控制对象,2表示程序控制对象 + color:'#F00', //标识颜色 status:1, //对象状态,1表示正常,0表示隐藏,2表示暂停 orientation:0, //当前定位方向,0表示上,1表示右,2表示下,3表示左 vector:{}, //目标坐标 @@ -110,7 +111,7 @@ function Game(id,options){ //寻址算法 Map.prototype.finder = function(param){ var defaults = { - map:this.data, + map:null,//this.data, start:{}, end:{} }; @@ -125,7 +126,6 @@ function Game(id,options){ return []; } var finded = false; - var _self = this; var y_length = options.map.length; var x_length = options.map[0].length; var steps = []; //步骤的映射 @@ -139,7 +139,7 @@ function Game(id,options){ var new_list = []; var next = function(from,to){ if(!finded){ - var value = _self.get(to.x,to.y); + var value = 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; @@ -190,7 +190,7 @@ function Game(id,options){ for(var i in settings){ this[i] = options[i]||settings[i]; } - } + }; //动画开始 Stage.prototype.start = function() { var requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame ||window.mozRequestAnimationFrame ||window.msRequestAnimationFrame; @@ -233,9 +233,21 @@ 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); + } this.items.push(item); return item; }; + //获取对象列表 + Stage.prototype.getItemsByType = function(type){ + var items = this.items.filter(function(item){ + if(item.type==type){ + return item; + } + }); + return items; + }; //添加地图 Stage.prototype.createMap = function(options){ var map = new Map(options); diff --git a/index.js b/index.js index db3ccff..2c20a55 100644 --- a/index.js +++ b/index.js @@ -339,120 +339,140 @@ context.fill(); } }); - var pos = map.coord2position(12,14); - stage.createItem({ - x:pos.x, - y:pos.y, - width:30, - height:30, - type:2, - frames:10, - speed:1, - update:function(){ - if(!this.coord.offset){ - this.path = map.finder({ - start:this.coord, - end:player.coord - }); - 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; + var NPC_COLOR = ['#96F','#6C6','#C30','#3C9']; + for(var i=0;i<4;i++){ + var pos = map.coord2position(12+i,14); + stage.createItem({ + x:pos.x, + y:pos.y, + width:30, + height:30, + color:NPC_COLOR[i], + type:2, + frames:10, + speed:1, + update:function(){ + if(!this.coord.offset){ + var new_map = []; + for(var j=0;jthis.coord.x){ + this.orientation = 1; + }else if(this.vector.xthis.coord.y){ + this.orientation = 2; + }else if(this.vector.ythis.coord.x){ - this.orientation = 1; - }else if(this.vector.xthis.coord.y){ - this.orientation = 2; - }else if(this.vector.y