From 6f95a8fd9fbb7b98db16da12fd300d6b9637ccde Mon Sep 17 00:00:00 2001 From: Carson Webster Date: Sat, 9 Dec 2023 14:59:13 -0800 Subject: [PATCH] Bee sprite and wing animations --- Cargo.lock | 34 ++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/bees.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++----- src/boids.rs | 28 +++++++++++++------------- src/lib.rs | 4 ++-- src/loading.rs | 15 +++++++++++++- src/tilemap.rs | 2 +- 7 files changed, 114 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 27e0050..3f2d13a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -705,6 +705,7 @@ dependencies = [ "image", "quadtree", "rand", + "time", "webbrowser", "winit", ] @@ -1682,6 +1683,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" +[[package]] +name = "deranged" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eb30d70a07a3b04884d2677f06bec33509dc67ca60d92949e5535352d3191dc" +dependencies = [ + "powerfmt", +] + [[package]] name = "derive-getters" version = "0.3.0" @@ -3131,6 +3141,12 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "pp-rs" version = "0.2.1" @@ -3729,6 +3745,24 @@ dependencies = [ "weezl", ] +[[package]] +name = "time" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" +dependencies = [ + "deranged", + "powerfmt", + "serde", + "time-core", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + [[package]] name = "tinyvec" version = "1.6.0" diff --git a/Cargo.toml b/Cargo.toml index 5c58660..65384d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,6 +70,7 @@ bevy_ecs_tilemap = { git = "https://github.com/divark/bevy_ecs_tilemap", branch bevy_ecs_ldtk = { git = "https://github.com/Trouv/bevy_ecs_ldtk.git", branch = "feat/bevy-0.12" } bevy-inspector-egui = "0.21.0" quadtree = { git = "https://github.com/MickHarrigan/quadtree.git" } +time = "0.3.30" [build-dependencies] diff --git a/src/bees.rs b/src/bees.rs index f12acb4..f69d52e 100644 --- a/src/bees.rs +++ b/src/bees.rs @@ -26,6 +26,7 @@ impl Plugin for BeesPlugin { .add_systems(OnEnter(GameState::Playing), setup) .add_systems(Update, create_boid_group.run_if(in_state(GameState::Playing))) .add_systems(Update, place_bee.run_if(in_state(GameState::Playing))) + .add_systems(Update, animate_wings.run_if(in_state(GameState::Playing))) .add_systems( Update, (build_or_update_quadtree, update_boids, move_system).run_if( @@ -154,6 +155,33 @@ fn setup(mut _commands: Commands) { // }); } +#[derive(Component)] +struct AnimationIndices { + first: usize, + last: usize, +} +#[derive(Component, Deref, DerefMut)] +struct AnimationTimer(Timer); + +fn animate_wings( + time: Res