From 99f8b482d2db839565373f547df08e9a74617856 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 10:49:38 +0800 Subject: [PATCH] =?UTF-8?q?updated=20=E9=83=A8=E5=88=86=E5=8F=82=E6=95=B0?= =?UTF-8?q?=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; } },