Ring minigame !!
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"weight": 25,
|
||||
"seasons": ["spring", "summer", "autumn", "winter"],
|
||||
"biomes": ["#bworld:is_ocean"],
|
||||
"minigame": "valley",
|
||||
"minigame": "ring",
|
||||
"difficulty": 100
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// the screens of the base game's menus, see scripts/server.ts for their slots. in gui pixels, like minecraft's
|
||||
import type { ClientContext, ClientMenu, Graphics, ItemStack, MenuScreen } from "bworld/client";
|
||||
import type { ClientContext, ClientMenu, Color, Graphics, ItemStack, MenuScreen } from "bworld/client";
|
||||
|
||||
const WIDTH = 176;
|
||||
// like minecraft's 176x166 container screens
|
||||
@@ -148,6 +148,27 @@ const MINIGAME_SCREENS: Record<string, (menu: ClientMenu, fish: ItemStack) => Me
|
||||
},
|
||||
};
|
||||
},
|
||||
// the gray rings, green once they're checked, and the green one growing out from the middle, over the world. a
|
||||
// click sends button 1
|
||||
ring: (menu) => {
|
||||
const { rings, ring_radius, ring_spacing, ring_width } = menu.data;
|
||||
const size = 2 * (ring_radius + (rings - 1) * ring_spacing + ring_width);
|
||||
return {
|
||||
width: size,
|
||||
height: size,
|
||||
dim_background: false,
|
||||
inventory_overlays: false,
|
||||
on_render_labels(g) {
|
||||
if (g.mouse.pressed) menu.click_button(1);
|
||||
const { radius, checked } = menu.data;
|
||||
for (let i = 0; i < rings; i++) {
|
||||
const color: Color = i < checked ? [0.3, 0.85, 0.3, 0.9] : [0.8, 0.8, 0.8, 0.9];
|
||||
ring(g, size / 2, size / 2, ring_radius + i * ring_spacing, ring_width, color);
|
||||
}
|
||||
ring(g, size / 2, size / 2, radius, 2, [0.3, 0.85, 0.3, 1]);
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
// sends the server button 1 when the mouse is pressed and 0 when it's let go, for minigames you hold the mouse in.
|
||||
@@ -160,3 +181,14 @@ function mouse_sender(menu: ClientMenu): (g: Graphics) => void {
|
||||
menu.click_button(holding ? 1 : 0);
|
||||
};
|
||||
}
|
||||
|
||||
// a ring around x, y: squares as big as the line is thick, close enough around to look like one
|
||||
function ring(g: Graphics, x: number, y: number, radius: number, thickness: number, color: Color) {
|
||||
const steps = Math.max(8, Math.ceil(2 * Math.PI * radius / (thickness / 2)));
|
||||
for (let i = 0; i < steps; i++) {
|
||||
const angle = i / steps * 2 * Math.PI;
|
||||
const px = x + Math.cos(angle) * radius - thickness / 2;
|
||||
const py = y + Math.sin(angle) * radius - thickness / 2;
|
||||
g.rect(px, py, thickness, thickness, color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,6 +356,46 @@ class HoldMinigame extends FishingMinigame {
|
||||
}
|
||||
}
|
||||
|
||||
// gray rings, and a thin green one growing out from the middle, faster the harder the fish is: like hold's bar
|
||||
// emptying, 1 + difficulty / 100 pixels a tick, 1.1 at 10 and 2 at 100. there's a ring for every 30 difficulty, at
|
||||
// least one: 0 to 30 is 1, 31 to 60 is 2, and so on, each further out than the last. clicking (button 1) while the
|
||||
// green ring is inside the next unchecked one checks it, and checking them all lands the fish. clicking any other time
|
||||
// loses it, and so does letting the green ring grow past one. in gui pixels, radiuses to the middle of each ring's line
|
||||
const RING_RADIUS = 48;
|
||||
const RING_SPACING = 16;
|
||||
const RING_WIDTH = 8;
|
||||
const RING_START = 4;
|
||||
const RING_GROWTH = 1;
|
||||
class RingMinigame extends FishingMinigame {
|
||||
#radius = RING_START;
|
||||
#rings = Math.max(1, Math.ceil(this.difficulty / 30));
|
||||
#checked = 0;
|
||||
|
||||
constructor(...args: MinigameArgs) {
|
||||
super(...args);
|
||||
this.menu.add_data("radius", () => this.#radius);
|
||||
this.menu.add_data("rings", () => this.#rings);
|
||||
this.menu.add_data("checked", () => this.#checked);
|
||||
this.menu.add_data("ring_radius", () => RING_RADIUS);
|
||||
this.menu.add_data("ring_spacing", () => RING_SPACING);
|
||||
this.menu.add_data("ring_width", () => RING_WIDTH);
|
||||
this.menu.on_button((_player, id) => {
|
||||
if (id !== 1) return;
|
||||
if (Math.abs(this.#radius - this.#next_ring()) > RING_WIDTH / 2) return this.lose();
|
||||
if (++this.#checked === this.#rings) this.win();
|
||||
});
|
||||
this.menu.on_tick(() => {
|
||||
this.#radius += RING_GROWTH * (1 + this.difficulty / 100);
|
||||
if (this.#radius > this.#next_ring() + RING_WIDTH / 2) this.lose();
|
||||
});
|
||||
}
|
||||
|
||||
// the radius of the first ring that isn't checked
|
||||
#next_ring() {
|
||||
return RING_RADIUS + this.#checked * RING_SPACING;
|
||||
}
|
||||
}
|
||||
|
||||
// stardew valley's, ported from ports/stardewfishing's FishingMinigame: holding the mouse lifts a green bar up a track
|
||||
// and letting go drops it, while the fish darts up and down. points go up 1 a tick while the bar is on the fish and
|
||||
// down 1 while it isn't, starting at a fifth: all of them lands it, none loses it. the bar and points are in the
|
||||
@@ -465,4 +505,5 @@ const MINIGAMES: Record<string, new (...args: MinigameArgs) => FishingMinigame>
|
||||
test: TestMinigame,
|
||||
hold: HoldMinigame,
|
||||
valley: ValleyMinigame,
|
||||
ring: RingMinigame,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user