mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-10 04:08:01 -06:00
refactor: unify ghost state management and animation handling, use integers for texture animation
This commit is contained in:
@@ -18,46 +18,41 @@ fn test_animated_texture_creation_errors() {
|
||||
let tiles = smallvec![mock_atlas_tile(1), mock_atlas_tile(2)];
|
||||
|
||||
assert!(matches!(
|
||||
AnimatedTexture::new(tiles.clone(), 0.0).unwrap_err(),
|
||||
GameError::Texture(TextureError::Animated(AnimatedTextureError::InvalidFrameDuration(0.0)))
|
||||
));
|
||||
|
||||
assert!(matches!(
|
||||
AnimatedTexture::new(tiles, -0.1).unwrap_err(),
|
||||
GameError::Texture(TextureError::Animated(AnimatedTextureError::InvalidFrameDuration(-0.1)))
|
||||
AnimatedTexture::new(tiles.clone(), 0).unwrap_err(),
|
||||
GameError::Texture(TextureError::Animated(AnimatedTextureError::InvalidFrameDuration(0)))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_animated_texture_advancement() {
|
||||
let tiles = smallvec![mock_atlas_tile(1), mock_atlas_tile(2), mock_atlas_tile(3)];
|
||||
let mut texture = AnimatedTexture::new(tiles, 0.1).unwrap();
|
||||
let mut texture = AnimatedTexture::new(tiles, 10).unwrap();
|
||||
|
||||
assert_eq!(texture.current_frame(), 0);
|
||||
|
||||
texture.tick(0.25);
|
||||
texture.tick(25);
|
||||
assert_eq!(texture.current_frame(), 2);
|
||||
assert!((texture.time_bank() - 0.05).abs() < 0.001);
|
||||
assert_eq!(texture.time_bank(), 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_animated_texture_wrap_around() {
|
||||
let tiles = smallvec![mock_atlas_tile(1), mock_atlas_tile(2)];
|
||||
let mut texture = AnimatedTexture::new(tiles, 0.1).unwrap();
|
||||
let mut texture = AnimatedTexture::new(tiles, 10).unwrap();
|
||||
|
||||
texture.tick(0.1);
|
||||
texture.tick(10);
|
||||
assert_eq!(texture.current_frame(), 1);
|
||||
|
||||
texture.tick(0.1);
|
||||
texture.tick(10);
|
||||
assert_eq!(texture.current_frame(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_animated_texture_single_frame() {
|
||||
let tiles = smallvec![mock_atlas_tile(1)];
|
||||
let mut texture = AnimatedTexture::new(tiles, 0.1).unwrap();
|
||||
let mut texture = AnimatedTexture::new(tiles, 10).unwrap();
|
||||
|
||||
texture.tick(0.1);
|
||||
texture.tick(10);
|
||||
assert_eq!(texture.current_frame(), 0);
|
||||
assert_eq!(texture.current_tile().color.unwrap().r, 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user