Merge pull request #527 from qweasz687/v2.x

锁定视角
This commit is contained in:
Zhang Chen 2021-08-13 12:05:22 +08:00 committed by GitHub
commit 87f2d7e886
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 102 additions and 56 deletions

View File

@ -860,6 +860,7 @@ action
| changePos_s
| setViewport_s
| setViewport_1_s
| lockViewport_s
| useItem_s
| loadEquip_s
| unloadEquip_s
@ -2129,6 +2130,19 @@ var code = '{"type": "setViewport"'+loc+MoveMode_List_0+Int_0+Bool_0+'},\n';
return code;
*/;
lockViewport_s
: '是否锁定视角' Bool Newline
/* lockViewport_s
tooltip : lockViewport: 是否锁定视角
helpUrl : /_docs/#/instruction
default : [false]
colour : this.soundColor
Bool_0 = Bool_0 ? (', "lock": true') : '';
var code = '{"type": "lockViewport"'+Bool_0+'},\n';
return code;
*/;
showImage_s
: '显示图片' '图片编号' NInt '图片' EvalString '翻转' Reverse_List BGNL?
'绘制的起点像素' 'x' PosString 'y' PosString '不透明度' Number '时间' Int '不等待执行完毕' Bool Newline
@ -4168,4 +4182,4 @@ this.block('idTemp_e').output='idString_e';
MotaActionParser()
*/
*/

View File

@ -569,6 +569,10 @@ ActionParser.prototype.parseAction = function() {
data.loc[0],data.loc[1],data.moveMode||'', data.time||0,data.async||false,this.next]);
}
break;
case "lockViewport":
this.next = MotaActionBlocks['lockViewport_s'].xmlText([data.lock,
this.next]);
break;
case "vibrate": // 画面震动
this.next = MotaActionBlocks['vibrate_s'].xmlText([data.direction||'horizontal',
data.time||0, data.speed, data.power, data.async||false, this.next]);
@ -1722,4 +1726,4 @@ MotaActionFunctions.replaceFromName = function (str) {
return str;
}
}
}

View File

@ -209,6 +209,7 @@ editor_blocklyconfig=(function(){
MotaActionBlocks['animate_1_s'].xmlText(),
MotaActionBlocks['setViewport_s'].xmlText(),
MotaActionBlocks['setViewport_1_s'].xmlText(),
MotaActionBlocks['lockViewport_s'].xmlText(),
MotaActionBlocks['showStatusBar_s'].xmlText(),
MotaActionBlocks['hideStatusBar_s'].xmlText(),
MotaActionBlocks['showHero_s'].xmlText(),
@ -712,4 +713,4 @@ function omitedcheckUpdateFunction(event) {
// end mark sfergsvae
}).toString().split('// start mark sfergsvae')[1].split('// end mark sfergsvae')[0]
}).toString().split('// start mark sfergsvae')[1].split('// end mark sfergsvae')[0]

View File

@ -202,7 +202,12 @@ control.prototype._animationFrame_heroMoving = function (timestamp) {
core.animateFrame.leftLeg = !core.animateFrame.leftLeg;
core.animateFrame.moveTime = timestamp;
}
core.drawHero(core.animateFrame.leftLeg?'leftFoot':'rightFoot', 4*core.status.heroMoving);
var way = core.utils.scan2[core.getHeroLoc('direction')],
heroMoving = core.status.heroMoving;
core.drawHero(core.animateFrame.leftLeg ? 'leftFoot' : 'rightFoot', {
x: way.x * 4 * heroMoving,
y: way.y * 4 * heroMoving
});
}
control.prototype._animationFrame_weather = function (timestamp) {
@ -813,40 +818,81 @@ control.prototype.tryMoveDirectly = function (destX, destY) {
}
////// 绘制勇士 //////
control.prototype.drawHero = function (status, offset, frame) {
control.prototype.drawHero = function (status, offset, frame, noGather) {
if (!core.isPlaying() || !core.status.floorId || core.status.gameOver) return;
var x = core.getHeroLoc('x'), y = core.getHeroLoc('y'), direction = core.getHeroLoc('direction');
status = status || 'stop';
offset = offset || 0;
offset = offset || {};
offset.x = offset.x || 0;
offset.y = offset.y || 0;
var way = core.utils.scan2[direction];
var dx = way.x, dy = way.y, offsetX = dx * offset, offsetY = dy * offset;
core.bigmap.offsetX = core.clamp((x - core.__HALF_SIZE__) * 32 + offsetX, 0, 32*core.bigmap.width-core.__PIXELS__);
core.bigmap.offsetY = core.clamp((y - core.__HALF_SIZE__) * 32 + offsetY, 0, 32*core.bigmap.height-core.__PIXELS__);
core.clearAutomaticRouteNode(x+dx, y+dy);
var dx = way.x, dy = way.y;
var offsetX = offset.x, offsetY = offset.y;
core.clearAutomaticRouteNode(x + dx, y + dy);
core.clearMap('hero');
core.status.heroCenter.px = 32 * x + offsetX + 16;
core.status.heroCenter.py = 32 * y + offsetY + 32 - core.material.icons.hero.height / 2;
this._drawHero_updateViewport(x, y, offset);
if (!core.hasFlag('hideHero')) {
this._drawHero_draw(direction, x, y, status, offset, frame);
}
this._drawHero_updateViewport();
this._drawHero_draw(direction, x, y, status, offset, frame, noGather);
}
}
control.prototype._drawHero_updateViewport = function () {
core.control.updateViewport();
control.prototype._drawHero_updateViewport = function (x, y, offset) {
core.setGameCanvasTranslate('hero', 0, 0);
if (flags.__lockViewport__) return;
var offsetX = offset.x, offsetY = offset.y;
var ox = (x - core.__HALF_SIZE__) * 32 + offsetX,
oy = (y - core.__HALF_SIZE__) * 32 + offsetY;
core.bigmap.offsetX = core.clamp(ox, 0, 32 * core.bigmap.width - core.__PIXELS__);
core.bigmap.offsetY = core.clamp(oy, 0, 32 * core.bigmap.height - core.__PIXELS__);
core.control.updateViewport();
}
control.prototype._drawHero_draw = function (direction, x, y, status, offset, frame) {
this._drawHero_getDrawObjs(direction, x, y, status, offset).forEach(function (block) {
control.prototype._drawHero_draw = function (direction, x, y, status, offset, frame, noGather) {
this._drawHero_getDrawObjs(direction, x, y, status, offset, noGather).forEach(function (block) {
core.drawImage('hero', block.img, (block.heroIcon[block.status] + (frame || 0))%4*block.width,
block.heroIcon.loc * block.height, block.width, block.height,
block.posx+(32-block.width)/2, block.posy+32-block.height, block.width, block.height);
});
}
control.prototype._drawHero_getDrawObjs = function (direction, x, y, status, offset, noGather) {
var heroIconArr = core.material.icons.hero, drawObjs = [], index = 0;
drawObjs.push({
"img": core.material.images.hero,
"width": core.material.icons.hero.width || 32,
"height": core.material.icons.hero.height,
"heroIcon": heroIconArr[direction],
"posx": x * 32 - core.bigmap.offsetX + offset.x,
"posy": y * 32 - core.bigmap.offsetY + offset.y,
"status": status,
"index": index++,
});
// 不重绘跟随者 比如说跳跃时……
if (!noGather) {
core.status.hero.followers.forEach(function(t) {
drawObjs.push({
"img": core.material.images.images[t.name],
"width": core.material.images.images[t.name].width / 4,
"height": core.material.images.images[t.name].height / 4,
"heroIcon": heroIconArr[t.direction],
"posx": 32 * t.x - core.bigmap.offsetX + (t.stop ? 0 : core.utils.scan2[t.direction].x * Math.abs(offset.x)),
"posy": 32 * t.y - core.bigmap.offsetY + (t.stop ? 0 : core.utils.scan2[t.direction].y * Math.abs(offset.y)),
"status": t.stop ? "stop" : status,
"index": index++
});
});
}
return drawObjs.sort(function(a, b) {
return a.posy==b.posy?b.index-a.index:a.posy-b.posy;
});
}
control.prototype.triggerHero = function (type, time, callback) {
if (type == null) {
type = core.hasFlag('hideHero') ? 'show' : 'hide';
@ -887,35 +933,6 @@ control.prototype._triggerHero_animate = function (type, delta, callback) {
core.animateFrame.asyncId[animate] = true;
}
control.prototype._drawHero_getDrawObjs = function (direction, x, y, status, offset) {
var heroIconArr = core.material.icons.hero, drawObjs = [], index = 0;
drawObjs.push({
"img": core.material.images.hero,
"width": core.material.icons.hero.width || 32,
"height": core.material.icons.hero.height,
"heroIcon": heroIconArr[direction],
"posx": x * 32 - core.bigmap.offsetX + core.utils.scan2[direction].x * offset,
"posy": y * 32 - core.bigmap.offsetY + core.utils.scan2[direction].y * offset,
"status": status,
"index": index++,
});
core.status.hero.followers.forEach(function (t) {
drawObjs.push({
"img": core.material.images.images[t.name],
"width": core.material.images.images[t.name].width/4,
"height": core.material.images.images[t.name].height/4,
"heroIcon": heroIconArr[t.direction],
"posx": 32*t.x - core.bigmap.offsetX + (t.stop?0:core.utils.scan2[t.direction].x*Math.abs(offset)),
"posy": 32*t.y - core.bigmap.offsetY + (t.stop?0:core.utils.scan2[t.direction].y*Math.abs(offset)),
"status": t.stop?"stop":status,
"index": index++
});
});
return drawObjs.sort(function(a, b) {
return a.posy==b.posy?b.index-a.index:a.posy-b.posy;
});
}
// ------ 画布、位置、阻激夹域,显伤 ------ //
////// 设置画布偏移

View File

@ -1527,6 +1527,11 @@ events.prototype._action_setViewport = function (data, x, y, prefix) {
this.__action_doAsyncFunc(data.async, core.moveViewport, data.loc[0], data.loc[1], data.moveMode, data.time);
}
events.prototype._action_lockViewport = function (data, x, y, prefix) {
flags.__lockViewport__ = data.lock;
core.doAction();
}
events.prototype._action_move = function (data, x, y, prefix) {
var loc = this.__action_getLoc(data.loc, x, y, prefix);
this.__action_doAsyncFunc(data.async, core.moveBlock, loc[0], loc[1], data.steps, data.time, data.keep);
@ -3547,10 +3552,16 @@ events.prototype._eventMoveHero_moving = function (step, moveSteps) {
return true;
}
if (step <= 4) {
core.drawHero('leftFoot', 4 * o * step);
core.drawHero('leftFoot', {
x: 4 * o * step,
y: 4 * o * step
});
}
else if (step <= 8) {
core.drawHero('rightFoot', 4 * o * step);
core.drawHero('rightFoot', {
x: 4 * o * step,
y: 4 * o * step
});
}
if (step == 8) {
core.setHeroLoc('x', x + o * core.utils.scan2[direction].x, true);
@ -3595,14 +3606,13 @@ events.prototype._jumpHero_doJump = function (jumpInfo, callback) {
events.prototype._jumpHero_jumping = function (jumpInfo) {
core.clearMap('hero');
core.maps.__updateJumpInfo(jumpInfo);
var x = core.getHeroLoc('x'),
y = core.getHeroLoc('y');
var nowx = jumpInfo.px, nowy = jumpInfo.py, width = jumpInfo.width || 32, height = jumpInfo.height;
core.bigmap.offsetX = core.clamp(nowx - 32*core.__HALF_SIZE__, 0, 32*core.bigmap.width-core.__PIXELS__);
core.bigmap.offsetY = core.clamp(nowy - 32*core.__HALF_SIZE__, 0, 32*core.bigmap.height-core.__PIXELS__);
core.control.updateViewport();
core.drawImage('hero', core.material.images.hero, jumpInfo.icon.stop, jumpInfo.icon.loc * height, width, height,
nowx + (32 - width) / 2 - core.bigmap.offsetX, nowy + 32-height - core.bigmap.offsetY, width, height);
core.status.heroCenter.px = nowx + 16;
core.status.heroCenter.py = nowy + 32 - height / 2;
core.drawHero(null, {
x: nowx - 32 * x,
y: nowy - 32 * y
}, 0, true);
}
events.prototype._jumpHero_finished = function (animate, ex, ey, callback) {