door
Permet à un objet de changer le niveau actuel lorsqu'un joueur entre collision avec lui
triggers on self
"locked""enter"triggers on others
"enter"parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
nextLevel | boolean | true | |
destination | number | 0 | |
delay | number | 0.1 | |
onInteract | boolean | false | |
locked | boolean | false | |
goToAnotherScene | boolean | true |
example
door({ nextLevel: true, destination: 0, delay: 0.1, onInteract: false, locked: false, goToAnotherScene: true}),function door(p) { const param = { nextLevel: true, destination: 0, delay: 0.1, onInteract: false, locked: false, goToAnotherScene: true, ...p, }; return { id: 'door', locked: param.locked, add() { const tryEnter = (obj) => { if (!this.locked) this.enter(obj); else this.trigger('try enter', { from: obj, }); }; if (param.onInteract) { this.tag('interactive'); this.on('interacted', (obj) => tryEnter(obj)); } else this.onCollide('player', (obj) => tryEnter(obj)); }, tryEnter(b, obj) { if (b) this.enter(obj); else this.trigger('locked'); }, enter(obj) { if (param.nextLevel) CURRENT_LEVEL = (CURRENT_LEVEL + 1) % LEVELS.length; else CURRENT_LEVEL = param.destination; wait(param.delay, () => go('game', obj)); obj.trigger('enter'); this.trigger('enter'); }, };}