throwBall
Permet à un objet de lancer une balle lorsqu'un joueur appuie sur shootKey
parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
speed | number | 800 | |
margin | vec2 | vec2(40, 40) | |
duration | number | 4 | |
fadeDuration | number | 0.4 | |
bouncing | number | 0.8 | |
friction | number | 0.4 | |
detuneAmp | number | 400 |
example
throwBall({ speed: 800, margin: vec2(40, 40), duration: 4, fadeDuration: 0.4, bouncing: 0.8, friction: 0.4, detuneAmp: 400}),function throwBall(p) { const param = { speed: 800, margin: vec2(40, 40), duration: 4, fadeDuration: 0.4, bouncing: 0.8, friction: 0.4, detuneAmp: 400, ...p } return { id: "throwBall", add() { this.on("throw", (facing = 1) => { if (this.isAlive) { const dir = vec2(facing, -0.5) const x = this.pos.x + param.margin.x * facing const y = this.pos.y - param.margin.y ball = add([ sprite("ball"), pos(x, y), lifespan(param.duration, { fade: param.fadeDuration }), area(), body(), bouncingBall({ ...param, ...{ direction: dir } }), anchor("center"), opacity(), "projectile", ]) } }) }, }}