setViewport & moveViewport

This commit is contained in:
oc 2019-07-09 20:23:52 +08:00
parent 7de3964525
commit 193046f33d
4 changed files with 105 additions and 2 deletions

View File

@ -293,6 +293,8 @@ action
| changeFloor_s
| changePos_0_s
| changePos_1_s
| setViewport_s
| moveViewport_s
| useItem_s
| openShop_s
| disableShop_s
@ -1241,6 +1243,38 @@ var code = '{"type": "animate", "name": "'+IdString_0+'"'+EvalString_0+async+'},
return code;
*/;
setViewport_s
: '设置视角' '左上角坐标' 'x' PosString? ',' 'y' PosString? Newline
/* setViewport_s
tooltip : setViewport: 设置视角
helpUrl : https://h5mota.com/games/template/_docs/#/event?id=changepos%EF%BC%9A%E5%BD%93%E5%89%8D%E4%BD%8D%E7%BD%AE%E5%88%87%E6%8D%A2%E5%8B%87%E5%A3%AB%E8%BD%AC%E5%90%91
default : ["",""]
colour : this.soundColor
var loc = '';
if (PosString_0 && PosString_1) {
loc = ', "loc": ['+PosString_0+','+PosString_1+']';
}
var code = '{"type": "setViewport"'+loc+'},\n';
return code;
*/;
moveViewport_s
: '移动视角' '动画时间' Int? '不等待执行完毕' Bool BGNL? StepString Newline
/* moveViewport_s
tooltip : moveViewport移动视角
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 : [300,false,"上右3下2左"]
colour : this.soundColor
Int_0 = Int_0!=='' ?(', "time": '+Int_0):'';
Bool_0 = Bool_0?', "async": true':'';
var code = '{"type": "moveViewport"'+Int_0+Bool_0+', "steps": '+JSON.stringify(StepString_0)+'},\n';
return code;
*/;
showImage_s
: '显示图片' '图片编号' Int '图片' EvalString BGNL?
'绘制的起点像素' 'x' PosString 'y' PosString '不透明度' Number '时间' Int '不等待执行完毕' Bool Newline
@ -2993,6 +3027,15 @@ ActionParser.prototype.parseAction = function() {
this.next = MotaActionBlocks['animate_s'].xmlText([
data.name,animate_loc,data.async||false,this.next]);
break;
case "setViewport": // 设置视角
data.loc = data.loc||['',''];
this.next = MotaActionBlocks['setViewport_s'].xmlText([
data.loc[0],data.loc[1],this.next]);
break;
case "moveViewport": // 移动视角
this.next = MotaActionBlocks['moveViewport_s'].xmlText([
data.time||0,data.async||false,this.StepString(data.steps),this.next]);
break;
case "vibrate": // 画面震动
this.next = MotaActionBlocks['vibrate_s'].xmlText([data.time||0, data.async||false, this.next]);
break;
@ -3547,7 +3590,7 @@ MotaActionFunctions.IdString_pre = function(IdString){
MotaActionFunctions.PosString_pre = function(PosString){
if (!PosString || /^-?\d+$/.test(PosString)) return PosString;
if (!(MotaActionFunctions.pattern.id.test(PosString)))throw new Error(PosString+'中包含了0-9 a-z A-Z _ 和中文之外的字符,或者是没有以flag: 开头');
//if (!(MotaActionFunctions.pattern.id.test(PosString)))throw new Error(PosString+'中包含了0-9 a-z A-Z _ 和中文之外的字符,或者是没有以flag: 开头');
return '"'+PosString+'"';
}

View File

@ -150,6 +150,8 @@ editor_blockly = function () {
MotaActionBlocks['waitAsync_s'].xmlText(),
MotaActionBlocks['vibrate_s'].xmlText(),
MotaActionBlocks['animate_s'].xmlText(),
MotaActionBlocks['setViewport_s'].xmlText(),
MotaActionBlocks['moveViewport_s'].xmlText(),
MotaActionBlocks['showStatusBar_s'].xmlText(),
MotaActionBlocks['hideStatusBar_s'].xmlText(),
MotaActionBlocks['setCurtain_0_s'].xmlText(),

View File

@ -779,6 +779,7 @@ control.prototype.drawHero = function (status, offset) {
});
core.control.updateViewport();
core.setGameCanvasTranslate('hero', 0, 0);
}
control.prototype._drawHero_getDrawObjs = function (direction, x, y, status, offset) {
@ -852,6 +853,48 @@ control.prototype.updateViewport = function() {
core.relocateCanvas('route', core.status.automaticRoute.offsetX - core.bigmap.offsetX, core.status.automaticRoute.offsetY - core.bigmap.offsetY);
}
////// 设置视野范围 //////
control.prototype.setViewport = function (x, y) {
core.bigmap.offsetX = core.clamp(x, 0, 32 * core.bigmap.width - core.__PIXELS__);
core.bigmap.offsetY = core.clamp(y, 0, 32 * core.bigmap.height - core.__PIXELS__);
this.updateViewport();
// ------ hero层也需要
var hero_x = core.clamp((core.getHeroLoc('x') - core.__HALF_SIZE__) * 32, 0, 32*core.bigmap.width-core.__PIXELS__);
var hero_y = core.clamp((core.getHeroLoc('y') - core.__HALF_SIZE__) * 32, 0, 32*core.bigmap.height-core.__PIXELS__);
core.control.setGameCanvasTranslate('hero', hero_x - core.bigmap.offsetX, hero_y - core.bigmap.offsetY);
}
////// 移动视野范围 //////
control.prototype.moveViewport = function (steps, time, callback) {
time = time || core.values.moveSpeed || 300;
var step = 0, moveSteps = (steps||[]).filter(function (t) {
return ['up','down','left','right'].indexOf(t)>=0;
});
var animate=window.setInterval(function() {
if (moveSteps.length==0) {
delete core.animateFrame.asyncId[animate];
clearInterval(animate);
if (callback) callback();
}
else {
if (core.control._moveViewport_moving(++step, moveSteps))
step = 0;
}
}, time / 16 / core.status.replay.speed);
core.animateFrame.asyncId[animate] = true;
}
control.prototype._moveViewport_moving = function (step, moveSteps) {
var direction = moveSteps[0], scan = core.utils.scan[direction];
core.setViewport(core.bigmap.offsetX + 2 * scan.x, core.bigmap.offsetY + 2 * scan.y);
if (step == 16) {
moveSteps.shift();
return true;
}
return false;
}
////// 获得勇士面对位置的x坐标 //////
control.prototype.nextX = function(n) {
if (n == null) n = 1;

View File

@ -1077,6 +1077,21 @@ events.prototype._action_animate = function (data, x, y, prefix) {
this.__action_doAsyncFunc(data.async, core.drawAnimate, data.name, data.loc[0], data.loc[1]);
}
events.prototype._action_setViewport = function (data, x, y, prefix) {
if (data.loc == null) {
core.drawHero();
}
else {
var loc = this.__action_getLoc(data.loc, x, y, prefix);
core.setViewport(32 * loc[0], 32 * loc[1]);
}
core.doAction();
}
events.prototype._action_moveViewport = function (data, x, y, prefix) {
this.__action_doAsyncFunc(data.async, core.moveViewport, data.steps, data.time);
}
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);
@ -2268,7 +2283,7 @@ events.prototype._eventMoveHero_moving = function (step, moveSteps) {
core.drawHero('leftFoot', 4 * o * step);
}
else if (step <= 8) {
core.drawHero('rightFoot', 4 * o * step);
core.drawHero('rightFoot', 4 * o * step);SGTM
}
if (step == 8) {
core.setHeroLoc('x', x + o * core.utils.scan[direction].x, true);