td-wavegen

Crates.iotd-wavegen
lib.rstd-wavegen
version1.0.0
sourcesrc
created_at2024-11-29 10:54:58.976214
updated_at2024-11-29 10:54:58.976214
descriptionTower Defense mob wave generator
homepage
repositoryhttps://gitlab.com/Aconitin/td-wavegen
max_upload_size
id1465506
size10,943
Sven (Aconitin)

documentation

README

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.

Commit count: 8

cargo fmt