Files
bworld/mods/bworld/scripts/minigames/hold.ts
T
2026-10-12 15:09:22 -03:00

53 lines
1.7 KiB
TypeScript

// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
import { FishingMinigame, type MinigameArgs, type MinigameScreen, mouse_sender } from "./minigame.ts";
// "Hold !" and a bar from 0 to 10 seconds, starting half full. while the mouse is held (button 1, and 0 when it's let
// go) it fills a second a second, otherwise it empties faster the harder the fish is: 1 + difficulty / 100 seconds a
// second, 1.1 at 10 and 2 at 100. full lands the fish, empty loses it
const HOLD_MAX = 10 * 20;
export class HoldMinigame extends FishingMinigame {
#progress = HOLD_MAX / 2;
constructor(...args: MinigameArgs) {
super(...args);
this.menu.add_data("progress", () => this.#progress);
this.menu.add_data("max", () => HOLD_MAX);
this.listen_for_mouse();
this.menu.on_tick(() => {
this.#progress += this.holding ? 1 : -(1 + this.difficulty / 100);
if (this.#progress >= HOLD_MAX) {
this.win();
} else if (this.#progress <= 0) {
this.lose();
}
});
}
}
// "Hold !" and a bar under it, filling while the mouse is held. the server counts, this sends when the mouse is
// pressed (button 1) and let go (button 0)
export const hold_screen: MinigameScreen = (menu) => {
const width = 120;
const height = 44;
const send_mouse = mouse_sender(menu);
return {
width,
height,
dim_background: false,
inventory_overlays: false,
on_render_background(g) {
g.panel(0, 0, width, height);
},
on_render_labels(g) {
send_mouse(g);
const text = "Reel !";
g.text(text, (width - g.measure_text(text)) / 2, 8);
const done = menu.data.progress / menu.data.max || 0;
g.rect(10, 26, width - 20, 8, [0.15, 0.1, 0.05, 1]);
g.rect(10, 26, (width - 20) * done, 8, [0.3, 0.8, 0.3, 1]);
},
};
};