climbController
Permet à un joueur de grimper sur certains objets
require
player()triggers on self
"climb start""climb jump""climb stop"parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
upKey | string | "up" | |
downKey | string | "down" | |
climbSpeed | number | 400 | |
climbJump | number | 600 | |
delay | number | 0.05 | |
sticky | boolean | true | |
catch | boolean | true |
example
climbController({ upKey: "up", downKey: "down", climbSpeed: 400, climbJump: 600, delay: 0.05, sticky: true, catch: true}),function climbController(p) { const param = { upKey: "up", downKey: "down", climbSpeed: 400, climbJump: 600, delay: 0.05, sticky: true, catch: true, ...p } return { onLadder: false, savedTimeOnLadder: 0, isClimbing: false, require: ["player"], add() { this.onCollideUpdate("climb", () => this.savedTimeOnLadder = time()) onKeyDown(param.upKey, () => this.climb(-1)); onKeyDown(param.downKey, () => this.climb(1)); this.on("climb start", () => { this.gravityScale = 0 this.vel = vec2(0, 0) this.isClimbing = true }) this.on("climb stop", () => { this.isClimbing = false this.gravityScale = 1 }) this.on("climb jump", () => this.jump(param.climbJump)) }, climb(d) { if (this.isAlive && this.isClimbing && this.onLadder) { this.move(0, d * param.climbSpeed) } }, update() { this.onLadder = time() - this.savedTimeOnLadder < param.delay if (!this.isClimbing && this.isAlive && this.onLadder && (param.sticky || isKeyDown(param.upKey))) this.trigger("climb start") else if (this.isClimbing && !this.onLadder) { if (isKeyDown(param.upKey)) this.trigger("climb jump") this.trigger("climb stop") } else if (this.isClimbing && this.isGrounded()) this.trigger("climb stop") else if (this.isClimbing && !param.catch && !isKeyDown(param.upKey)) this.trigger("climb stop") }, }}