diff --git a/Design.md b/Design.md new file mode 100644 index 0000000..622fb16 --- /dev/null +++ b/Design.md @@ -0,0 +1,16 @@ +## Game design + +4-6 guns, with 1 magazine per gun. +Optics can be left out +Can only be found in the world +Always have a starting pistol available +Inventory system + Looting system +Boxes all around the map with guns, equipment, ammo. + +A mix between a battle royale and an extraction looter shooter: +All players spawn like an extraction looter shooter, to get out they have to extract, +but the map contains loot like a battle royale. + +Make sure guns are usable with iron sights. + +Multiplayer \ No newline at end of file diff --git a/assets/weapons/Glock17.glb b/assets/weapons/Glock17.glb new file mode 100644 index 0000000..9a0dcf2 Binary files /dev/null and b/assets/weapons/Glock17.glb differ diff --git a/src/comps/core/markers/firearm.rs b/src/comps/core/markers/firearm.rs index 2faf874..f0b2496 100644 --- a/src/comps/core/markers/firearm.rs +++ b/src/comps/core/markers/firearm.rs @@ -16,6 +16,8 @@ pub struct FirearmData<'a> { pub rebound_time_seconds: f32, pub asset_path: &'a str, + pub identifier: String, + pub vertical_recoil_modifier: f32, pub horizontal_recoil_modifier: f32, pub recoil_pattern: FirearmSprayPattern, diff --git a/src/constants/player_values.rs b/src/constants/player_values.rs index 804e81a..3b92179 100644 --- a/src/constants/player_values.rs +++ b/src/constants/player_values.rs @@ -27,10 +27,3 @@ pub const PLAYER_LATERAL_ACCELERATION_MULTIPLIER: f32 = 1.0; pub const PLAYER_LINEAR_DAMPING_TIME_OFFSET_AFTER_JUMP_IN_MS: u128 = 20; pub const DEFAULT_PLAYER_FIREARM: Firearm = Firearm::M4A1; - -/* -pub const PLAYER_CAMERA_HEADBOB_Y_POS: f32 = 0.2; -pub const PLAYER_CAMERA_HEADBOB_Y_NEG: f32 = -0.2; -pub const PLAYER_CAMERA_HEADBOB_X_POS: f32 = 0.2; -pub const PLAYER_CAMERA_HEADBOB_X_NEG: f32 = -0.2; -*/ diff --git a/src/logic/core/guns/equip_firearm.rs b/src/logic/core/guns/equip_firearm.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/logic/core/guns/firearm.rs b/src/logic/core/guns/firearm.rs index 7287551..0345498 100644 --- a/src/logic/core/guns/firearm.rs +++ b/src/logic/core/guns/firearm.rs @@ -42,6 +42,7 @@ impl Firearm { y: -0.45, z: -2.7, }, + identifier: String::from("m4a1_rifle"), } } diff --git a/src/logic/core/guns/mod.rs b/src/logic/core/guns/mod.rs index b370c15..e50150e 100644 --- a/src/logic/core/guns/mod.rs +++ b/src/logic/core/guns/mod.rs @@ -2,4 +2,5 @@ pub mod caliber; pub mod firearm; pub mod player_firing; pub mod spawn_firearm; -pub mod spray_pattern; \ No newline at end of file +pub mod spray_pattern; +pub mod equip_firearm; \ No newline at end of file diff --git a/src/logic/core/guns/spawn_firearm.rs b/src/logic/core/guns/spawn_firearm.rs index 1c7d684..b778f51 100644 --- a/src/logic/core/guns/spawn_firearm.rs +++ b/src/logic/core/guns/spawn_firearm.rs @@ -1,50 +1,61 @@ use std::time::Duration; -use bevy::prelude::*; +use bevy::{prelude::*, gltf::Gltf}; use crate::{ - comps::core::markers::{holdable::InPlayerHands, player::PlayerHand, firearm::MagazineData}, + comps::core::markers::{holdable::InPlayerHands, player::PlayerHand, firearm::{MagazineData, FirearmData}}, constants::player_values::DEFAULT_PLAYER_FIREARM, - utils, setup::animations::FirearmAnimations, + utils, setup::{animations::FirearmAnimations, gltf_assets::GltfAssets}, }; -use super::player_firing::PlayerFiringInfo; +use super::{player_firing::PlayerFiringInfo, firearm::Firearm}; pub fn spawn_firearm_on_player_hands( mut commands: Commands, query: Query>, asset_server: Res, mut player_firing_info: ResMut, + assets_gltf: Res, + loaded_gltf_assets: Res>, ) { - for entity in query.iter() { - let mut firearm_transform = Transform::from_xyz(0.0, 0.0, 0.0); - firearm_transform.rotate_y(utils::rad_deg::radians_from_degrees( - DEFAULT_PLAYER_FIREARM.holdable_object_data().y_rot, - )); + if let Some(asset_handle) = assets_gltf.assets.iter().find(|asset| asset.id == Firearm::M4A1.firearm_data().identifier) { + if let Some(gltf) = loaded_gltf_assets.get(&asset_handle.asset) { + println!("C"); + for entity in query.iter() { + let mut firearm_transform = Transform::from_xyz(0.0, 0.0, 0.0); + firearm_transform.rotate_y(utils::rad_deg::radians_from_degrees( + DEFAULT_PLAYER_FIREARM.holdable_object_data().y_rot, + )); + + let scene = gltf.scenes[0].clone(); - let firearm = commands - .spawn(( - SceneBundle { - scene: asset_server.load(format!("{}#Scene0", DEFAULT_PLAYER_FIREARM.firearm_data().asset_path)), - visibility: Visibility::Inherited, - transform: firearm_transform, - ..default() - }, - 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(); + let firearm = commands + .spawn(( + SceneBundle { + scene, + visibility: Visibility::Inherited, + transform: firearm_transform, + ..default() + }, + DEFAULT_PLAYER_FIREARM.firearm_data(), + FirearmAnimations { reload_magazine: todo!() }, + DEFAULT_PLAYER_FIREARM.holdable_object_data(), + MagazineData { rounds_shot: 0, max_capacity: DEFAULT_PLAYER_FIREARM.firearm_data().max_capacity }, + InPlayerHands, - commands.entity(entity).push_children(&[firearm]); - let time_in_secs_between_each_round = - 1.0 / DEFAULT_PLAYER_FIREARM.firearm_data().fire_rate * 60.0; - player_firing_info.full_auto_timer = Timer::new( - Duration::from_secs_f32(time_in_secs_between_each_round), - TimerMode::Once, - ); - // Load animations - commands.insert_resource(FirearmAnimations { reload_magazine: asset_server.load(format!("{}#Animation0", DEFAULT_PLAYER_FIREARM.firearm_data().asset_path))}) + )) + .id(); + + commands.entity(entity).push_children(&[firearm]); + let time_in_secs_between_each_round = + 1.0 / DEFAULT_PLAYER_FIREARM.firearm_data().fire_rate * 60.0; + player_firing_info.full_auto_timer = Timer::new( + Duration::from_secs_f32(time_in_secs_between_each_round), + TimerMode::Once, + ); + // Load animations + commands.insert_resource(FirearmAnimations { reload_magazine: asset_server.load(format!("{}#Animation0", DEFAULT_PLAYER_FIREARM.firearm_data().asset_path))}) + } + } } } diff --git a/src/logic/core/player/camera_effects.rs b/src/logic/core/player/camera_effects.rs index e69de29..3220062 100644 --- a/src/logic/core/player/camera_effects.rs +++ b/src/logic/core/player/camera_effects.rs @@ -0,0 +1,11 @@ +use bevy::{prelude::*, gltf::Gltf}; + +// Once the scene is loaded, start the animation +pub fn setup_scene_once_loaded( + gltf_assets: Res>, + asset_server: Res, +) { + for asset in gltf_assets.iter() { + + } +} \ No newline at end of file diff --git a/src/scenes/scene1/init.rs b/src/scenes/scene1/init.rs index ac251a5..dea9032 100644 --- a/src/scenes/scene1/init.rs +++ b/src/scenes/scene1/init.rs @@ -12,7 +12,7 @@ use crate::{ player_vertical_sync::sync_player_y_state, spawn_player::spawn_player, }, - }, + }, setup::{gltf_assets::load_all_assets, load_state::GameLoadState}, }; use super::{ @@ -21,17 +21,20 @@ use super::{ }; pub fn load_scene(application: &mut App) { + application.insert_resource(GameLoadState::default()); application.insert_resource(MouseMovementSettings::default()); application.insert_resource(PlayerFiringInfo::default()); // Startup + application.add_systems(PreStartup, load_all_assets); application.add_systems(Startup, spawn_ground); application.add_systems(Startup, spawn_obstacles); - application.add_systems(Startup, spawn_player); + application.add_systems(Startup, spawn_player.after(load_all_assets)); + application.add_systems(Startup, setup_lighting); + application.add_systems( PostStartup, - spawn_firearm_on_player_hands.after(spawn_player), + spawn_firearm_on_player_hands, ); - // Update application.add_systems(Update, capture_input); @@ -41,6 +44,4 @@ pub fn load_scene(application: &mut App) { application.add_systems(Update, asset_loaded); application.add_systems(Update, update_camera_vertical_position); application.add_systems(Update, capture_hand_usage); - - application.add_systems(Startup, setup_lighting); } diff --git a/src/setup/gltf_assets.rs b/src/setup/gltf_assets.rs index b95730c..2a84e3a 100644 --- a/src/setup/gltf_assets.rs +++ b/src/setup/gltf_assets.rs @@ -1,12 +1,30 @@ -// use bevy::prelude::*; +use bevy::{prelude::*, gltf::Gltf}; -// use bevy::gltf::Gltf; +use crate::logic::core::guns::firearm::Firearm; -// #[derive(Resource)] -// pub struct LoadedAssetMap(Handle); +use super::load_state::GameLoadState; -// /// Loads gltf asset into AssetServer. Inserts Resource as a LoadedAsset -// pub fn load_gltf(mut commands: Commands, ass: Res) { -// let gltf = ass.load("my_asset_pack.glb"); -// commands.insert_resource(LoadedAsset(gltf)); -// } +#[derive(Resource)] +pub struct GltfAssets { + pub assets: Vec +} +pub struct GltfAsset { + pub id: String, + pub asset: Handle +} + + +pub fn load_all_assets( + mut commands: Commands, + asset_server: Res, + mut game_load_state: ResMut, +) { + let m4a1_gltf_asset = GltfAsset { id: Firearm::M4A1.firearm_data().identifier, asset: asset_server.load(Firearm::M4A1.firearm_data().asset_path) } ; + + commands.insert_resource(GltfAssets { + assets: Vec::from([ + m4a1_gltf_asset + ]) + }); + game_load_state.assets_loaded = true; +} \ No newline at end of file diff --git a/src/setup/load_state.rs b/src/setup/load_state.rs new file mode 100644 index 0000000..9bec042 --- /dev/null +++ b/src/setup/load_state.rs @@ -0,0 +1,7 @@ +use bevy::prelude::*; + +#[derive(Resource, Default)] +pub struct GameLoadState { + pub assets_loaded: bool, + pub animations_loaded: bool, +} \ No newline at end of file diff --git a/src/setup/mod.rs b/src/setup/mod.rs index 69d15d7..29b64f0 100644 --- a/src/setup/mod.rs +++ b/src/setup/mod.rs @@ -1,2 +1,3 @@ pub mod gltf_assets; -pub mod animations; \ No newline at end of file +pub mod animations; +pub mod load_state; \ No newline at end of file