5 stable releases

1.2.0 Dec 25, 2024
1.0.3 Dec 23, 2024
1.0.0 Nov 29, 2024

#801 in Data structures

Download history 116/week @ 2024-11-26 24/week @ 2024-12-03 7/week @ 2024-12-10 140/week @ 2024-12-17 410/week @ 2024-12-24 2/week @ 2024-12-31

560 downloads per month

MIT/Apache

12KB
220 lines

td-wavegen

A helper library for generating waves of mobs for e.g. TD-type levels.

Specify a cost for each mob and a budget function (giving you a certain budget per wave) and this will provide a set of mobs for each wave. E.g. if you create a waves generator like this:

let mob_type_a = MobType { index: 1, cost: 1 };
let mob_type_b = MobType { index: 2, cost: 3 };
let mob_type_c = MobType { index: 3, cost: 5 };

let mob_types = vec![mob_type_a, mob_type_c, mob_type_b];

let mut waves = Waves::builder()
    .with_mob_types(mob_types)
    .with_starting_wave(2)
    .with_cost_function(|wave| wave * 3)
    .build();

... then you can use it like an iterator, e.g. like this:

let wave_1 = waves.next();
let wave_2 = waves.next();
let wave_3 = waves.next();

... or in a loop, to get a list of mobs you need to spawn each wave in your game.

The cost function defined above sets a budget for each wave, and the library will, for each wave, keep trying to "buy" mobs into the current wave set until it runs out of budget.

You can also generate a wave directly by supplying a maximum budget like this:

let mob_type_a = MobType { index: 1, cost: 2 };
let mob_type_b = MobType { index: 2, cost: 4 };

let mob_types = vec![mob_type_b, mob_type_a];

let wave: Wave = Wave::gen_from_max_total_cost(7, &mob_types);

Note that currently, it starts buying at the most expensive mob and moves downwards from there. Different buying strategies are WIP.

No runtime deps