From dc165d3c138e938ee2ddc976d010ee006f2a2bb3 Mon Sep 17 00:00:00 2001 From: Thom Bruce Date: Tue, 10 Oct 2023 00:45:26 +0100 Subject: [PATCH] move planet and star setup to own modules --- CHANGELOG.md | 2 + src/astronomy/planet.rs | 46 +++++++++++- src/astronomy/planetary_system.rs | 119 +++++++----------------------- src/astronomy/star.rs | 55 +++++++++++++- src/effects/animate.rs | 45 +++++++++++ src/effects/mod.rs | 1 + src/main.rs | 3 +- 7 files changed, 175 insertions(+), 96 deletions(-) create mode 100644 src/effects/animate.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bc74aa..fda8a76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Indicators now appear in circle close to player ship for better readability - Add transparency to indicators +- Moved bulk of planet and star setup to own modules - Renamed AppState to GameState for better clarity - Improved readability and versatility of assets with bevy_asset_loader - Moved menu music loading from main to menu module @@ -23,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Moved assets, camera, game_time and state to resources module - Moved credits, pause and start_menu to menus module - Moved blink effect to effects module +- Moved animation to effects module ## [0.0.12] - 2023-10-07 diff --git a/src/astronomy/planet.rs b/src/astronomy/planet.rs index eb48a27..0bb36be 100644 --- a/src/astronomy/planet.rs +++ b/src/astronomy/planet.rs @@ -1,4 +1,48 @@ use bevy::prelude::*; +use crate::{ + effects::animate::{AnimationBundle, AnimationIndices, AnimationTimer}, + hud::indicator::Indicated, +}; + +use super::orbit::{Orbit, Orbitable}; + +const PLANET_ANIMATION_INDICES: AnimationIndices = AnimationIndices { + first: 0, + last: 124, +}; + #[derive(Component, Clone, Debug)] -pub struct Planet {} +pub struct Planet; + +#[derive(Bundle)] +pub struct PlanetBundle { + pub name: Name, + pub marker: Planet, + pub indicated: Indicated, + pub orbitable: Orbitable, + pub orbit: Orbit, + pub animation_bundle: AnimationBundle, + pub sprite_sheet_bundle: SpriteSheetBundle, +} +impl Default for PlanetBundle { + fn default() -> Self { + Self { + name: Name::new("Planet"), + marker: Planet, + indicated: Indicated { + color: Color::ORANGE_RED, + }, + orbitable: Orbitable::default(), + orbit: Orbit { + parent: None, + semi_major_axis: 0., + }, + animation_bundle: AnimationBundle { + indices: PLANET_ANIMATION_INDICES, + timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)), + }, + sprite_sheet_bundle: SpriteSheetBundle::default(), + } + } +} diff --git a/src/astronomy/planetary_system.rs b/src/astronomy/planetary_system.rs index c4ea3ca..c422c16 100644 --- a/src/astronomy/planetary_system.rs +++ b/src/astronomy/planetary_system.rs @@ -6,9 +6,9 @@ use crate::{ }; use super::{ - orbit::{Orbit, OrbitPlugin, Orbitable}, - planet::Planet, - star::Star, + orbit::{Orbit, OrbitPlugin}, + planet::{Planet, PlanetBundle}, + star::{Star, StarBundle}, }; pub struct PlanetarySystemPlugin; @@ -27,63 +27,11 @@ impl Plugin for PlanetarySystemPlugin { ) .chain(), ); - app.add_systems(Update, animate_sprite.run_if(in_state(GameState::Active))); - } -} - -#[derive(Component, Clone, Copy)] -struct AnimationIndices { - first: usize, - last: usize, -} - -#[derive(Component, Deref, DerefMut)] -struct AnimationTimer(Timer); - -fn animate_sprite( - time: Res