generated from 2ndbeam/bevy-template
feat: added clap for level parsing
- Camera sets up as a child of player entity
This commit is contained in:
parent
79fe190b6b
commit
3cddecf592
7 changed files with 156 additions and 13 deletions
|
|
@ -6,7 +6,7 @@ use bevy::{
|
|||
use bevy_rapier2d::prelude::*;
|
||||
|
||||
use crate::{
|
||||
player::Player,
|
||||
StartupArgs, player::Player
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
|
@ -86,7 +86,8 @@ pub fn lock_door(
|
|||
pub fn setup_world(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
startup_args: Res<StartupArgs>,
|
||||
) {
|
||||
let level_handle = asset_server.load("levels/level.toml");
|
||||
let level_handle = asset_server.load(startup_args.level.clone());
|
||||
commands.insert_resource(LevelAssetHandle(level_handle));
|
||||
}
|
||||
|
|
|
|||
12
src/lib.rs
12
src/lib.rs
|
|
@ -7,6 +7,7 @@ use bevy_rapier2d::{
|
|||
prelude::*,
|
||||
rapier::prelude::IntegrationParameters,
|
||||
};
|
||||
use clap::Parser;
|
||||
|
||||
pub mod input;
|
||||
pub mod inventory;
|
||||
|
|
@ -37,7 +38,15 @@ pub enum LoadingState {
|
|||
Ready,
|
||||
}
|
||||
|
||||
fn camera_bundle() -> impl Bundle {
|
||||
#[derive(Parser, Resource, Clone, PartialEq, Eq, Hash, Debug, Reflect, Default)]
|
||||
#[reflect(Resource, Clone, PartialEq, Hash, Debug, Default)]
|
||||
pub struct StartupArgs {
|
||||
#[arg(long, short, default_value = "levels/level.toml")]
|
||||
/// Level to load (relative to assets folder)
|
||||
level: String,
|
||||
}
|
||||
|
||||
pub fn camera_bundle() -> impl Bundle {
|
||||
(
|
||||
Camera2d,
|
||||
Camera {
|
||||
|
|
@ -67,7 +76,6 @@ pub const fn meters(value: f32) -> f32 {
|
|||
}
|
||||
|
||||
fn setup_global(mut commands: Commands) {
|
||||
commands.spawn(camera_bundle());
|
||||
commands.spawn(ui::UiRoot::new());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,12 +6,16 @@ use bevy::{
|
|||
},
|
||||
};
|
||||
|
||||
use expedition_demo::ExpeditionPlugin;
|
||||
use clap::Parser;
|
||||
use expedition_demo::{ExpeditionPlugin, StartupArgs};
|
||||
|
||||
fn main() {
|
||||
let startup_args = StartupArgs::parse();
|
||||
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
|
||||
.add_plugins(ExpeditionPlugin)
|
||||
.insert_resource(startup_args)
|
||||
.add_plugins(RemotePlugin::default())
|
||||
.add_plugins(RemoteHttpPlugin::default())
|
||||
.run();
|
||||
|
|
|
|||
|
|
@ -2,9 +2,7 @@ use bevy::prelude::*;
|
|||
use bevy_rapier2d::prelude::*;
|
||||
|
||||
use crate::{
|
||||
meters,
|
||||
input::InputAction as Action,
|
||||
inventory::Inventory,
|
||||
camera_bundle, input::InputAction as Action, inventory::Inventory, meters
|
||||
};
|
||||
|
||||
pub mod systems;
|
||||
|
|
@ -40,6 +38,7 @@ pub fn player_bundle(asset_server: &Res<AssetServer>, position: Vec2) -> impl Bu
|
|||
Inventory::new(UVec2::new(6, 2)),
|
||||
Inventory::new(UVec2::new(5, 3)),
|
||||
Inventory::new(UVec2::new(4, 4)),
|
||||
camera_bundle(),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue