Created
July 17, 2016 03:32
-
-
Save teramotodaiki/bb1d94e05d5b06b32f2d49845c1d35d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 見た目だけ使いたいMOD 実装2 (テストなし) | |
game.preload('enchantjs/monster5.gif'); | |
// ====> ウロボロスクラス | |
// 文字からフレーム配列を生成する | |
var anm = function(source) { | |
Array.prototype._SCALE_ = function(scale) { | |
var result = []; | |
for (var i = 0; i < this.length * scale; ++i) { | |
result.push(this[i / scale | 0]); | |
} | |
return result; | |
}; | |
var result = source.replace(/ /g, '').replace(/\*/g, ')._SCALE_(').split('+').map(function (s) { | |
return Function('return (' + s + ')')(); | |
}).reduce(function (a, b) { | |
return a.concat(b); | |
}); | |
delete Array.prototype._SCALE_; | |
return result; | |
}; | |
RPGObject.prototype.animation = function(type, source) { | |
type = BehaviorTypes[type.charAt(0).toUpperCase() + type.slice(1)]; | |
this.setFrame(type, anm(source)); | |
}; | |
var Ouroboros = enchant.Class(EnemyBase, { | |
initialize: function(){ | |
EnemyBase.call(this, 80, 80, -24, -36); | |
this.image = game.assets['enchantjs/monster5.gif']; | |
this.animation('idle', '[0] * 60 + [1] * 20'); | |
this.animation('attack', '[1, 5, 9, 10, 6, 1] * 3 + null'); | |
this.animation('walk', '[2, 3, 4, 3] * 4'); | |
this.animation('dead', '[1, 5, 7, 4, 0] * 5 + null'); | |
}, | |
onbecomeidle: function () { | |
// コウモリと9割同じ | |
// 咬みつくモーションをカッコよくするためにプレイヤーの1マス横を目指す | |
var target = Hack.player; | |
var signX = this.direction = Math.sign(target.mapX - this.mapX); | |
var moveX = 32 * Math.sign(target.mapX - this.mapX - signX); | |
var moveY = 32 * Math.sign(target.mapY - this.mapY); | |
this.tl.become('walk').moveBy(moveX, moveY, 30, enchant.Easing.QUAD_EASEINOUT).then(function () { | |
this.direction = signX = Math.sign(target.mapX - this.mapX); | |
// プレイヤーと同じ、もしくは1マス横なら攻撃する | |
if (this.mapX === (target.mapX - signX) && this.mapY === target.mapY) { | |
this.tl.become('attack').delay(20).become('idle'); | |
Hack.Attack.call(this, this.mapX + signX, this.mapY, this.atk); | |
} | |
else this.tl.become('idle'); | |
}); | |
} | |
}); | |
// <==== ウロボロスクラス | |
// 遅延評価してRPGObjectを返すジェネレータ(実体はただの関数) | |
// @return RPGObject like object | |
var __cacheObject = null; | |
var mod = function () { | |
var origin = __cacheObject || new Ouroboros(); | |
this.width = origin.width; | |
this.height = origin.height; | |
this.image = origin.image; | |
this.color = origin.color; | |
Object.keys(origin.getFrameOfBehavior).forEach(function (type) { | |
this.setFrame(type, origin.getFrameOfBehavior[type]); | |
}, this); | |
var loc = [ this.mapX, this.mapY ]; | |
this.offset = { x: origin.offset.x, y: origin.offset.y }; | |
this.locate(loc[0], loc[1]); | |
this.shadow.visible = false; | |
origin.destroy(); | |
__cacheObject = origin; | |
}; | |
return mod; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment