Added magazines
This commit is contained in:
parent
56fc163b5c
commit
b01c9aad39
@ -4,14 +4,15 @@ use crate::logic::core::guns::{caliber::Caliber, spray_pattern::FirearmSprayPatt
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct FirearmData<'a> {
|
||||
/// Where the bullets will come out of
|
||||
/// Where the bullets will come out of, and muzzle flash will be spawned out of.
|
||||
pub firing_point: Vec3,
|
||||
pub caliber: Caliber,
|
||||
/// Placeholder until mags get implemented
|
||||
pub max_capacity: u32,
|
||||
pub max_capacity: usize,
|
||||
/// Rounds per minute
|
||||
pub fire_rate: f32,
|
||||
/// Amount of seconds it takes for gun to come down from shooting
|
||||
/// Also is the time it takes for the gun to aim in or aim out.
|
||||
pub rebound_time_seconds: f32,
|
||||
pub asset_path: &'a str,
|
||||
|
||||
@ -28,3 +29,9 @@ pub struct FirearmData<'a> {
|
||||
/// Final position of hands when not aimed in
|
||||
pub final_position: Vec3,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct MagazineData {
|
||||
pub rounds_shot: usize,
|
||||
pub max_capacity: usize,
|
||||
}
|
@ -10,7 +10,7 @@ pub enum Firearm {
|
||||
impl Firearm {
|
||||
pub fn firearm_data(&self) -> FirearmData {
|
||||
FirearmData {
|
||||
firing_point: Vec3::ZERO,
|
||||
firing_point: Vec3 { x: -2.5, y: 0.0, z: 0.0 },
|
||||
caliber: Caliber::NATO556,
|
||||
max_capacity: 30,
|
||||
fire_rate: 800.0,
|
||||
@ -19,10 +19,10 @@ impl Firearm {
|
||||
horizontal_recoil_modifier: 0.5,
|
||||
recoil_pattern: FirearmSprayPattern {
|
||||
vertical: Vec::from([
|
||||
1.0, 1.2, 1.3, 1.6, 1.5, 1.7, 1.5, 1.5, 1.5, 2.0
|
||||
1.0, 1.2, 1.3, 1.6, 1.5, 1.7, 1.5, 1.5, 1.5, 2.0 // 10 for now
|
||||
]),
|
||||
horizontal: Vec::from([
|
||||
1.0, 1.2, 1.3, -1.6, 1.5, -1.7, -1.5, 1.5, -1.5, 2.0
|
||||
1.0, 1.2, 1.3, -1.6, 1.5, -1.7, -1.5, 1.5, -1.5, 2.0 // 10 for now
|
||||
]),
|
||||
},
|
||||
asset_path: "weapons/m4a1_rifle.glb#Scene0",
|
||||
|
@ -3,7 +3,7 @@ use std::time::Duration;
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{
|
||||
comps::core::markers::{holdable::InPlayerHands, player::PlayerHand},
|
||||
comps::core::markers::{holdable::InPlayerHands, player::PlayerHand, firearm::MagazineData},
|
||||
constants::player_values::DEFAULT_PLAYER_FIREARM,
|
||||
utils,
|
||||
};
|
||||
@ -31,6 +31,7 @@ pub fn spawn_firearm_on_player_hands(
|
||||
},
|
||||
DEFAULT_PLAYER_FIREARM.firearm_data(),
|
||||
DEFAULT_PLAYER_FIREARM.holdable_object_data(),
|
||||
MagazineData { rounds_shot: 0, max_capacity: DEFAULT_PLAYER_FIREARM.firearm_data().max_capacity },
|
||||
InPlayerHands,
|
||||
))
|
||||
.id();
|
||||
|
@ -1,7 +1,7 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{
|
||||
comps::core::markers::{firearm::FirearmData, holdable::InPlayerHands, player::PlayerHand},
|
||||
comps::core::markers::{firearm::{FirearmData, MagazineData}, holdable::InPlayerHands, player::PlayerHand},
|
||||
logic::core::guns::player_firing::PlayerFiringInfo, utils::rad_deg::radians_from_degrees,
|
||||
};
|
||||
|
||||
@ -12,22 +12,16 @@ pub fn capture_hand_usage(
|
||||
|
||||
mut player_firing_info: ResMut<PlayerFiringInfo>,
|
||||
mut firearm_query: Query<
|
||||
(&mut Transform, &'static FirearmData),
|
||||
(&mut Transform, &'static FirearmData, &mut MagazineData),
|
||||
(With<InPlayerHands>, Without<PlayerHand>),
|
||||
>,
|
||||
) {
|
||||
player_firing_info.full_auto_timer.tick(time.delta());
|
||||
|
||||
for (mut _firearm_transform, firearm_data) in firearm_query.iter_mut() {
|
||||
for (mut _firearm_transform, firearm_data, mut magazine_data) in firearm_query.iter_mut() {
|
||||
for mut hand_transform in hand_query.iter_mut() {
|
||||
// AIMING IN/OUT
|
||||
if mouse_buttons.pressed(MouseButton::Right) {
|
||||
|
||||
|
||||
//firearm_transform.rotation = firearm_transform.rotation.lerp(Quat::default(), (time.delta_seconds() / //firearm_data.rebound_time_seconds).clamp(0.0, 1.0));
|
||||
|
||||
|
||||
|
||||
let rotation_lerp_quat = hand_transform.rotation.lerp(
|
||||
firearm_data.final_aimed_rotation,
|
||||
(time.delta_seconds() / firearm_data.rebound_time_seconds).clamp(0.0, 1.0),
|
||||
@ -38,10 +32,6 @@ pub fn capture_hand_usage(
|
||||
);
|
||||
hand_transform.rotation = rotation_lerp_quat;
|
||||
hand_transform.translation = position_lerp_vec3;
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
hand_transform.rotation = hand_transform
|
||||
.rotation
|
||||
@ -50,16 +40,12 @@ pub fn capture_hand_usage(
|
||||
firearm_data.final_position,
|
||||
(time.delta_seconds() / 0.5).clamp(0.0, 1.0),
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Shooting & Recoil
|
||||
// SHOOTING & RECOIL
|
||||
if mouse_buttons.pressed(MouseButton::Left) {
|
||||
if player_firing_info.full_auto_timer.finished() {
|
||||
|
||||
if magazine_data.rounds_shot < magazine_data.max_capacity {
|
||||
// Get recoil numbers from patterns
|
||||
let vertical_recoil_number: f32 = match firearm_data.recoil_pattern.vertical.get(player_firing_info.current_round_index) {
|
||||
Some(vert_recoil_number) => *vert_recoil_number,
|
||||
None => {
|
||||
@ -72,17 +58,24 @@ pub fn capture_hand_usage(
|
||||
*firearm_data.recoil_pattern.horizontal.last().expect("FOUND A FIREARM_DATA WITHOUT ANY FIREARM_RECOIL_PATTERN.")
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Increment indexes and timers
|
||||
player_firing_info.current_round_index += 1;
|
||||
player_firing_info.last_shot_timestamp = time.elapsed_seconds();
|
||||
player_firing_info.full_auto_timer.reset();
|
||||
magazine_data.rounds_shot += 1;
|
||||
|
||||
|
||||
// Apply recoil
|
||||
hand_transform
|
||||
.rotate_x(radians_from_degrees(firearm_data.vertical_recoil_modifier * vertical_recoil_number));
|
||||
hand_transform.rotate_y(radians_from_degrees(firearm_data.horizontal_recoil_modifier * horizontal_recoil_number));
|
||||
} else {
|
||||
//TODO: play magazine empty sound
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
if player_firing_info.full_auto_timer.finished() {
|
||||
player_firing_info.current_round_index = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user