ability per second db value and hold-down trigger
This commit is contained in:
@@ -161,9 +161,13 @@ fn shot_collision(
|
||||
|
||||
let shot_entity = if query_shot.contains(*e1) { *e1 } else { *e2 };
|
||||
|
||||
let shot_pos = query_shot.get(shot_entity).unwrap().1.translation;
|
||||
if let Ok(mut entity) = commands.get_entity(shot_entity) {
|
||||
entity.despawn();
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
commands.entity(shot_entity).despawn();
|
||||
let shot_pos = query_shot.get(shot_entity).unwrap().1.translation;
|
||||
|
||||
let texture_atlas = TextureAtlas {
|
||||
layout: assets.layout.clone(),
|
||||
|
||||
@@ -4,6 +4,7 @@ mod missile;
|
||||
mod thrown;
|
||||
|
||||
use crate::{
|
||||
GameState,
|
||||
aim::AimTarget,
|
||||
character::CharacterHierarchy,
|
||||
global_observer,
|
||||
@@ -74,17 +75,34 @@ pub struct TriggerThrow(pub TriggerData);
|
||||
#[derive(Event, Reflect)]
|
||||
pub struct TriggerMissile(pub TriggerData);
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
struct TriggerStateRes {
|
||||
cooldown: f32,
|
||||
active: bool,
|
||||
}
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
app.init_resource::<TriggerStateRes>();
|
||||
|
||||
app.add_plugins(gun::plugin);
|
||||
app.add_plugins(thrown::plugin);
|
||||
app.add_plugins(arrow::plugin);
|
||||
app.add_plugins(missile::plugin);
|
||||
|
||||
app.add_systems(Update, update.run_if(in_state(GameState::Playing)));
|
||||
|
||||
global_observer!(app, on_trigger_state);
|
||||
}
|
||||
|
||||
fn on_trigger_state(
|
||||
trigger: Trigger<TriggerState>,
|
||||
fn on_trigger_state(trigger: Trigger<TriggerState>, mut res: ResMut<TriggerStateRes>) {
|
||||
res.active = matches!(trigger.event(), TriggerState::Active);
|
||||
if !res.active {
|
||||
res.cooldown = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
fn update(
|
||||
mut res: ResMut<TriggerStateRes>,
|
||||
mut commands: Commands,
|
||||
player_rot: Query<&Transform, With<PlayerBodyMesh>>,
|
||||
player_query: Query<(Entity, &AimTarget), With<Player>>,
|
||||
@@ -93,7 +111,7 @@ fn on_trigger_state(
|
||||
time: Res<Time>,
|
||||
character: CharacterHierarchy,
|
||||
) {
|
||||
if matches!(trigger.event(), TriggerState::Active) {
|
||||
if res.active && res.cooldown < time.elapsed_secs() {
|
||||
let Some(state) = active_heads.current() else {
|
||||
return;
|
||||
};
|
||||
@@ -129,8 +147,11 @@ fn on_trigger_state(
|
||||
|
||||
active_heads.use_ammo(time.elapsed_secs());
|
||||
|
||||
let ability = heads_db.head_stats(state.head).ability;
|
||||
match ability {
|
||||
let head = heads_db.head_stats(state.head);
|
||||
|
||||
res.cooldown = time.elapsed_secs() + (1. / head.aps);
|
||||
|
||||
match head.ability {
|
||||
HeadAbility::Thrown => commands.trigger(TriggerThrow(trigger_state)),
|
||||
HeadAbility::Gun => commands.trigger(TriggerGun(trigger_state)),
|
||||
HeadAbility::Missile => commands.trigger(TriggerMissile(trigger_state)),
|
||||
|
||||
Reference in New Issue
Block a user