Moving pcs

This commit is contained in:
Franklin Blanco 2023-09-18 09:44:51 -07:00
parent d1a1589bf6
commit 785bd89b6b
13 changed files with 118 additions and 56 deletions

16
Design.md Normal file
View File

@ -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

BIN
assets/weapons/Glock17.glb Normal file

Binary file not shown.

View File

@ -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,

View File

@ -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;
*/

View File

View File

@ -42,6 +42,7 @@ impl Firearm {
y: -0.45,
z: -2.7,
},
identifier: String::from("m4a1_rifle"),
}
}

View File

@ -3,3 +3,4 @@ pub mod firearm;
pub mod player_firing;
pub mod spawn_firearm;
pub mod spray_pattern;
pub mod equip_firearm;

View File

@ -1,39 +1,48 @@
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<Entity, With<PlayerHand>>,
asset_server: Res<AssetServer>,
mut player_firing_info: ResMut<PlayerFiringInfo>,
assets_gltf: Res<GltfAssets>,
loaded_gltf_assets: Res<Assets<Gltf>>,
) {
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)),
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,
))
.id();
@ -48,3 +57,5 @@ pub fn spawn_firearm_on_player_hands(
commands.insert_resource(FirearmAnimations { reload_magazine: asset_server.load(format!("{}#Animation0", DEFAULT_PLAYER_FIREARM.firearm_data().asset_path))})
}
}
}
}

View File

@ -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<Assets<Gltf>>,
asset_server: Res<AssetServer>,
) {
for asset in gltf_assets.iter() {
}
}

View File

@ -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);
}

View File

@ -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<Gltf>);
use super::load_state::GameLoadState;
// /// Loads gltf asset into AssetServer. Inserts Resource as a LoadedAsset
// pub fn load_gltf(mut commands: Commands, ass: Res<AssetServer>) {
// let gltf = ass.load("my_asset_pack.glb");
// commands.insert_resource(LoadedAsset(gltf));
// }
#[derive(Resource)]
pub struct GltfAssets {
pub assets: Vec<GltfAsset>
}
pub struct GltfAsset {
pub id: String,
pub asset: Handle<Gltf>
}
pub fn load_all_assets(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut game_load_state: ResMut<GameLoadState>,
) {
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;
}

7
src/setup/load_state.rs Normal file
View File

@ -0,0 +1,7 @@
use bevy::prelude::*;
#[derive(Resource, Default)]
pub struct GameLoadState {
pub assets_loaded: bool,
pub animations_loaded: bool,
}

View File

@ -1,2 +1,3 @@
pub mod gltf_assets;
pub mod animations;
pub mod load_state;