Uninterruptible shooting animations (#49)

This commit is contained in:
PROMETHIA-27
2025-06-23 08:06:36 -04:00
committed by GitHub
parent b5d15187dd
commit 376ae8c770
3 changed files with 62 additions and 6 deletions

View File

@@ -1,4 +1,6 @@
use crate::{GameState, character::CharacterAnimations};
use crate::{
GameState, character::CharacterAnimations, head::ActiveHead, heads_database::HeadsDatabase,
};
use bevy::{animation::RepeatAnimation, ecs::query::QueryData, prelude::*};
use std::time::Duration;
@@ -71,24 +73,70 @@ fn update_animation(
&CharacterAnimations,
&mut AnimationFlags,
)>,
character: Query<&ActiveHead>,
headdb: Res<HeadsDatabase>,
) {
for (mut controller, anims, mut flags) in animated.iter_mut() {
if flags.shooting && flags.any_direction && anims.run_shoot.is_some() {
let head = character.get(anims.of_character).unwrap();
let head = headdb.head_stats(head.0);
let is_playing_shoot = anims.shoot.is_some()
&& controller.is_playing(anims.shoot.unwrap())
&& !controller
.player
.animation(anims.shoot.unwrap())
.unwrap()
.is_finished();
let is_playing_run_shoot = anims.run_shoot.is_some()
&& controller.is_playing(anims.run_shoot.unwrap())
&& !controller
.player
.animation(anims.run_shoot.unwrap())
.unwrap()
.is_finished();
let wait_for_shoot = !head.interrupt_shoot && (is_playing_shoot || is_playing_run_shoot);
if wait_for_shoot {
return;
} else if flags.shooting && flags.any_direction && anims.run_shoot.is_some() {
if !controller.is_playing(anims.run_shoot.unwrap()) {
controller.play(
anims.run_shoot.unwrap(),
DEFAULT_TRANSITION_DURATION,
RepeatAnimation::Forever,
RepeatAnimation::Never,
);
}
if controller
.player
.animation(anims.run_shoot.unwrap())
.unwrap()
.is_finished()
{
controller
.player
.animation_mut(anims.run_shoot.unwrap())
.unwrap()
.replay();
}
} else if flags.shooting && anims.shoot.is_some() {
if !controller.is_playing(anims.shoot.unwrap()) {
controller.play(
anims.shoot.unwrap(),
DEFAULT_TRANSITION_DURATION,
RepeatAnimation::Forever,
RepeatAnimation::Never,
);
}
if controller
.player
.animation(anims.shoot.unwrap())
.unwrap()
.is_finished()
{
controller
.player
.animation_mut(anims.shoot.unwrap())
.unwrap()
.replay();
}
} else if flags.hit {
if !controller.is_playing(anims.hit) {
controller.play(