patroling
Permet à un objet de se déplacer jusqu'à ce qu'il recontre un objet
parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
speed | number | 60 | |
direction | number | -1 | |
uTrunDelay | number | 0.5 | |
startDelay | number | 0.5 | |
tag | string | 'stopper' |
example
patroling({ speed: 60, direction: -1, uTrunDelay: 0.5, startDelay: 0.5, tag: 'stopper'}),function patroling(p) { const param = { speed: 60, direction: -1, uTrunDelay: 0.5, startDelay: 0.5, tag: 'stopper', ...p, }; return { id: 'partoling', add() { let currentDirection = param.direction; this.onCollide('stopper', (obj, col) => { const l = col.isLeft() && currentDirection < 0; const r = col.isRight() && currentDirection > 0; const bt = !col.isTop() && !col.isBottom(); if ((l || r) && bt && !obj.has('player') && !obj.has('projectile')) { const targetDirection = currentDirection > 0 ? -1 : 1; tween( currentDirection, targetDirection, param.uTrunDelay, (v) => (currentDirection = v), easings.easeInSin ); this.trigger('facing', vec2(targetDirection, 0)); } }); this.on('respawn', () => { currentDirection = param.direction; this.trigger('facing', vec2(param.direction, 0)); }); onUpdate(() => { this.move(param.speed * currentDirection, 0); }); this.trigger('facing', vec2(param.direction, 0)); }, };}