Ring minigame !!
This commit is contained in:
@@ -147,14 +147,14 @@ The fishing table, `bworld:gameplay/fishing`, isn't a file: the base game builds
|
||||
}
|
||||
```
|
||||
|
||||
| Field | What |
|
||||
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `weight` | How often it's caught against the other fish, 1 when not given. |
|
||||
| `seasons` | The [seasons](../worldgen/biomes.md#seasons) it's caught in where the hook is, every one when not given. |
|
||||
| `biomes` | The [biomes](../worldgen/biomes.md#biome-ids) and [biome tags](../worldgen/biomes.md#biome-tags) it's caught in where the hook is, every one when not given. |
|
||||
| `time` | The hours it's caught at on a 24 hour clock, from `from` up to `to`, like `6.5` for 06:30. When `from` is past `to` it wraps around midnight. All day when not given. |
|
||||
| `minigame` | What the player does to land it once it's reeled in, in a screen that holds the fish until they win. Closing it lets the fish get away. Caught right away when not given. The base game's are `"test"`, a Catch button, `"hold"`, a bar that fills while the mouse is held and empties while it isn't: full lands the fish, empty loses it, and `"valley"`, Stardew Valley's, where holding the mouse lifts a bar to keep the fish in it. |
|
||||
| `difficulty` | How hard its minigame is, 10 when not given. In `"hold"`, the bar empties `1 + difficulty / 100` times as fast as it fills: 1.1 at 10, 2 at 100. In `"valley"`, it's Stardew Valley's fish difficulty: the higher, the more the fish darts around. |
|
||||
| Field | What |
|
||||
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `weight` | How often it's caught against the other fish, 1 when not given. |
|
||||
| `seasons` | The [seasons](../worldgen/biomes.md#seasons) it's caught in where the hook is, every one when not given. |
|
||||
| `biomes` | The [biomes](../worldgen/biomes.md#biome-ids) and [biome tags](../worldgen/biomes.md#biome-tags) it's caught in where the hook is, every one when not given. |
|
||||
| `time` | The hours it's caught at on a 24 hour clock, from `from` up to `to`, like `6.5` for 06:30. When `from` is past `to` it wraps around midnight. All day when not given. |
|
||||
| `minigame` | What the player does to land it once it's reeled in, in a screen that holds the fish until they win. Closing it lets the fish get away. Caught right away when not given. The base game's are `"test"`, a Catch button, `"hold"`, a bar that fills while the mouse is held and empties while it isn't: full lands the fish, empty loses it, `"valley"`, Stardew Valley's, where holding the mouse lifts a bar to keep the fish in it, and `"ring"`, where a green ring grows out toward a gray one and clicking while it's inside lands the fish. |
|
||||
| `difficulty` | How hard its minigame is, 10 when not given. In `"hold"`, the bar empties `1 + difficulty / 100` times as fast as it fills: 1.1 at 10, 2 at 100. In `"ring"`, the green ring grows `1 + difficulty / 100` times as fast, and there's a gray ring to click for every 30 difficulty: 1 up to 30, 2 up to 60, 3 up to 90, 4 up to 120. In `"valley"`, it's Stardew Valley's fish difficulty: the higher, the more the fish darts around. |
|
||||
|
||||
When every fish can be ruled out, nothing is caught, so keep one that's always caught.
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -389,3 +389,118 @@ Deno.test("harder valley fish move around more", async () => {
|
||||
assert(hard > easy * 2, `${hard} isn't much more than ${easy}`);
|
||||
}, "valley");
|
||||
});
|
||||
|
||||
Deno.test("the ring minigame lands the fish when clicked with the green ring in the gray one", async () => {
|
||||
const t = await setup();
|
||||
// at difficulty 0 it grows 1 a tick
|
||||
await with_minigames(() =>
|
||||
with_difficulty(0, async () => {
|
||||
const open = () => {
|
||||
t.send(1, { type: "chat", text: "/fish cod" });
|
||||
return opened_menu(t.take(1));
|
||||
};
|
||||
const closes = () => t.take(1).some((m: Msg) => m.type === "close_menu");
|
||||
|
||||
// too early: the green ring starts at 4, the gray one is from 44 to 52
|
||||
let opened = open();
|
||||
assertEquals(opened.data, {
|
||||
radius: 4,
|
||||
rings: 1,
|
||||
checked: 0,
|
||||
ring_radius: 48,
|
||||
ring_spacing: 16,
|
||||
ring_width: 8,
|
||||
});
|
||||
for (let i = 0; i < 30; i++) t.game.tick();
|
||||
t.send(1, { type: "menu_button", menu: opened.id, button: 1 });
|
||||
t.game.tick();
|
||||
assert(closes());
|
||||
assertEquals(t.fish().length, 0);
|
||||
|
||||
// too late: past 52 it's gone
|
||||
opened = open();
|
||||
for (let i = 0; i < 48; i++) t.game.tick();
|
||||
assert(!closes());
|
||||
t.game.tick();
|
||||
t.game.tick();
|
||||
assert(closes());
|
||||
assertEquals(t.fish().length, 0);
|
||||
|
||||
// in it
|
||||
opened = open();
|
||||
for (let i = 0; i < 44; i++) t.game.tick();
|
||||
assertEquals(menu_data(t.take(1))?.radius, 48);
|
||||
t.send(1, { type: "menu_button", menu: opened.id, button: 1 });
|
||||
assertEquals(t.fish().map((i: Msg) => i.id), ["bworld:cod"]);
|
||||
}), "ring");
|
||||
});
|
||||
|
||||
Deno.test("the ring minigame's green ring grows faster the harder the fish is", async () => {
|
||||
const t = await setup();
|
||||
let radius = 0;
|
||||
// how big it is after 10 ticks, from 4
|
||||
const after_10_ticks = (difficulty: number | undefined) =>
|
||||
with_difficulty(difficulty, async () => {
|
||||
t.send(1, { type: "chat", text: "/fish cod" });
|
||||
t.take(1);
|
||||
for (let i = 0; i < 10; i++) t.game.tick();
|
||||
radius = menu_data(t.take(1))?.radius;
|
||||
});
|
||||
await with_minigames(async () => {
|
||||
await after_10_ticks(undefined);
|
||||
assertAlmostEquals(radius, 4 + 11);
|
||||
await after_10_ticks(100);
|
||||
assertEquals(radius, 4 + 20);
|
||||
}, "ring");
|
||||
});
|
||||
|
||||
Deno.test("the ring minigame has a ring for every 30 difficulty", async () => {
|
||||
const t = await setup();
|
||||
const rings: number[] = [];
|
||||
await with_minigames(async () => {
|
||||
for (const difficulty of [0, 30, 31, 60, 61, 90, 91, 120]) {
|
||||
await with_difficulty(difficulty, async () => {
|
||||
t.send(1, { type: "chat", text: "/fish cod" });
|
||||
rings.push(opened_menu(t.take(1)).data.rings);
|
||||
});
|
||||
}
|
||||
}, "ring");
|
||||
assertEquals(rings, [1, 1, 2, 2, 3, 3, 4, 4]);
|
||||
});
|
||||
|
||||
Deno.test("the ring minigame needs every ring checked, and missing one loses it", async () => {
|
||||
const t = await setup();
|
||||
const closes = () => t.take(1).some((m: Msg) => m.type === "close_menu");
|
||||
// at 60 there are 2 rings, at 48 and 64, and the green ring grows 1.6 a tick from 4
|
||||
await with_minigames(() =>
|
||||
with_difficulty(60, async () => {
|
||||
t.send(1, { type: "chat", text: "/fish cod" });
|
||||
let opened = opened_menu(t.take(1));
|
||||
for (let i = 0; i < 26; i++) t.game.tick(); // 45.6
|
||||
t.send(1, { type: "menu_button", menu: opened.id, button: 1 });
|
||||
assertEquals(menu_data(t.take(1))?.checked, 1);
|
||||
assertEquals(t.fish().length, 0);
|
||||
for (let i = 0; i < 11; i++) t.game.tick(); // 63.2
|
||||
t.send(1, { type: "menu_button", menu: opened.id, button: 1 });
|
||||
assertEquals(t.fish().map((i: Msg) => i.id), ["bworld:cod"]);
|
||||
|
||||
// checking the first and letting the green ring past the second
|
||||
t.send(1, { type: "chat", text: "/fish cod" });
|
||||
opened = opened_menu(t.take(1));
|
||||
for (let i = 0; i < 26; i++) t.game.tick();
|
||||
t.send(1, { type: "menu_button", menu: opened.id, button: 1 });
|
||||
for (let i = 0; i < 15; i++) t.game.tick(); // 71.2
|
||||
assert(closes());
|
||||
assertEquals(t.fish().length, 1);
|
||||
|
||||
// clicking twice in the first: the second click isn't in the second ring
|
||||
t.send(1, { type: "chat", text: "/fish cod" });
|
||||
opened = opened_menu(t.take(1));
|
||||
for (let i = 0; i < 26; i++) t.game.tick();
|
||||
t.send(1, { type: "menu_button", menu: opened.id, button: 1 });
|
||||
t.send(1, { type: "menu_button", menu: opened.id, button: 1 });
|
||||
t.game.tick();
|
||||
assert(closes());
|
||||
assertEquals(t.fish().length, 1);
|
||||
}), "ring");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user