type:closeDoor

This commit is contained in:
oc 2019-03-21 22:31:13 +08:00
parent 54b659b5d6
commit 20781645d4
5 changed files with 80 additions and 1 deletions

View File

@ -901,6 +901,30 @@ needKey是可选的如果设置为true则需要钥匙才能打开此门。如
!> needKey仅对当前楼层开门有效跨楼层的门仍然不需要钥匙即可打开如有需求请自行判定。
### closeDoor关门
从V2.6开始提供了关门事件`{"type": "closeDoor"}`,拥有关门动画和对应的音效。
``` js
"x,y": [ // 实际执行的事件列表
{"type": "closeDoor", "id": "yellowDoor", "loc": [3,6]}, // 给(3,6)点关上黄门
{"type": "closeDoor", "id": "specialDoor"}, // 不写loc则视为当前点
]
```
id为你要关门的ID需要是一个合法的门系统默认只支持如下几种
```
yellowDoor, blueDoor, redDoor, greenDoor, specialDoor, steelDoor,
yellowWall, blueWall, whiteWall
```
如果需要自己添加门,请参考[新增门和对应的钥匙](personalization#新增门和对应的钥匙)。
loc可选为要关的位置不填默认为当前点。
关门事件需要保证该点是空地,否则将无视此事件。
### changeFloor楼层切换
在事件中也可以对楼层进行切换。一个比较典型的例子就是TSW中勇士在三楼的陷阱被扔到了二楼就是一个楼层切换事件。

View File

@ -256,6 +256,7 @@ action
| waitAsync_s
| battle_s
| openDoor_s
| closeDoor_s
| changeFloor_s
| changePos_0_s
| changePos_1_s
@ -961,6 +962,23 @@ var code = '{"type": "openDoor"'+floorstr+IdString_0+Bool_0+'},\n';
return code;
*/;
closeDoor_s
: '关门' 'x' PosString? ',' 'y' PosString? 'ID' IdString Newline
/* closeDoor_s
tooltip : closeDoor: 关门事件,需要该点本身无事件
helpUrl : https://h5mota.com/games/template/docs/#/event?id=opendoor%EF%BC%9A%E5%BC%80%E9%97%A8
default : ["","","yellowDoor"]
colour : this.dataColor
var floorstr = '';
if (PosString_0 && PosString_1) {
floorstr = ', "loc": ['+PosString_0+','+PosString_1+']';
}
var code = '{"type": "closeDoor", "id": "'+IdString_0+'"'+floorstr+'},\n';
return code;
*/;
changeFloor_s
: '楼层切换' IdString? 'x' PosString? ',' 'y' PosString? '朝向' DirectionEx_List '动画时间' Int? Newline
@ -2338,6 +2356,11 @@ ActionParser.prototype.parseAction = function() {
this.next = MotaActionBlocks['openDoor_s'].xmlText([
data.loc[0],data.loc[1],data.floorId||'',data.needKey||false,this.next]);
break;
case "closeDoor": // 关一个门,需要该点无事件
data.loc=data.loc||['','']
this.next = MotaActionBlocks['closeDoor_s'].xmlText([
data.loc[0],data.loc[1],data.id,this.next]);
break;
case "useItem": // 使用道具
this.next = MotaActionBlocks['useItem_s'].xmlText([
data.id,this.next]);

View File

@ -721,7 +721,7 @@ editor.prototype.listen = function () {
mouseOutCheck = 2;
setTimeout(clear1);
e.stopPropagation();
uc.clearRect(0, 0, core.__SIZE__, core.__SIZE__);
uc.clearRect(0, 0, core.__PIXELS__, core.__PIXELS__);
var loc = eToLoc(e);
var pos = locToPos(loc,true);
stepPostfix = [];

View File

@ -93,6 +93,7 @@ editor_blockly = function () {
MotaActionBlocks['changePos_1_s'].xmlText(),
MotaActionBlocks['battle_s'].xmlText(),
MotaActionBlocks['openDoor_s'].xmlText(),
MotaActionBlocks['closeDoor_s'].xmlText(),
MotaActionBlocks['useItem_s'].xmlText(),
MotaActionBlocks['openShop_s'].xmlText(),
MotaActionBlocks['setBlock_s'].xmlText(),

View File

@ -1118,6 +1118,11 @@ events.prototype._action_openDoor = function (data, x, y, prefix) {
}
}
events.prototype._action_closeDoor = function (data, x, y, prefix) {
var loc = this.__action_getLoc(data.loc, x, y, prefix);
core.closeDoor(loc[0], loc[1], data.id, core.doAction);
}
events.prototype._action_useItem = function (data, x, y, prefix) {
// 考虑到可能覆盖楼传事件的问题这里不对fly进行检查。
if (data.id != 'book' && core.canUseItem(data.id)) {
@ -1800,6 +1805,32 @@ events.prototype.setGlobalFlag = function (name, value) {
core.resize();
}
events.prototype.closeDoor = function (x, y, id, callback) {
id = id || "";
if (!(id.endsWith("Door") || id.endsWith("Wall"))
|| !core.material.icons.animates[id] || core.getBlock(x, y) != null) {
if (callback) callback();
return;
}
// 关门动画
core.playSound('door.mp3');
var door = core.material.icons.animates[id];
var speed = id.endsWith("Door") ? 30 : 70, state = 0;
var animate = window.setInterval(function () {
state++;
if (state == 4) {
clearInterval(animate);
delete core.animateFrame.asyncId[animate];
core.setBlock(core.getNumberById(id), x, y);
if (callback) callback();
return;
}
core.clearMap('event', 32 * x, 32 * y, 32, 32);
core.drawImage('event', core.material.images.animates, 32 * (4-state), 32 * door, 32, 32, 32 * x, 32 * y, 32, 32);
}, speed / core.status.replay.speed);
core.animateFrame.asyncId[animate] = true;
}
////// 显示图片 //////
events.prototype.showImage = function (code, image, x, y, dw, dh, opacityVal, time, callback) {
dw /= 100;