怪物朝向

This commit is contained in:
ckcz123 2021-08-04 16:18:56 +08:00
parent 861cbeb587
commit e56a5ff41b
2 changed files with 22 additions and 9 deletions

View File

@ -35,8 +35,18 @@ enemys.prototype.getEnemys = function () {
if (enemys[id].faceIds) {
var downId = enemys[id].faceIds.down;
if (downId != null && downId != id && enemys[downId]) {
enemys[id] = core.clone(enemys[downId]);
enemys[id].id = id;
enemys[id] = {id: id};
for (var property in enemys[downId]) {
if (property != 'id' && enemys[downId].hasOwnProperty(property)) {
(function (id, downId, property) {
Object.defineProperty(enemys[id], property, {
get: function () { return enemys[downId][property] },
set: function (v) { enemys[downId][property] = v },
enumerable: true
})
})(id, downId, property);
}
}
}
}
}

View File

@ -803,17 +803,20 @@ utils.prototype.strlen = function (str) {
utils.prototype.turnDirection = function (turn, direction) {
direction = direction || core.getHeroLoc('direction');
var directionList = ["left", "up", "right", "down"];
var directionList = ["left", "leftup", "up", "rightup", "right", "rightdown", "down", "leftdown"];
if (directionList.indexOf(turn) >= 0) return turn;
switch (turn) {
case ':left': turn = 3; break; // turn left
case ':right': turn = 1; break; // turn right
case ':back': turn = 2; break; // turn back
default: turn = 0; break;
if (typeof turn === 'number' && turn % 45 == 0) turn /= 45;
else {
switch (turn) {
case ':left': turn = 6; break; // turn left
case ':right': turn = 2; break; // turn right
case ':back': turn = 4; break; // turn back
default: turn = 0; break;
}
}
var index = directionList.indexOf(direction);
if (index < 0) return direction;
return directionList[(index + (turn || 0)) % 4];
return directionList[(index + (turn || 0)) % directionList.length];
}
utils.prototype.matchWildcard = function (pattern, string) {