swordController
triggers on self
"moved""on guard"parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
shootKey | string | 'space' | |
keyPressToShoot | boolean | true | |
mousePressToShoot | boolean | true | |
sequenceBreakDelay | number | 0.2 | |
delay | number | 0.1 | |
postureBreak | boolean | true | |
postureBreakDelay | number | 0.2 | |
moveSequence | array | [] | |
onJumpMoveSequence | array | [] |
example
swordController({ shootKey: 'space', keyPressToShoot: true, mousePressToShoot: true, sequenceBreakDelay: 0.2, delay: 0.1, postureBreak: true, postureBreakDelay: 0.2, moveSequence: [], onJumpMoveSequence: []}),function swordController(p) { const param = { shootKey: 'space', keyPressToShoot: true, mousePressToShoot: true, sequenceBreakDelay: 0.2, delay: 0.1, postureBreak: true, postureBreakDelay: 0.2, moveSequence: [], onJumpMoveSequence: [], ...p, }; return { id: 'swordController', onGuard: true, add() { let c = 0; let savedTime = 0; let delay = param.delay; const hit = () => { if (this.isAlive && time() - savedTime > delay) { this.trigger('moved'); const sequence = !this.isGrounded() && param.onJumpMoveSequence.length > 0 ? param.onJumpMoveSequence : param.moveSequence; const p = sequence.length > 0 ? sequence[c % sequence.length] : {}; this.trigger('sword stroke', p); c++; savedTime = time(); delay = p.delay ? p.delay : param.delay; this.onGuard = false; this.moveSavedTime = time(); } }; if (param.keyPressToShoot) onKeyPress(param.shootKey, () => hit()); if (param.mousePressToShoot) onMousePress(() => hit()); onUpdate(() => { if ( !this.onGuard && time() - savedTime > delay + param.sequenceBreakDelay ) { this.trigger('on guard'); this.onGuard = true; } }); this.on('on guard', () => (c = 0)); this.on('respawn', () => (savedTime = 0)); if (param.postureBreak) this.on('hit', () => { delay += param.postureBreakDelay; savedTime = time(); }); }, };}