Async move & jump
This commit is contained in:
1 parent
52f311ce58
commit
cbbd973357
4 files changed
+79
-69
No files matched your search
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
+36
-12
@@ -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": // 楼层转换
|
||||
|
||||
+21
-30
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user