Async move & jump

This commit is contained in:
ckcz123 2018-11-30 21:14:14 +08:00
parent 52f311ce58
commit cbbd973357
4 changed files with 79 additions and 69 deletions

View File

@ -1084,45 +1084,48 @@ return code;
*/;
move_s
: '移动事件' 'x' PosString? ',' 'y' PosString? '动画时间' Int? '不消失' Bool BGNL? StepString Newline
: '移动事件' 'x' PosString? ',' 'y' PosString? '动画时间' Int? '不消失' Bool '不等待执行完毕' Bool BGNL? StepString Newline
/* move_s
tooltip : move: 让某个NPC/怪物移动,位置可不填代表当前事件
helpUrl : https://h5mota.com/games/template/docs/#/event?id=move%EF%BC%9A%E8%AE%A9%E6%9F%90%E4%B8%AAnpc%E6%80%AA%E7%89%A9%E7%A7%BB%E5%8A%A8
default : ["","",500,false,"上右3下2左上左2"]
default : ["","",500,false,false,"上右3下2左上左2"]
colour : this.eventColor
var floorstr = '';
if (PosString_0 && PosString_1) {
floorstr = ', "loc": ['+PosString_0+','+PosString_1+']';
}
Int_0 = Int_0 ?(', "time": '+Int_0):'';
var code = '{"type": "move"'+floorstr+''+Int_0+', "steps": '+JSON.stringify(StepString_0)+', "keep": '+Bool_0+'},\n';
Bool_0 = Bool_0?', "keep": true':'';
Bool_1 = Bool_1?', "async": true':'';
var code = '{"type": "move"'+floorstr+Int_0+Bool_0+Bool_1+', "steps": '+JSON.stringify(StepString_0)+'},\n';
return code;
*/;
moveHero_s
: '移动勇士' '动画时间' Int? BGNL? StepString Newline
: '移动勇士' '动画时间' Int? '不等待执行完毕' Bool BGNL? StepString Newline
/* moveHero_s
tooltip : moveHero移动勇士,用这种方式移动勇士的过程中将无视一切地形, 无视一切事件, 中毒状态也不会扣血
helpUrl : https://h5mota.com/games/template/docs/#/event?id=movehero%EF%BC%9A%E7%A7%BB%E5%8A%A8%E5%8B%87%E5%A3%AB
default : [500,"上右3下2左上左2"]
default : [500,false,"上右3下2左上左2"]
colour : this.dataColor
Int_0 = Int_0 ?(', "time": '+Int_0):'';
var code = '{"type": "moveHero"'+Int_0+', "steps": '+JSON.stringify(StepString_0)+'},\n';
Bool_0 = Bool_0?', "async": true':'';
var code = '{"type": "moveHero"'+Int_0+Bool_0+', "steps": '+JSON.stringify(StepString_0)+'},\n';
return code;
*/;
jump_s
: '跳跃事件' '起始 x' PosString? ',' 'y' PosString? '终止 x' PosString? ',' 'y' PosString? '动画时间' Int? '不消失' Bool Newline
: '跳跃事件' '起始 x' PosString? ',' 'y' PosString? '终止 x' PosString? ',' 'y' PosString? '动画时间' Int? '不消失' Bool '不等待执行完毕' Bool Newline
/* jump_s
tooltip : jump: 让某个NPC/怪物跳跃
helpUrl : https://h5mota.com/games/template/docs/#/event?id=jump%EF%BC%9A%E8%AE%A9%E6%9F%90%E4%B8%AANPC%2F%E6%80%AA%E7%89%A9%E8%B7%B3%E8%B7%83
default : ["","","","",500,true]
default : ["","","","",500,true,false]
colour : this.eventColor
var floorstr = '';
if (PosString_0 && PosString_1) {
@ -1132,25 +1135,28 @@ if (PosString_2 && PosString_3) {
floorstr += ', "to": ['+PosString_2+','+PosString_3+']';
}
Int_0 = Int_0 ?(', "time": '+Int_0):'';
var code = '{"type": "jump"'+floorstr+''+Int_0+', "keep": '+Bool_0+'},\n';
Bool_0 = Bool_0?', "keep": true':'';
Bool_1 = Bool_1?', "async": true':'';
var code = '{"type": "jump"'+floorstr+''+Int_0+Bool_0+Bool_1+'},\n';
return code;
*/;
jumpHero_s
: '跳跃勇士' 'x' PosString? ',' 'y' PosString? '动画时间' Int? Newline
: '跳跃勇士' 'x' PosString? ',' 'y' PosString? '动画时间' Int? '不等待执行完毕' Bool Newline
/* jumpHero_s
tooltip : jumpHero: 跳跃勇士
helpUrl : https://h5mota.com/games/template/docs/#/event?id=jumpHero%EF%BC%9A%E8%B7%B3%E8%B7%83%E5%8B%87%E5%A3%AB
default : ["","",500]
default : ["","",500,false]
colour : this.dataColor
var floorstr = '';
if (PosString_0 && PosString_1) {
floorstr = ', "loc": ['+PosString_0+','+PosString_1+']';
}
Int_0 = Int_0 ?(', "time": '+Int_0):'';
var code = '{"type": "jumpHero"'+floorstr+Int_0+'},\n';
Bool_0 = Bool_0?', "async": true':'';
var code = '{"type": "jumpHero"'+floorstr+Int_0+Bool_0+'},\n';
return code;
*/;
@ -1910,22 +1916,22 @@ ActionParser.prototype.parseAction = function() {
case "move": // 移动事件
data.loc=data.loc||['',''];
this.next = MotaActionBlocks['move_s'].xmlText([
data.loc[0],data.loc[1],data.time||0,data.keep,this.StepString(data.steps),this.next]);
data.loc[0],data.loc[1],data.time||0,data.keep||false,data.async||false,this.StepString(data.steps),this.next]);
break;
case "moveHero":
this.next = MotaActionBlocks['moveHero_s'].xmlText([
data.time||0,this.StepString(data.steps),this.next]);
data.time||0,data.async||false,this.StepString(data.steps),this.next]);
break;
case "jump": // 跳跃事件
data.from=data.from||['',''];
data.to=data.to||['',''];
this.next = MotaActionBlocks['jump_s'].xmlText([
data.from[0],data.from[1],data.to[0],data.to[1],data.time||0,data.keep,this.next]);
data.from[0],data.from[1],data.to[0],data.to[1],data.time||0,data.keep||false,data.async||false,this.next]);
break;
case "jumpHero": // 跳跃勇士
data.loc=data.loc||['','']
this.next = MotaActionBlocks['jumpHero_s'].xmlText([
data.loc[0],data.loc[1],data.time||0,this.next]);
data.loc[0],data.loc[1],data.time||0,data.async||false,this.next]);
break;
case "changeFloor": // 楼层转换
data.loc=data.loc||['','']

