updated 部分参数修改

This commit is contained in:
郑浩乐 2016-01-06 10:49:38 +08:00
parent 2b3d86f979
commit 99f8b482d2
2 changed files with 27 additions and 25 deletions

View File

@ -33,7 +33,9 @@ function Game(id,options){
orientation:0, //当前定位方向,0表示上,1表示右,2表示下,3表示左 orientation:0, //当前定位方向,0表示上,1表示右,2表示下,3表示左
vector:{}, //目标坐标 vector:{}, //目标坐标
coord:{}, //如果对象与地图绑定,获得坐标值 coord:{}, //如果对象与地图绑定,获得坐标值
speed:1, //速度等级,内部计算器times多少帧变化一次 speed:0, //移动速度
frames:1, //速度等级,内部计算器times多少帧变化一次
times:0, //计数
control:{}, //控制缓存,到达定位点时处理 control:{}, //控制缓存,到达定位点时处理
path:[], //NPC自动行走的路径 path:[], //NPC自动行走的路径
index:0, //对象索引 index:0, //对象索引
@ -196,8 +198,8 @@ function Game(id,options){
if(stage.items.length){ if(stage.items.length){
stage.items.forEach(function(item,index){ stage.items.forEach(function(item,index){
if(stage.status!=2&&item.status!=2){ //对象及布景状态不为暂停 if(stage.status!=2&&item.status!=2){ //对象及布景状态不为暂停
if(!(f%item.speed)){ if(!(f%item.frames)){
item.frames = f/item.speed; //计数器 item.times = f/item.frames; //计数器
} }
if(stage.map&&item.type){ if(stage.map&&item.type){
item.coord = stage.map.position2coord(item.x,item.y); item.coord = stage.map.position2coord(item.x,item.y);

View File

@ -18,11 +18,11 @@
y:game.height*.45, y:game.height*.45,
width:100, width:100,
height:100, height:100,
speed:10, frames:10,
draw:function(context){ draw:function(context){
context.fillStyle = '#FC3'; context.fillStyle = '#FC3';
context.beginPath(); 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); context.arc(this.x,this.y,this.width/2,.20*Math.PI,1.80*Math.PI,false);
}else{ }else{
context.arc(this.x,this.y,this.width/2,.01*Math.PI,1.99*Math.PI,false); context.arc(this.x,this.y,this.width/2,.01*Math.PI,1.99*Math.PI,false);
@ -220,10 +220,10 @@
height:30, height:30,
type:1, type:1,
orientation:3, orientation:3,
speed:10, speed:2,
frames:10,
update:function(){ update:function(){
var coord = this.coord; var coord = this.coord;
var steps = 2;
if(!coord.offset){ if(!coord.offset){
if(typeof this.control.orientation!='undefined'){ if(typeof this.control.orientation!='undefined'){
switch(this.control.orientation){ switch(this.control.orientation){
@ -254,7 +254,7 @@
case 0: case 0:
var value = map.get(coord.x,coord.y-1); var value = map.get(coord.x,coord.y-1);
if(value==0){ if(value==0){
this.y-=steps; this.y-=this.speed;
}else if(value<0){ }else if(value<0){
this.y += map.size*(map.y_length-1); this.y += map.size*(map.y_length-1);
} }
@ -262,7 +262,7 @@
case 1: case 1:
var value = map.get(coord.x+1,coord.y); var value = map.get(coord.x+1,coord.y);
if(value==0){ if(value==0){
this.x+=steps; this.x+=this.speed;
}else if(value<0){ }else if(value<0){
this.x -= map.size*(map.x_length-1); this.x -= map.size*(map.x_length-1);
} }
@ -270,7 +270,7 @@
case 2: case 2:
var value = map.get(coord.x,coord.y+1); var value = map.get(coord.x,coord.y+1);
if(value==0){ if(value==0){
this.y+=steps; this.y+=this.speed;
}else if(value<0){ }else if(value<0){
this.y -= map.size*(map.y_length-1); this.y -= map.size*(map.y_length-1);
} }
@ -278,7 +278,7 @@
case 3: case 3:
var value = map.get(coord.x-1,coord.y); var value = map.get(coord.x-1,coord.y);
if(value==0){ if(value==0){
this.x-=steps; this.x-=this.speed;
}else if(value<0){ }else if(value<0){
this.x += map.size*(map.x_length-1); this.x += map.size*(map.x_length-1);
} }
@ -287,16 +287,16 @@
}else{ }else{
switch(this.orientation){ switch(this.orientation){
case 0: case 0:
this.y-=steps; this.y-=this.speed;
break; break;
case 1: case 1:
this.x+=steps; this.x+=this.speed;
break; break;
case 2: case 2:
this.y+=steps; this.y+=this.speed;
break; break;
case 3: case 3:
this.x-=steps; this.x-=this.speed;
break; break;
} }
} }
@ -306,28 +306,28 @@
context.beginPath(); context.beginPath();
switch(this.orientation){ switch(this.orientation){
case 0: 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); context.arc(this.x,this.y,this.width/2,1.70*Math.PI,1.30*Math.PI,false);
}else{ }else{
context.arc(this.x,this.y,this.width/2,1.51*Math.PI,1.49*Math.PI,false); context.arc(this.x,this.y,this.width/2,1.51*Math.PI,1.49*Math.PI,false);
} }
break; break;
case 1: 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); context.arc(this.x,this.y,this.width/2,.20*Math.PI,1.80*Math.PI,false);
}else{ }else{
context.arc(this.x,this.y,this.width/2,.01*Math.PI,1.99*Math.PI,false); context.arc(this.x,this.y,this.width/2,.01*Math.PI,1.99*Math.PI,false);
} }
break; break;
case 2: 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); context.arc(this.x,this.y,this.width/2,.70*Math.PI,.30*Math.PI,false);
}else{ }else{
context.arc(this.x,this.y,this.width/2,.51*Math.PI,.49*Math.PI,false); context.arc(this.x,this.y,this.width/2,.51*Math.PI,.49*Math.PI,false);
} }
break; break;
case 3: 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); context.arc(this.x,this.y,this.width/2,1.20*Math.PI,.80*Math.PI,false);
}else{ }else{
context.arc(this.x,this.y,this.width/2,1.01*Math.PI,.99*Math.PI,false); context.arc(this.x,this.y,this.width/2,1.01*Math.PI,.99*Math.PI,false);
@ -346,7 +346,8 @@
width:30, width:30,
height:30, height:30,
type:2, type:2,
speed:10, frames:10,
speed:1,
update:function(){ update:function(){
if(!this.coord.offset){ if(!this.coord.offset){
this.path = map.finder({ this.path = map.finder({
@ -366,19 +367,18 @@
this.orientation = 0; this.orientation = 0;
} }
} }
var steps = 1;
switch(this.orientation){ switch(this.orientation){
case 0: case 0:
this.y-=steps; this.y-=this.speed;
break; break;
case 1: case 1:
this.x+=steps; this.x+=this.speed;
break; break;
case 2: case 2:
this.y+=steps; this.y+=this.speed;
break; break;
case 3: case 3:
this.x-=steps; this.x-=this.speed;
break; break;
} }
}, },