import Vec2 from "./Vec2.js"; export default class Shaker { constructor(decay = 7) { this.vec = new Vec2(); this.decay = decay; this.shakeX = 0; this.shakeY = 0; } shake(x, y = x) { this.shakeX = x; this.shakeY = y; } update(dt) { if (this.shakeX > 0.1) this.vec.x = (Math.random() - 0.5) * this.shakeX * dt; if (this.shakeY > 0.1) this.vec.y = (Math.random() - 0.5) * this.shakeY * dt; var xRatio = 1 / (1 + (dt * this.decay)); this.shakeX *= xRatio; this.shakeY *= xRatio; } }