diff --git a/src/features/r50-jump-puff.js b/src/features/r50-jump-puff.js new file mode 100644 index 0000000..c96f168 --- /dev/null +++ b/src/features/r50-jump-puff.js @@ -0,0 +1,15 @@ +// #50: double jump for everyone. A small puff under the cat on the second jump. +import { PAL } from "../palette.js"; +export default { + id: "jump-puff-50", + order: 55, + layer: "fg", + draw(g, w) { + const p = w.player; if (!p || !p.puffT || w.reduced) return; + const r = Math.round((0.25 - p.puffT) * 24); + g.fillStyle = PAL.playerShade; + g.fillRect(Math.round(p.x) - 3 - r, Math.round(p.y) + 1, 2, 1); + g.fillRect(Math.round(p.x) + 2 + r, Math.round(p.y) + 1, 2, 1); + g.fillRect(Math.round(p.x) - 1, Math.round(p.y) + 2 + (r >> 1), 2, 1); + }, +}; diff --git a/src/player.js b/src/player.js index f377946..6fabb47 100644 --- a/src/player.js +++ b/src/player.js @@ -4,12 +4,16 @@ import { solidBelow } from "./world.js"; export const SPEED = 82, JUMP = 205, GRAV = 560; export function makePlayer() { return { - x: 24, y: 40, vx: 0, vy: 0, f: 1, onGround: false, walk: 0, emote: null, emoteT: 0, jumps: 1, + x: 24, y: 40, vx: 0, vy: 0, f: 1, onGround: false, walk: 0, emote: null, emoteT: 0, jumps: 2, puffT: 0, update(dt, w, input) { const dir = (input.held("right") ? 1 : 0) - (input.held("left") ? 1 : 0); this.vx = dir * SPEED; if (dir) this.f = dir; this.walk = dir && this.onGround ? this.walk + dt : 0; - if (input.take("jump") && (this.onGround || this.jumpsLeft > 0)) { if (!this.onGround) this.jumpsLeft--; this.vy = -JUMP; this.onGround = false; } + if (input.take("jump") && (this.onGround || this.jumpsLeft > 0)) { + if (!this.onGround) { this.jumpsLeft--; this.puffT = 0.25; } + this.vy = -JUMP; this.onGround = false; + } + this.puffT = Math.max(0, this.puffT - dt); for (let i = 0; i < 4; i++) if (input.take("e" + i)) { this.emote = i; this.emoteT = 2; } this.emoteT = Math.max(0, this.emoteT - dt); if (!this.emoteT) this.emote = null; this.vy = Math.min(320, this.vy + GRAV * dt);