throwItemController
Permet à un objet de lancer une balle lorsqu'un joueur appuie sur shootKey
require
shoot()holdItem()triggers on self
"moved""drop item"parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
shootKey | string | "space" | |
keyPressToShoot | boolean | true | |
mousePressToShoot | boolean | true |
example
throwItemController({ shootKey: "space", keyPressToShoot: true, mousePressToShoot: true}),function throwItemController(p) { const param = { shootKey: "space", keyPressToShoot: true, mousePressToShoot: true, ...p, } return { id: "throwItemController", require: ["shoot", "holdItem"], add() { const throwItem = () => { if ((this.isAlive || !this.is("alive")) && this.holdItem) { this.trigger("moved") this.trigger("shoot", this.holdItem) this.trigger("drop item") } } if (param.keyPressToShoot) onKeyPress(param.shootKey, () => throwItem()) if (param.mousePressToShoot) onMousePress(() => throwItem()) }, }}