var yd={yibu1:0,yibu2:0,evx:0,evy:0,oldx:0,oldy:0,haomiao:40,guijix:[],guijiy:[],guijiyoubiao:0,guijiyoubiao2:0,
zhenx:1,zheny:7,jiange:1,
key1:"",key2:"",jptime:null,zt:"走路",

npcmove:function(obj){  //npc,怪移动
obj.dong=setInterval(function(){
if(winload==false||--obj.tingdun>0)return;
if(zd.zdzhong)return;
if(obj.bushu==null||++obj.bushu>obj.bushumax){
obj.bushu=0;obj.bushumax=round(random()*100)
obj.xjiajian=random()>0.5?true:false;obj.yjiajian=random()>0.5?true:false;
obj.tingdun=round(random()*30);var rn1=random();
if(rn1>0.66){obj.leftortop="斜"}else if(rn1>0.33){obj.leftortop="左"}else{obj.leftortop="上"}
obj.xsudu=3+round(random()*6);obj.ysudu=3+round(random()*6);return;
}
var varx=obj.xjiajian==true?obj.offsetLeft+obj.xsudu:obj.offsetLeft-obj.xsudu;
var vary=obj.yjiajian==true?obj.offsetTop+obj.ysudu:obj.offsetTop-obj.ysudu;
if(varx<obj.zuobi||varx>obj.youbi||vary<obj.shangbi||vary>obj.xiabi)return obj.bushu=obj.bushumax+1;
if(obj.leftortop=="左")return obj.style.left=varx
if(obj.leftortop=="上")return obj.style.top=vary
if(obj.leftortop=="斜"){obj.style.left=varx;obj.style.top=vary}
},60)
},
keymove:function(whatzhi,obj){  //键盘移动
if(yd.key1==""){yd.key1=whatzhi}
else if(yd.key2==""){yd.key2=whatzhi}
else if(yd.key1!=whatzhi&&yd.key2!=whatzhi){yd.key2=whatzhi}yd.cle();
var useyd=rpg.yd+rpg.yd2,x2=0,y2=0;
if(yd.key1=="上"||yd.key2=="上"){y2=-useyd;yd.zheny=7}
if(yd.key1=="下"||yd.key2=="下"){y2=useyd;yd.zheny=10}
if(yd.key1=="左"||yd.key2=="左"){x2=-useyd;yd.zheny=8}
if(yd.key1=="右"||yd.key2=="右"){x2=useyd;yd.zheny=9}
if((yd.key1=="左"||yd.key2=="左")&&(yd.key1=="下"||yd.key2=="下")){yd.zheny=11}
else if((yd.key1=="右"||yd.key2=="右")&&(yd.key1=="下"||yd.key2=="下"))yd.zheny=12
yd.jptime=setInterval(function(){
yd.oldx=mex;yd.oldy=mey;var tempmex=x2+yd.oldx;tempmey=y2+yd.oldy;
if(xunlu.jisuan(tempmex,tempmey,x2,y2)==false)return yd.cle();
fmleft-=x2;fmtop-=y2;fm1.style.left=fmleft;fm1.style.top=fmtop
mex=tempmex;mey=tempmey;obj.style.left=mex;obj.style.top=mey
yd.ying();if(++me.jiange>yd.jiange){me.jiange=0;yd.clips()}
zd.tance();},yd.haomiao);
},
cle:function(){  //重置,或打住处理
yd.zheny>6?yd.zheny-=6:yd.zheny=1;
if(yd.jptime!=null){clearInterval(yd.jptime);yd.jptime=null}
if(time1!=null){  //当鼠标弹起
clearInterval(time1);time1=null;yd.yibu1=0;yd.yibu2=0;
}},
clips:function(){  //png流
yd.zhenx<6?yd.zhenx++:yd.zhenx=1;
if(!zd.zdzhong)me.style.backgroundPosition=(-yd.zhenx+1)*mewid+" "+(-yd.zheny+1)*mehei;
me2.style.backgroundPosition=me.style.backgroundPosition
},
ying:function(){  //影
ying.style.left=mewid/2+mex-(ying.offsetWidth/2);
if(yd.zt=="飞行"){ying.style.top=mehei+mey-(ying.offsetHeight/2)+10}
else{ying.style.top=mehei+mey-(ying.offsetHeight/2)-15}

if(++me.jiange>yd.jiange){me.jiange=0;yd.clips();}
if(++yd.guijiyoubiao>2000){yd.guijiyoubiao2=0;yd.guijiyoubiao=0;}
yd.guijix[yd.guijiyoubiao]=mex;yd.guijiy[yd.guijiyoubiao]=mey

if(yd.guijiyoubiao2+20<yd.guijiyoubiao){++yd.guijiyoubiao2;
var tempbiao=yd.guijiyoubiao>10?yd.guijiyoubiao-10:0;
me2.style.left=yd.guijix[tempbiao];me2.style.top=yd.guijiy[tempbiao];
me3.style.left=yd.guijix[yd.guijiyoubiao2];me3.style.top=yd.guijiy[yd.guijiyoubiao2];
}
switch(yd.zheny){
case 8:me2.style.zIndex=6;me3.style.zIndex=7;break;   //左上
case 11:me2.style.zIndex=4;me3.style.zIndex=3;break;   //左下
case 9:me2.style.zIndex=6;me3.style.zIndex=7;break;   //右上
case 12:me2.style.zIndex=4;me3.style.zIndex=3;break;   //右下
case 7:me2.style.zIndex=6;me3.style.zIndex=7;break;   //上
case 10:me2.style.zIndex=4;me3.style.zIndex=3;break;   //下
}
},
ck:function(obj){  //RPG ck
var useyd=rpg.yd+rpg.yd2;
try{if(document.selection.type!="none"){document.selection.empty();lttext.blur()}}catch(e){}
yd.cle();
var newx=yd.evx-55,newy=yd.evy>yd.oldy?yd.evy-95:yd.evy-110;yd.oldx=mex;yd.oldy=mey
fm1.oldleft=fmleft;fm1.oldtop=fmtop;  //新算法
var x1=$(newx-yd.oldx),y1=$(newy-yd.oldy)
if(x1==0||y1==0)return;
if(y1>x1){var x2=useyd/(y1/(newx-yd.oldx));yd.yibu2=$(x1/x2);newy-yd.oldy>0?y2=useyd:y2=-useyd;}
else{var y2=useyd/(x1/(newy-yd.oldy));yd.yibu2=$(y1/y2);newx-yd.oldx>0?x2=useyd:x2=-useyd;}
var su2=useyd/4;yd.zheny=x2<-su2&&y2<-su2?8: //左上
x2<-su2&&y2>su2?11:  //左下
x2>su2&&y2<-su2?9:  //右上
x2>su2&&y2>su2?12:  //右下
x2<0&&$(y2)<su2?8:  //左
x2>0&&$(y2)<su2?9:  //右
$(x2)<su2&&y2<0?7:10 //4=下,1=上
x2=round(x2);y2=round(y2)
yd.clips();time1=setInterval(function(){yd.move(obj,x2,y2)},yd.haomiao)
},
move:function(obj,x2,y2){  //RPG move
if(ckin){yd.evx+=x2;yd.evy+=y2}  //连运
if(++yd.yibu1>yd.yibu2){if(me.fmwp!=null)me.fmwp.onmousedown();return yd.cle()};
var tempmex=x2*yd.yibu1+yd.oldx;tempmey=y2*yd.yibu1+yd.oldy;
try{if(xunlu.jisuan(tempmex,tempmey,x2,y2)==false)return yd.cle();}catch(e){  //这里加try,完全为了将来制作官网主页,iframe嵌套游戏时不出错,否则可去除
}

fmleft=fm1.oldleft-(tempmex-yd.oldx);fmtop=fm1.oldtop-(tempmey-yd.oldy);  //新,略带影晕晃动效果
fm1.style.left=fmleft;fm1.style.top=fmtop
mex=tempmex;mey=tempmey;obj.style.left=mex;obj.style.top=mey
yd.ying();
zd.tance();
}
}  //json yd over.