View File

@ -832,12 +832,8 @@ control.prototype.moveHero = function (direction, callback) {
/////// 使用事件让勇士移动。这个函数将不会触发任何事件 //////
control.prototype.eventMoveHero = function(steps, time, callback) {
time = time || 100;
core.clearMap('ui');
core.setAlpha('ui', 1.0);
// 要运行的轨迹将steps展开
var moveSteps=[];
steps.forEach(function (e) {
@ -864,14 +860,11 @@ control.prototype.eventMoveHero = function(steps, time, callback) {
'right': {'x': 1, 'y': 0}
};
// core.status.replay.animate=true;
var animate=window.setInterval(function() {
var x=core.getHeroLoc('x'), y=core.getHeroLoc('y');
if (moveSteps.length==0) {
clearInterval(animate);
core.drawHero(null, x, y);
// core.status.replay.animate=false;
if (core.isset(callback)) callback();
}
else {
@ -902,9 +895,6 @@ control.prototype.jumpHero = function (ex, ey, time, callback) {
if (!core.isset(ey)) ey=sy;
time = time || 500;
core.clearMap('ui');
core.setAlpha('ui', 1.0);
// core.status.replay.animate=true;
core.playSound('jump.mp3');
@ -954,7 +944,6 @@ control.prototype.jumpHero = function (ex, ey, time, callback) {
core.setHeroLoc('x', ex);
core.setHeroLoc('y', ey);
core.drawHero();
// core.status.replay.animate=false;
if (core.isset(callback)) callback();
}

View File

@ -598,14 +598,26 @@ events.prototype.doAction = function() {
x=core.calValue(data.loc[0]);
y=core.calValue(data.loc[1]);
}
core.moveBlock(x,y,data.steps,data.time,data.keep,function() {
core.events.doAction();
})
if (data.async) {
core.moveBlock(x,y,data.steps,data.time,data.keep);
this.doAction();
}
else {
core.moveBlock(x,y,data.steps,data.time,data.keep,function() {
core.events.doAction();
})
}
break;
case "moveHero":
core.eventMoveHero(data.steps,data.time,function() {
core.events.doAction();
});
if (data.async) {
core.eventMoveHero(data.steps, data.time);
this.doAction();
}
else {
core.eventMoveHero(data.steps,data.time,function() {
core.events.doAction();
});
}
break;
case "jump": // 跳跃事件
{
@ -618,9 +630,15 @@ events.prototype.doAction = function() {
ex=core.calValue(data.to[0]);
ey=core.calValue(data.to[1]);
}
core.jumpBlock(sx,sy,ex,ey,data.time,data.keep,function() {
core.events.doAction();
});
if (data.async) {
core.jumpBlock(sx,sy,ex,ey,data.time,data.keep);
this.doAction();
}
else {
core.jumpBlock(sx,sy,ex,ey,data.time,data.keep,function() {
core.events.doAction();
});
}
break;
}
case "jumpHero":
@ -630,9 +648,15 @@ events.prototype.doAction = function() {
ex=core.calValue(data.loc[0]);
ey=core.calValue(data.loc[1]);
}
core.jumpHero(ex,ey,data.time,function() {
core.events.doAction();
});
if (data.async) {
core.jumpHero(ex,ey,data.time);
this.doAction();
}
else {
core.jumpHero(ex,ey,data.time,function() {
core.events.doAction();
});
}
break;
}
case "changeFloor": // 楼层转换

View File

@ -738,8 +738,6 @@ maps.prototype.getBlockCls = function (x, y, floorId, showDisable) {
maps.prototype.moveBlock = function(x,y,steps,time,keep,callback) {
time = time || 500;
core.clearMap('route');
var block = core.getBlock(x,y);
if (block==null) {// 不存在
if (core.isset(callback)) callback();
@ -747,14 +745,9 @@ maps.prototype.moveBlock = function(x,y,steps,time,keep,callback) {
}
var id = block.block.id;
// core.status.replay.animate=true;
// 需要删除该块
core.removeBlock(x,y);
core.clearMap('ui');
core.setAlpha('ui', 1.0);
block=block.block;
var image, bx, by, height = block.event.height || 32;
@ -786,8 +779,8 @@ maps.prototype.moveBlock = function(x,y,steps,time,keep,callback) {
faceIds = block.event.faceIds||{};
}
var opacityVal = 1;
core.setOpacity('route', opacityVal);
var alpha = 1;
core.setAlpha('route', alpha);
core.canvas.route.drawImage(image, bx * 32, by * height, 32, height, block.x * 32, block.y * 32 +32 - height, 32, height);
// 要运行的轨迹将steps展开
@ -834,15 +827,11 @@ maps.prototype.moveBlock = function(x,y,steps,time,keep,callback) {
// 已经移动完毕,消失
if (moveSteps.length==0) {
if (keep) opacityVal=0;
else opacityVal -= 0.06;
core.setOpacity('route', opacityVal);
if (keep) alpha=0;
else alpha -= 0.06;
core.clearMap('route', nowX, nowY-height+32, 32, height);
core.canvas.route.drawImage(image, animateCurrent * 32, by * height, 32, height, nowX, nowY-height+32, 32, height);
if (opacityVal<=0) {
if (alpha<=0) {
clearInterval(animate);
core.clearMap('route');
core.setOpacity('route', 1);
// 不消失
if (keep) {
core.setBlock(id, nowX/32, nowY/32);
@ -851,6 +840,11 @@ maps.prototype.moveBlock = function(x,y,steps,time,keep,callback) {
// core.status.replay.animate=false;
if (core.isset(callback)) callback();
}
else {
core.setAlpha('route', alpha);
core.canvas.route.drawImage(image, animateCurrent * 32, by * height, 32, height, nowX, nowY-height+32, 32, height);
core.setAlpha('route', 1);
}
}
else {
// 移动中
@ -865,10 +859,10 @@ maps.prototype.moveBlock = function(x,y,steps,time,keep,callback) {
}
}
core.clearMap('route', nowX, nowY-height+32, 32, height);
step++;
nowX+=scan[direction].x*2;
nowY+=scan[direction].y*2;
core.clearMap('route', nowX-32, nowY-32, 96, 96);
// 绘制
core.canvas.route.drawImage(image, animateCurrent * 32, by * height, 32, height, nowX, nowY-height+32, 32, height);
if (step==16) {
@ -883,7 +877,6 @@ maps.prototype.moveBlock = function(x,y,steps,time,keep,callback) {
////// 显示跳跃某块的动画,达到{"type":"jump"}的效果 //////
maps.prototype.jumpBlock = function(sx,sy,ex,ey,time,keep,callback) {
time = time || 500;
core.clearMap('route');
var block = core.getBlock(sx,sy);
if (block==null) {
if (core.isset(callback)) callback();
@ -891,12 +884,8 @@ maps.prototype.jumpBlock = function(sx,sy,ex,ey,time,keep,callback) {
}
var id = block.block.id;
// core.status.replay.animate=true;
// 需要删除该块
core.removeBlock(sx,sy);
core.clearMap('ui');
core.setAlpha('ui', 1.0);
block=block.block;
var image, bx, by, height = block.event.height || 32;
@ -926,8 +915,8 @@ maps.prototype.jumpBlock = function(sx,sy,ex,ey,time,keep,callback) {
by = core.material.icons[block.event.cls][block.event.id];
}
var opacityVal = 1;
core.setOpacity('route', opacityVal);
var alpha = 1;
core.setAlpha('route', alpha);
core.canvas.route.drawImage(image, bx*32, by * height, 32, height, block.x * 32, block.y * 32 +32 - height, 32, height);
core.playSound('jump.mp3');
@ -977,12 +966,10 @@ maps.prototype.jumpBlock = function(sx,sy,ex,ey,time,keep,callback) {
core.canvas.route.drawImage(image, animateCurrent * 32, by * height, 32, height, drawX(), drawY()-height+32, 32, height);
}
else {
if (keep) opacityVal=0;
else opacityVal -= 0.06;
core.setOpacity('route', opacityVal);
if (keep) alpha=0;
else alpha -= 0.06;
core.clearMap('route', drawX(), drawY()-height+32, 32, height);
core.canvas.route.drawImage(image, animateCurrent * 32, by * height, 32, height, drawX(), drawY()-height+32, 32, height);
if (opacityVal<=0) {
if (alpha<=0) {
clearInterval(animate);
core.clearMap('route');
core.setOpacity('route', 1);
@ -990,9 +977,13 @@ maps.prototype.jumpBlock = function(sx,sy,ex,ey,time,keep,callback) {
core.setBlock(id, ex, ey);
core.showBlock(ex, ey);
}
// core.status.replay.animate=false;
if (core.isset(callback)) callback();
}
else {
core.setAlpha('route', alpha);
core.canvas.route.drawImage(image, animateCurrent * 32, by * height, 32, height, drawX(), drawY()-height+32, 32, height);
core.setAlpha('route', 1);
}
}
}, time / 16 / core.status.replay.speed);