feat: ghost animation states, frightened/eaten behaviors, smallvec animation arrays

This commit is contained in:
Ryan Walters
2025-09-01 11:46:18 -05:00
parent 8f504d6c77
commit 98196f3e07
10 changed files with 448 additions and 95 deletions

View File

@@ -1,3 +1,5 @@
use smallvec::SmallVec;
use crate::error::{AnimatedTextureError, GameError, GameResult, TextureError};
use crate::texture::sprite::AtlasTile;
@@ -8,7 +10,7 @@ use crate::texture::sprite::AtlasTile;
#[derive(Debug, Clone)]
pub struct AnimatedTexture {
/// Sequence of sprite tiles that make up the animation frames
tiles: Vec<AtlasTile>,
tiles: SmallVec<[AtlasTile; 4]>,
/// Duration each frame should be displayed (in seconds)
frame_duration: f32,
/// Index of the currently active frame in the tiles vector
@@ -18,7 +20,7 @@ pub struct AnimatedTexture {
}
impl AnimatedTexture {
pub fn new(tiles: Vec<AtlasTile>, frame_duration: f32) -> GameResult<Self> {
pub fn new(tiles: SmallVec<[AtlasTile; 4]>, frame_duration: f32) -> GameResult<Self> {
if frame_duration <= 0.0 {
return Err(GameError::Texture(TextureError::Animated(
AnimatedTextureError::InvalidFrameDuration(frame_duration),