bouncingBall
Permet à un objet de se déplacer et de rebondir
parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
direction | vec2 | vec2(0, 0) | |
speed | number | 0 | |
bouncing | number | 0.8 | |
friction | number | 0.4 | |
detuneAmp | number | 400 |
example
bouncingBall({ direction: vec2(0, 0), speed: 0, bouncing: 0.8, friction: 0.4, detuneAmp: 400}),function bouncingBall(p) { const param = { direction: vec2(0, 0), speed: 0, bouncing: 0.8, friction: 0.4, detuneAmp: 400, ...p } return { id: "bouncing ball", currentSpeed: 1, currentDirection: param.direction, add() { this.onCollide("body", (obj, col) => { let m = vec2(1, 1) if (col.isTop() || col.isBottom()) m = vec2(1, -1) else if (col.isLeft() || col.isRight()) m = vec2(-1, 1) if (col.isBottom()) this.jump(this.currentSpeed * param.speed) this.currentDirection = this.currentDirection.scale(m) this.currentSpeed = this.currentSpeed * param.bouncing this.currentVolume = this.currentVolume * param.bouncing this.trigger("bounce", { volume: this.currentSpeed, detune: this.currentSpeed * param.detuneAmp }) }) }, update() { this.move(this.currentDirection.scale(this.currentSpeed * param.speed)) if (this.isGrounded()) this.currentSpeed -= this.currentSpeed * param.friction * dt() }, }}