From 86f8df16b16bbba46b6e3b1a109980e140aeb915 Mon Sep 17 00:00:00 2001 From: Andrea Manzi Date: Sat, 24 Oct 2026 23:47:04 +0200 Subject: [PATCH] I cipressi ondeggiano morbidi, tutti interi dalla base, invece che a fasce Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01ApqNBvNbNCwXqR2RLo8QJh --- src/engine/render.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/engine/render.js b/src/engine/render.js index 6f1bdbb..94d02b5 100644 --- a/src/engine/render.js +++ b/src/engine/render.js @@ -331,17 +331,20 @@ export const EFFECTS = { ctx.fillRect(x + 2, y - up, 2, 1); } }, - // Alberi al vento (i cipressi): un pezzo di sfondo ridisegnato inclinato appena, più in cima che alla base. + // Alberi al vento (i cipressi): il pezzo di sfondo si piega tutto insieme dalla base, di frazioni di pixel e con + // due onde lente sovrapposte, così il movimento è morbido e non a scatti. sway(ctx, e, time, game) { const bg = backgrounds.get(game.scene.background); if (!bg) return; - const k = bg.width / WIDTH; + const k = bg.width / WIDTH, amount = e.amount ?? 1.2; for (const [i, [x, y, w, h]] of e.rects.entries()) { - const a = Math.sin(time / (e.speed ?? 900) + i * 1.3) * (e.amount ?? 1.6); - for (let r = 0; r < h; r += 2) { - const dx = Math.round(a * (1 - r / h)); - if (dx) ctx.drawImage(bg, x * k, (y + r) * k, w * k, 2 * k, x + dx, y + r, w, 2); - } + const a = amount * (0.65 * Math.sin(time / 1900 + i * 1.7) + 0.35 * Math.sin(time / 830 + i * 2.9)); + ctx.save(); + ctx.imageSmoothingEnabled = true; + ctx.translate(x, y + h); + ctx.transform(1, 0, -a / h, 1, 0, 0); + ctx.drawImage(bg, x * k, y * k, w * k, h * k, 0, -h, w, h); + ctx.restore(); } }, // Lampioni: un alone caldo che si accende (di solito solo di sera, con `phase`).