Added muzzle flash light
This commit is contained in:
parent
373f18cef2
commit
22a8c91c5e
|
@ -2,3 +2,4 @@ pub mod camera;
|
|||
pub mod firearm;
|
||||
pub mod holdable;
|
||||
pub mod player;
|
||||
pub mod muzzle_flash;
|
|
@ -0,0 +1,4 @@
|
|||
use bevy::{prelude::Component, time::Timer};
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct MuzzleFlashMarker(pub Timer);
|
|
@ -1 +0,0 @@
|
|||
|
|
@ -1 +0,0 @@
|
|||
pub mod m4a1;
|
|
@ -0,0 +1,12 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::comps::core::markers::muzzle_flash::MuzzleFlashMarker;
|
||||
|
||||
pub fn despawn_muzzle_flashes(mut commands: Commands, mut query: Query<(&mut MuzzleFlashMarker, Entity)>, time: Res<Time>) {
|
||||
for (mut muzzle_flash, entity) in query.iter_mut() {
|
||||
muzzle_flash.0.tick(time.delta());
|
||||
if muzzle_flash.0.finished() {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,4 +2,6 @@ pub mod caliber;
|
|||
pub mod firearm;
|
||||
pub mod player_firing;
|
||||
pub mod spray_pattern;
|
||||
pub mod equip_firearm;
|
||||
pub mod equip_firearm;
|
||||
pub mod shoot;
|
||||
pub mod despawn_shots;
|
|
@ -0,0 +1,30 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::comps::core::markers::muzzle_flash::MuzzleFlashMarker;
|
||||
|
||||
use super::caliber::Caliber;
|
||||
|
||||
pub fn shoot_bullet(
|
||||
mut commands: &mut Commands,
|
||||
firing_point: Transform,
|
||||
towards: Vec3,
|
||||
caliber: Caliber
|
||||
) {
|
||||
commands.spawn(
|
||||
(PointLightBundle {
|
||||
point_light: PointLight {
|
||||
//252, 238, 128
|
||||
color: Color::Rgba { red: 252., green: 238., blue: 128., alpha: 0.5 },
|
||||
intensity: 0.001,
|
||||
range: 30.0,
|
||||
shadows_enabled: true,
|
||||
..Default::default()
|
||||
},
|
||||
transform: firing_point,
|
||||
visibility: Visibility::Visible,
|
||||
..Default::default()
|
||||
}, MuzzleFlashMarker(Timer::new(Duration::from_millis(10), TimerMode::Once)))
|
||||
);
|
||||
}
|
|
@ -2,17 +2,18 @@ use bevy::prelude::*;
|
|||
|
||||
use crate::{
|
||||
comps::core::markers::{firearm::{FirearmData, MagazineData}, holdable::InPlayerHands, player::{PlayerHand, Player}},
|
||||
logic::core::guns::{player_firing::PlayerFiringInfo, firearm::Firearm}, utils::rad_deg::radians_from_degrees, setup::{animations::AllFirearmAnimations, load_state::GameLoadState, equipment::{EquipmentChangeEvent, Equipment}}, ui::game::settings::SettingsScreenUIConfiguration,
|
||||
logic::core::guns::{player_firing::PlayerFiringInfo, firearm::Firearm, shoot::shoot_bullet}, utils::rad_deg::radians_from_degrees, setup::{animations::AllFirearmAnimations, load_state::GameLoadState, equipment::{EquipmentChangeEvent, Equipment}}, ui::game::settings::SettingsScreenUIConfiguration,
|
||||
};
|
||||
|
||||
pub fn capture_hand_usage(
|
||||
mut commands: Commands,
|
||||
mouse_buttons: Res<Input<MouseButton>>,
|
||||
keyboard_input: Res<Input<KeyCode>>,
|
||||
mut hand_query: Query<&mut Transform, With<PlayerHand>>,
|
||||
time: Res<Time>,
|
||||
|
||||
mut firearm_query: Query<
|
||||
(&mut Transform, &'static FirearmData, &mut MagazineData),
|
||||
(&GlobalTransform, &'static FirearmData, &mut MagazineData),
|
||||
(With<InPlayerHands>, Without<PlayerHand>),
|
||||
>,
|
||||
player_query: Query<&Player>,
|
||||
|
@ -36,7 +37,7 @@ pub fn capture_hand_usage(
|
|||
for mut player_firing_info in player_firing_info_query.iter_mut() {
|
||||
player_firing_info.full_auto_timer.tick(time.delta());
|
||||
|
||||
for (mut _firearm_transform, firearm_data, mut magazine_data) in firearm_query.iter_mut() {
|
||||
for (firearm_transform, firearm_data, mut magazine_data) in firearm_query.iter_mut() {
|
||||
for mut hand_transform in hand_query.iter_mut() {
|
||||
|
||||
if player_firing_info.is_reloading {
|
||||
|
@ -91,7 +92,6 @@ pub fn capture_hand_usage(
|
|||
}
|
||||
// SHOOTING & RECOIL
|
||||
if mouse_buttons.pressed(MouseButton::Left) && !settings_screen_config.settings_menu_shown {
|
||||
//TODO: make click input not shoot when just clicked after a menu
|
||||
if player_firing_info.full_auto_timer.finished() {
|
||||
if magazine_data.rounds_shot < magazine_data.max_capacity {
|
||||
// Get recoil numbers from patterns
|
||||
|
@ -107,6 +107,9 @@ pub fn capture_hand_usage(
|
|||
*firearm_data.recoil_pattern.horizontal.last().expect("FOUND A FIREARM_DATA WITHOUT ANY FIREARM_RECOIL_PATTERN.")
|
||||
},
|
||||
};
|
||||
// TODO: Spawn Bullet & Muzzle flash
|
||||
let firing_point_global = firearm_transform.translation().clone();
|
||||
shoot_bullet(&mut commands, Transform::from_translation(firing_point_global + (firearm_transform.forward() * 1.5) + (firearm_transform.up() / 2.5)), firearm_data.firing_point, firearm_data.caliber.clone());
|
||||
// Increment indexes and timers
|
||||
player_firing_info.current_round_index += 1;
|
||||
player_firing_info.last_shot_timestamp = time.elapsed_seconds();
|
||||
|
|
|
@ -2,13 +2,13 @@ use bevy::prelude::*;
|
|||
|
||||
use crate::{
|
||||
comps::core::controller::capture_input,
|
||||
logic::core::player::{
|
||||
logic::core::{player::{
|
||||
camera_player_sync::{
|
||||
follow_cursor_with_camera, update_camera_vertical_position, MouseMovementSettings,
|
||||
},
|
||||
hands::capture_hand_usage,
|
||||
player_vertical_sync::sync_player_y_state, player_values_state::PlayerValuesState,
|
||||
}, setup::{assets::load_all_assets, load_state::GameLoadState, spawn::add_all_spawners, animations::{load_animations, AllFirearmAnimations}, equipment::{EquipmentChangeEvent, change_equipment}},
|
||||
}, guns::despawn_shots::despawn_muzzle_flashes}, setup::{assets::load_all_assets, load_state::GameLoadState, spawn::add_all_spawners, animations::{load_animations, AllFirearmAnimations}, equipment::{EquipmentChangeEvent, change_equipment}},
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
@ -39,6 +39,7 @@ pub fn load_scene(application: &mut App) {
|
|||
application.add_systems(Update, capture_hand_usage);
|
||||
|
||||
application.add_systems(Update, change_equipment);
|
||||
application.add_systems(Update, despawn_muzzle_flashes);
|
||||
|
||||
application.add_event::<EquipmentChangeEvent>();
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ pub fn setup_fps_counter(mut commands: Commands, ) {
|
|||
style: Style {
|
||||
position_type: PositionType::Absolute,
|
||||
right: Val::Px(10.0),
|
||||
top: Val::Px(5.0),
|
||||
top: Val::Px(30.0),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
|
|
Loading…
Reference in New Issue