shootController
Permet à un objet de lancer une balle lorsqu'un joueur appuie sur shootKey
triggers on self
"moved"parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
shootKey | string | 'space' | |
keyPressToShoot | boolean | true | |
mousePressToShoot | boolean | true | |
delay | number | 0.2 |
example
shootController({ shootKey: 'space', keyPressToShoot: true, mousePressToShoot: true, delay: 0.2}),function shootController(p) { const param = { shootKey: 'space', keyPressToShoot: true, mousePressToShoot: true, delay: 0.2, ...p, }; return { id: 'shootBulletController', weapon: {}, add() { let savedTime = 0; let delay = param.delay; const pullTrigger = () => { if ( (this.isAlive || !this.has('alive')) && time() - savedTime > delay ) { this.trigger('moved'); savedTime = time(); this.trigger('shoot', { weapon: this.weapon, }); delay = this.weapon.delay ? this.weapon.delay : param.delay; } }; if (param.keyPressToShoot) onKeyPress(param.shootKey, () => pullTrigger()); if (param.mousePressToShoot) onMousePress(() => pullTrigger()); }, };}