From 27ee782aad3945084938b305f870490bddcbec2b Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Sun, 10 Jan 2021 17:50:08 +0100 Subject: [PATCH] Add logic for weapon firing/reloading --- src/lib.rs | 1 + src/main.rs | 3 ++- src/weapon.rs | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/weapon.rs diff --git a/src/lib.rs b/src/lib.rs index 9527b01..96f9925 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ pub mod hud; pub mod player; +pub mod weapon; pub mod world; diff --git a/src/main.rs b/src/main.rs index 3130509..4ad56d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use bevy::{input::system::exit_on_esc_system, prelude::*}; use bevy_rapier3d::physics::RapierPhysicsPlugin; -use rake::{hud::HudPlugin, player::PlayerPlugin, world::WorldPlugin}; +use rake::{hud::HudPlugin, player::PlayerPlugin, weapon::WeaponPlugin, world::WorldPlugin}; fn main() { App::build() @@ -18,6 +18,7 @@ fn main() { .add_plugin(PlayerPlugin) .add_plugin(HudPlugin) .add_plugin(WorldPlugin) + .add_plugin(WeaponPlugin) .add_system(exit_on_esc_system.system()) .run(); } diff --git a/src/weapon.rs b/src/weapon.rs new file mode 100644 index 0000000..c6820ef --- /dev/null +++ b/src/weapon.rs @@ -0,0 +1,56 @@ +use bevy::{ + input::{mouse::MouseButtonInput, ElementState}, + prelude::*, +}; +use std::time::Duration; + +pub struct WeaponPlugin; + +impl Plugin for WeaponPlugin { + fn build(&self, app: &mut AppBuilder) { + app + .add_resource(WeaponData::default()) + .add_system(shoot_system.system()); + } +} + +pub struct WeaponData { + pub reload_timer: Timer, + pub reloading: bool, +} + +impl Default for WeaponData { + fn default() -> Self { + WeaponData { + reload_timer: Timer::new(Duration::from_secs(1), false), + reloading: false, + } + } +} + +fn shoot_system( + mut mouse_event_reader: Local>, + mouse_button_events: Res>, + time: Res