Added ship model
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,7 @@
|
||||
use bevy::prelude::*;
|
||||
#[cfg(feature = "dev")]
|
||||
use bevy::window::PrimaryWindow;
|
||||
use bevy_rapier3d::plugin::PhysicsSet;
|
||||
|
||||
use crate::{components::camera::*, states::play::PlaySystems};
|
||||
|
||||
@@ -9,7 +10,11 @@ pub struct CameraPlugin;
|
||||
impl Plugin for CameraPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Update, camera_pitch.in_set(PlaySystems));
|
||||
app.add_systems(Update, camera_attachment.in_set(PlaySystems));
|
||||
app.add_systems(
|
||||
PostUpdate,
|
||||
//Update after physics moves entities
|
||||
camera_attachment.in_set(PlaySystems).after(PhysicsSet::Writeback),
|
||||
);
|
||||
#[cfg(feature = "dev")]
|
||||
app.add_systems(Update, camera_toggle.in_set(PlaySystems));
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ impl Plugin for GamePlugin {
|
||||
CameraPlugin,
|
||||
StateManagementPlugin,
|
||||
MainMenuPlugin,
|
||||
// ShipPlugin,
|
||||
ShipPlugin,
|
||||
TypesPlugin,
|
||||
PlayerPlugin,
|
||||
));
|
||||
@@ -32,7 +32,7 @@ impl Plugin for GamePlugin {
|
||||
#[cfg(feature = "dev-phys")]
|
||||
RapierDebugRenderPlugin::default(),
|
||||
));
|
||||
app.add_systems(Update, (setup_scene, spawn_ship).chain().in_set(PlayStartupSystems));
|
||||
app.add_systems(Update, (setup_scene).chain().in_set(PlayStartupSystems));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,14 @@ fn setup_scene(
|
||||
PlayerDrag(0.5),
|
||||
Collider::capsule_y(0.5, 0.5),
|
||||
RigidBody::KinematicPositionBased,
|
||||
KinematicCharacterController::default(),
|
||||
KinematicCharacterController {
|
||||
autostep: Some(CharacterAutostep {
|
||||
include_dynamic_bodies: true,
|
||||
max_height: CharacterLength::Absolute(0.25),
|
||||
..default()
|
||||
}),
|
||||
..default()
|
||||
},
|
||||
Mesh3d(meshes.add(Capsule3d::new(0.5, 1.0))),
|
||||
MeshMaterial3d(materials.add(Color::linear_rgb(1.0, 0.0, 0.2))),
|
||||
Transform::from_translation(Vec3::new(0.0, 10.0, 10.0)),
|
||||
@@ -110,7 +117,7 @@ fn spawn_ship(
|
||||
Mesh3d(meshes.add(Cuboid::new(3.0, 0.1, 6.0))),
|
||||
MeshMaterial3d(material.clone()),
|
||||
Name::new("Ship"),
|
||||
Ship,
|
||||
// Ship,
|
||||
Velocity::zero(),
|
||||
Damping::default(),
|
||||
Transform::from_xyz(0.0, 1.0, 0.0),
|
||||
|
||||
@@ -1,18 +1,50 @@
|
||||
use bevy::{input::mouse::MouseMotion, prelude::*};
|
||||
use bevy_rapier3d::prelude::*;
|
||||
|
||||
use crate::{components::tags::Ship, states::play::PlaySystems, utils::input::get_mouse_delta};
|
||||
use crate::{
|
||||
components::tags::Ship,
|
||||
states::play::{PlayStartupSystems, PlaySystems},
|
||||
utils::input::get_mouse_delta,
|
||||
};
|
||||
|
||||
pub struct ShipPlugin;
|
||||
|
||||
impl Plugin for ShipPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Update, spawn_ship.in_set(PlayStartupSystems));
|
||||
|
||||
app.add_systems(Update, ship_controls.in_set(PlaySystems));
|
||||
#[cfg(feature = "dev-viz")]
|
||||
app.add_systems(Update, ship_debug.in_set(PlaySystems));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource, Debug, Reflect)]
|
||||
struct ShipMesh(Handle<Scene>);
|
||||
|
||||
fn spawn_ship(mut commads: Commands, assets: Res<AssetServer>) {
|
||||
let scene = assets.load(GltfAssetLabel::Scene(0).from_asset("models/Ship.glb"));
|
||||
|
||||
commads.insert_resource(ShipMesh(scene.clone()));
|
||||
|
||||
commads.spawn((
|
||||
SceneRoot(scene),
|
||||
Transform::from_xyz(0.0, 3.0, 0.0),
|
||||
RigidBody::KinematicVelocityBased,
|
||||
GravityScale(0.0),
|
||||
children![
|
||||
(
|
||||
Transform::from_xyz(-2.0, -2.7, 0.0),
|
||||
Collider::round_cuboid(6.0, 0.1, 3.0, 0.05)
|
||||
),
|
||||
(
|
||||
Transform::from_xyz(-2.0, 2.8, 0.0),
|
||||
Collider::round_cuboid(6.0, 0.1, 3.0, 0.05)
|
||||
)
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
fn ship_controls(
|
||||
ship_query: Single<(&Transform, &mut Velocity, &mut Damping), With<Ship>>,
|
||||
key: Res<ButtonInput<KeyCode>>,
|
||||
|
||||
@@ -12,7 +12,9 @@ use crate::{
|
||||
menu::{
|
||||
MainMenuSystems, MenuCleanupSystems, MenuStartupSystems, MenuState, OptionsMenuSystems, SavesMenuSystems,
|
||||
},
|
||||
play::{PausedSystems, PlayCleanupSystems, PlayStartupSystems, PlayState, PlaySystems},
|
||||
play::{
|
||||
PausedSystems, PlayAssetFinalizeSystems, PlayCleanupSystems, PlayStartupSystems, PlayState, PlaySystems,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -28,7 +30,7 @@ impl Plugin for StateManagementPlugin {
|
||||
|
||||
//Loading
|
||||
app.add_loading_state(LoadingState::new(MenuState::Loading).continue_to_state(MenuState::Startup))
|
||||
.add_loading_state(LoadingState::new(PlayState::Loading).continue_to_state(PlayState::Startup));
|
||||
.add_loading_state(LoadingState::new(PlayState::Loading).continue_to_state(PlayState::AssetFinalize));
|
||||
|
||||
//Game
|
||||
configure_sets!(app, MenuSystems.run_if(in_state(GameState::MainMenu)));
|
||||
@@ -58,6 +60,12 @@ impl Plugin for StateManagementPlugin {
|
||||
configure_sets!(app, MenuCleanupSystems.run_if(in_state(MenuState::Cleanup)));
|
||||
|
||||
//Play
|
||||
configure_sets!(
|
||||
app,
|
||||
PlayAssetFinalizeSystems
|
||||
.run_if(in_state(PlayState::AssetFinalize))
|
||||
.in_set(InGameSystems)
|
||||
);
|
||||
configure_sets!(
|
||||
app,
|
||||
PlayStartupSystems
|
||||
@@ -113,15 +121,23 @@ impl Plugin for StateManagementPlugin {
|
||||
);
|
||||
|
||||
//State Transitions
|
||||
app.add_systems(Update, game_asset_finalize.in_set(PlayAssetFinalizeSystems));
|
||||
app.add_systems(Update, game_startup.in_set(PlayStartupSystems));
|
||||
app.add_systems(Update, game_cleanup.in_set(PlayCleanupSystems));
|
||||
}
|
||||
}
|
||||
|
||||
fn game_asset_finalize(mut next: ResMut<NextState<PlayState>>) {
|
||||
next.set(PlayState::Startup);
|
||||
info_once!("Moving to PlayState:{:?}", PlayState::Startup);
|
||||
}
|
||||
|
||||
fn game_startup(mut next: ResMut<NextState<PlayState>>) {
|
||||
next.set(PlayState::Playing);
|
||||
info_once!("Moving to PlayState:{:?}", PlayState::Playing);
|
||||
}
|
||||
|
||||
fn game_cleanup(mut next: ResMut<NextState<PlayState>>) {
|
||||
next.set(PlayState::Idle);
|
||||
info_once!("Moving to PlayState:{:?}", PlayState::Idle);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ use bevy::prelude::*;
|
||||
|
||||
#[derive(States, Debug, Reflect, Default, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum MenuState {
|
||||
#[default]
|
||||
Idle,
|
||||
#[default]
|
||||
Loading,
|
||||
AssetFinalize,
|
||||
Startup,
|
||||
|
||||
@@ -12,6 +12,9 @@ pub enum PlayState {
|
||||
Cleanup,
|
||||
}
|
||||
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct PlayAssetFinalizeSystems;
|
||||
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct PlayStartupSystems;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user