Uninterruptible shooting animations (#49)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
([
|
([
|
||||||
/*00*/(key:"angry demonstrator", ability:Thrown, aps:2, ammo:10, range:90, damage:25, projectile:"molotov"),
|
/*00*/(key:"angry demonstrator", ability:Thrown, aps:2, ammo:10, range:90, damage:25, projectile:"molotov", interrupt_shoot:false),
|
||||||
/*01*/(key:"carnival knife thrower", ability:Arrow, range:60, ammo:5),
|
/*01*/(key:"carnival knife thrower", ability:Arrow, range:60, ammo:5),
|
||||||
/*02*/(key:"chicago gangster", ability:Gun, ammo:25, range:60),
|
/*02*/(key:"chicago gangster", ability:Gun, ammo:25, range:60),
|
||||||
/*03*/(key:"commando", ability:Gun, aps:7.4, ammo:26, range:60, damage:12),
|
/*03*/(key:"commando", ability:Gun, aps:7.4, ammo:26, range:60, damage:12),
|
||||||
|
|||||||
@@ -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 bevy::{animation::RepeatAnimation, ecs::query::QueryData, prelude::*};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@@ -71,24 +73,70 @@ fn update_animation(
|
|||||||
&CharacterAnimations,
|
&CharacterAnimations,
|
||||||
&mut AnimationFlags,
|
&mut AnimationFlags,
|
||||||
)>,
|
)>,
|
||||||
|
character: Query<&ActiveHead>,
|
||||||
|
headdb: Res<HeadsDatabase>,
|
||||||
) {
|
) {
|
||||||
for (mut controller, anims, mut flags) in animated.iter_mut() {
|
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()) {
|
if !controller.is_playing(anims.run_shoot.unwrap()) {
|
||||||
controller.play(
|
controller.play(
|
||||||
anims.run_shoot.unwrap(),
|
anims.run_shoot.unwrap(),
|
||||||
DEFAULT_TRANSITION_DURATION,
|
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() {
|
} else if flags.shooting && anims.shoot.is_some() {
|
||||||
if !controller.is_playing(anims.shoot.unwrap()) {
|
if !controller.is_playing(anims.shoot.unwrap()) {
|
||||||
controller.play(
|
controller.play(
|
||||||
anims.shoot.unwrap(),
|
anims.shoot.unwrap(),
|
||||||
DEFAULT_TRANSITION_DURATION,
|
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 {
|
} else if flags.hit {
|
||||||
if !controller.is_playing(anims.hit) {
|
if !controller.is_playing(anims.hit) {
|
||||||
controller.play(
|
controller.play(
|
||||||
|
|||||||
@@ -24,9 +24,13 @@ pub struct HeadStats {
|
|||||||
pub ammo: u32,
|
pub ammo: u32,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub damage: u32,
|
pub damage: u32,
|
||||||
// ability per second
|
/// ability per second
|
||||||
#[serde(default = "default_aps")]
|
#[serde(default = "default_aps")]
|
||||||
pub aps: f32,
|
pub aps: f32,
|
||||||
|
#[serde(default = "default_interrupt_shoot")]
|
||||||
|
pub interrupt_shoot: bool,
|
||||||
|
#[serde(default)]
|
||||||
|
pub shoot_offset: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_aps() -> f32 {
|
fn default_aps() -> f32 {
|
||||||
@@ -37,6 +41,10 @@ fn default_ammo() -> u32 {
|
|||||||
10
|
10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn default_interrupt_shoot() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Asset, Reflect, Serialize, Deserialize)]
|
#[derive(Debug, Asset, Reflect, Serialize, Deserialize)]
|
||||||
pub struct HeadDatabaseAsset(pub Vec<HeadStats>);
|
pub struct HeadDatabaseAsset(pub Vec<HeadStats>);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user