lebron asset loading
This commit is contained in:
46
src/asset_loading/mod.rs
Normal file
46
src/asset_loading/mod.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::GameState;
|
||||
use bevy_asset_loader::prelude::*;
|
||||
// use bevy_egui::{EguiContexts, egui, egui::ProgressBar};
|
||||
// use bevy_kira_audio::AudioSource;
|
||||
// use iyes_progress::{ProgressCounter, ProgressPlugin};
|
||||
|
||||
/// Loads resources and assets for the game.
|
||||
/// See assets/main.assets.ron for the actual paths used.
|
||||
pub(super) fn plugin(app: &mut App) {
|
||||
app.add_loading_state(
|
||||
LoadingState::new(GameState::Loading)
|
||||
.continue_to_state(GameState::Menu)
|
||||
.with_dynamic_assets_file::<StandardDynamicAssetCollection>("main.assets.ron")
|
||||
.load_collection::<ImageAssets>(), // .load_collection::<AudioAssets>()
|
||||
// .load_collection::<GltfAssets>()
|
||||
// .load_collection::<TextureAssets>()
|
||||
// .load_collection::<GrassAssets>()
|
||||
// .load_collection::<ConfigAssets>(),
|
||||
);
|
||||
}
|
||||
|
||||
// the following asset collections will be loaded during the State `GameState::InitialLoading`
|
||||
// when done loading, they will be inserted as resources (see <https://github.com/NiklasEi/bevy_asset_loader>)
|
||||
|
||||
#[derive(AssetCollection, Resource, Clone)]
|
||||
pub(crate) struct AudioAssets {}
|
||||
|
||||
#[derive(AssetCollection, Resource, Clone)]
|
||||
pub(crate) struct GltfAssets {}
|
||||
|
||||
#[derive(AssetCollection, Resource, Clone)]
|
||||
pub(crate) struct TextureAssets {}
|
||||
|
||||
#[derive(AssetCollection, Resource, Clone)]
|
||||
pub(crate) struct GrassAssets {}
|
||||
|
||||
#[derive(AssetCollection, Resource, Clone)]
|
||||
pub(crate) struct ConfigAssets {}
|
||||
|
||||
#[derive(AssetCollection, Resource, Clone)]
|
||||
pub(crate) struct ImageAssets {
|
||||
#[asset(key = "lebron")]
|
||||
pub(crate) king: Handle<Image>,
|
||||
}
|
||||
29
src/main.rs
29
src/main.rs
@@ -1,14 +1,29 @@
|
||||
use bevy::prelude::*;
|
||||
use asset_loading::ImageAssets;
|
||||
use bevy::{prelude::*, state::app::StatesPlugin};
|
||||
|
||||
mod asset_loading;
|
||||
|
||||
fn main() -> AppExit {
|
||||
App::new()
|
||||
.add_plugins((DefaultPlugins))
|
||||
.add_plugins((DefaultPlugins, asset_loading::plugin))
|
||||
.init_state::<GameState>()
|
||||
// We need to register components to make them visible to Blenvy
|
||||
.register_type::<Player>()
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(OnExit(GameState::Loading), debug_our_king)
|
||||
.run()
|
||||
}
|
||||
|
||||
#[derive(States, Default, Clone, Eq, PartialEq, Debug, Hash)]
|
||||
enum GameState {
|
||||
/// During the loading State the loading_plugin will load our assets
|
||||
#[default]
|
||||
Loading,
|
||||
/// During this State the actual game logic is executed
|
||||
Playing,
|
||||
/// Here the menu is drawn and waiting for player interaction
|
||||
Menu,
|
||||
}
|
||||
|
||||
#[derive(Component, Reflect)]
|
||||
struct Player {
|
||||
strength: f32,
|
||||
@@ -20,4 +35,10 @@ struct Player {
|
||||
luck: f32,
|
||||
}
|
||||
|
||||
fn setup(mut commands: Commands) {}
|
||||
fn setup(mut commands: Commands) {
|
||||
commands.spawn(Camera2d);
|
||||
}
|
||||
|
||||
fn debug_our_king(mut commands: Commands, images: Res<ImageAssets>) {
|
||||
commands.spawn(Sprite::from_image(images.king.clone()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user