mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-08 02:07:56 -06:00
refactor: move animation components into new systems/animation submodule
This commit is contained in:
@@ -1,13 +1,12 @@
|
|||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
component::Component,
|
component::Component,
|
||||||
query::{Has, Or, With, Without},
|
query::{Has, Or, With, Without},
|
||||||
resource::Resource,
|
|
||||||
system::{Query, Res},
|
system::{Query, Res},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
systems::{DeltaTime, Dying, Frozen, Position, Renderable, Velocity},
|
systems::{DeltaTime, Dying, Frozen, LinearAnimation, Looping, Position, Renderable, Velocity},
|
||||||
texture::animated::{DirectionalTiles, TileSequence},
|
texture::animated::DirectionalTiles,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Directional animation component with shared timing across all directions
|
/// Directional animation component with shared timing across all directions
|
||||||
@@ -33,33 +32,6 @@ impl DirectionalAnimation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tag component to mark animations that should loop when they reach the end
|
|
||||||
#[derive(Component, Clone, Copy, Debug, PartialEq, Eq)]
|
|
||||||
pub struct Looping;
|
|
||||||
|
|
||||||
/// Linear animation component for non-directional animations (frightened ghosts)
|
|
||||||
#[derive(Component, Resource, Clone)]
|
|
||||||
pub struct LinearAnimation {
|
|
||||||
pub tiles: TileSequence,
|
|
||||||
pub current_frame: usize,
|
|
||||||
pub time_bank: u16,
|
|
||||||
pub frame_duration: u16,
|
|
||||||
pub finished: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LinearAnimation {
|
|
||||||
/// Creates a new linear animation with the given tiles and frame duration
|
|
||||||
pub fn new(tiles: TileSequence, frame_duration: u16) -> Self {
|
|
||||||
Self {
|
|
||||||
tiles,
|
|
||||||
current_frame: 0,
|
|
||||||
time_bank: 0,
|
|
||||||
frame_duration,
|
|
||||||
finished: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Updates directional animated entities with synchronized timing across directions.
|
/// Updates directional animated entities with synchronized timing across directions.
|
||||||
///
|
///
|
||||||
/// This runs before the render system to update sprites based on current direction and movement state.
|
/// This runs before the render system to update sprites based on current direction and movement state.
|
||||||
30
src/systems/animation/linear.rs
Normal file
30
src/systems/animation/linear.rs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
use crate::texture::animated::TileSequence;
|
||||||
|
use bevy_ecs::component::Component;
|
||||||
|
use bevy_ecs::resource::Resource;
|
||||||
|
|
||||||
|
/// Tag component to mark animations that should loop when they reach the end
|
||||||
|
#[derive(Component, Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
pub struct Looping;
|
||||||
|
|
||||||
|
/// Linear animation component for non-directional animations (frightened ghosts)
|
||||||
|
#[derive(Component, Resource, Clone)]
|
||||||
|
pub struct LinearAnimation {
|
||||||
|
pub tiles: TileSequence,
|
||||||
|
pub current_frame: usize,
|
||||||
|
pub time_bank: u16,
|
||||||
|
pub frame_duration: u16,
|
||||||
|
pub finished: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LinearAnimation {
|
||||||
|
/// Creates a new linear animation with the given tiles and frame duration
|
||||||
|
pub fn new(tiles: TileSequence, frame_duration: u16) -> Self {
|
||||||
|
Self {
|
||||||
|
tiles,
|
||||||
|
current_frame: 0,
|
||||||
|
time_bank: 0,
|
||||||
|
frame_duration,
|
||||||
|
finished: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
7
src/systems/animation/mod.rs
Normal file
7
src/systems/animation/mod.rs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
mod blinking;
|
||||||
|
mod directional;
|
||||||
|
mod linear;
|
||||||
|
|
||||||
|
pub use self::blinking::*;
|
||||||
|
pub use self::directional::*;
|
||||||
|
pub use self::linear::*;
|
||||||
@@ -10,12 +10,11 @@ pub mod profiling;
|
|||||||
#[cfg_attr(coverage_nightly, coverage(off))]
|
#[cfg_attr(coverage_nightly, coverage(off))]
|
||||||
pub mod render;
|
pub mod render;
|
||||||
|
|
||||||
pub mod animation;
|
mod animation;
|
||||||
pub mod blinking;
|
mod collision;
|
||||||
pub mod collision;
|
|
||||||
pub mod common;
|
pub mod common;
|
||||||
pub mod ghost;
|
mod ghost;
|
||||||
pub mod hud;
|
mod hud;
|
||||||
pub mod input;
|
pub mod input;
|
||||||
pub mod item;
|
pub mod item;
|
||||||
pub mod lifetime;
|
pub mod lifetime;
|
||||||
@@ -27,7 +26,6 @@ pub mod state;
|
|||||||
|
|
||||||
pub use self::animation::*;
|
pub use self::animation::*;
|
||||||
pub use self::audio::*;
|
pub use self::audio::*;
|
||||||
pub use self::blinking::*;
|
|
||||||
pub use self::collision::*;
|
pub use self::collision::*;
|
||||||
pub use self::common::*;
|
pub use self::common::*;
|
||||||
pub use self::debug::*;
|
pub use self::debug::*;
|
||||||
|
|||||||
Reference in New Issue
Block a user