diff --git a/Cargo.lock b/Cargo.lock index 7321ccd..c73732b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -732,12 +732,43 @@ dependencies = [ "thread_local", ] +[[package]] +name = "bevy_prng" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08497116068623556e67e59b0204f5d9d8e7a2d4fd378f87c9c798f7af93f236" +dependencies = [ + "bevy", + "rand_chacha", + "rand_core", + "rand_pcg", + "rand_xoshiro", + "serde", + "serde_derive", + "wyrand", +] + [[package]] name = "bevy_ptr" version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8050e2869fe341db6874203b5a01ff12673807a2c7c80cb829f6c7bea6997268" +[[package]] +name = "bevy_rand" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c98c3be37468a6008cf0bb392e3decff0fc062898570b0ea4543fa6e9355bf7a" +dependencies = [ + "bevy", + "bevy_prng", + "getrandom", + "rand_chacha", + "rand_core", + "serde", + "serde_derive", +] + [[package]] name = "bevy_rapier2d" version = "0.25.0" @@ -1054,7 +1085,9 @@ name = "bin-projekt" version = "0.1.0" dependencies = [ "bevy", + "bevy_rand", "bevy_rapier2d", + "rand", "some_bevy_tools", ] @@ -2878,6 +2911,12 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "presser" version = "0.3.1" @@ -2923,6 +2962,58 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17fd96390ed3feda12e1dfe2645ed587e0bea749e319333f104a33ff62f77a0b" +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", + "serde", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", + "serde", +] + +[[package]] +name = "rand_pcg" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e" +dependencies = [ + "rand_core", + "serde", +] + +[[package]] +name = "rand_xoshiro" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" +dependencies = [ + "rand_core", + "serde", +] + [[package]] name = "range-alloc" version = "0.1.3" @@ -4143,6 +4234,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "wyrand" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dadc56f0dc130aa22c0d2fe303ccee3a2ad429c87d257642e96017920c66ed0" +dependencies = [ + "rand_core", + "serde", +] + [[package]] name = "x11-dl" version = "2.21.0" diff --git a/Cargo.toml b/Cargo.toml index d866544..29b48e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,9 @@ edition = "2021" [dependencies] # bevy = { version = "0.13.0", features = ["dynamic_linking"] } bevy = "0.13" +bevy_rand = { version = "0.6.0", features = ["wyrand"] } bevy_rapier2d = { version = "0.25.0", features = [ "simd-stable", "debug-render-2d" ] } +rand = { version = "0.8.5", features = ["small_rng"] } some_bevy_tools = "0.2.4" # Enable a small amount of optimization in debug mode diff --git a/assets/sprites/enemy.png b/assets/sprites/enemy.png new file mode 100644 index 0000000..ea4d074 Binary files /dev/null and b/assets/sprites/enemy.png differ diff --git a/src/enemy.rs b/src/enemy.rs new file mode 100644 index 0000000..90ef132 --- /dev/null +++ b/src/enemy.rs @@ -0,0 +1,94 @@ +use bevy::prelude::*; +use bevy_rand::{prelude::WyRand, resource::GlobalEntropy}; +use rand::Rng; + +use crate::METER; + +#[derive(Debug, Event)] +pub struct SpawnEvent { + pos: (f32, f32), + spawner: Entity, +} + +#[derive(Component)] +pub struct Spawner { + pos: (f32, f32), + size: (f32, f32), + spawn_cooldown: Timer, + cur_enemies: u8, + max_enemies: u8, + amount_range: std::ops::Range, +} + +pub fn enemies_plugin(app: &mut App) { + app.add_event::() + .add_systems(Startup, setup_spawners) + .add_systems(Update, (spawn_enemies, do_spawn)); +} + +pub fn setup_spawners(mut commands: Commands) { + commands.spawn(Spawner { + pos: (-6.5 * METER, 5.5 * METER), + size: (14. * METER, 1.5 * METER), + spawn_cooldown: Timer::from_seconds(5., TimerMode::Repeating), + cur_enemies: 0, + max_enemies: 10, + amount_range: 2..4, + }); +} + +#[derive(Component)] +pub struct Enemy; + +// TODO: waves n stuff +// and gamestate lolz +pub fn spawn_enemies( + mut ev_spawn: EventWriter, + mut rng: ResMut>, + mut query: Query<(Entity, &mut Spawner)>, + time: Res