This commit is contained in:
Back777space
2025-04-05 18:42:15 +02:00
12 changed files with 124 additions and 7 deletions

51
Cargo.lock generated
View File

@@ -123,6 +123,7 @@ name = "among-me"
version = "0.1.0"
dependencies = [
"bevy",
"bevy_asset_loader",
]
[[package]]
@@ -167,6 +168,12 @@ dependencies = [
"libc",
]
[[package]]
name = "anyhow"
version = "1.0.97"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f"
[[package]]
name = "approx"
version = "0.5.1"
@@ -421,6 +428,31 @@ dependencies = [
"web-sys",
]
[[package]]
name = "bevy_asset_loader"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d806c255faca43ace03fe99889dd322e295a55ed4dd478a5d8ea6efe523158fe"
dependencies = [
"anyhow",
"bevy",
"bevy_asset_loader_derive",
"bevy_common_assets",
"path-slash",
"serde",
]
[[package]]
name = "bevy_asset_loader_derive"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b758b06fa9ec729c925f1fc256b503ca438f1ea345636af362b5fae71f5d8868"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "bevy_asset_macros"
version = "0.15.3"
@@ -467,6 +499,19 @@ dependencies = [
"wgpu-types",
]
[[package]]
name = "bevy_common_assets"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3521990269672c442f2bf0fbed0fce9db719e3dd136dd4012a97809464a4389d"
dependencies = [
"anyhow",
"bevy",
"ron",
"serde",
"thiserror",
]
[[package]]
name = "bevy_core"
version = "0.15.3"
@@ -3122,6 +3167,12 @@ version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
[[package]]
name = "path-slash"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42"
[[package]]
name = "percent-encoding"
version = "2.3.1"

View File

@@ -5,3 +5,4 @@ edition = "2024"
[dependencies]
bevy = "0.15.3"
bevy_asset_loader = { version ="0.22.0", features = ["standard_dynamic_assets"] }

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 735 KiB

Binary file not shown.

Binary file not shown.

View File

@@ -1,5 +0,0 @@
(
assets:
[
]
)

3
assets/main.assets.ron Normal file
View File

@@ -0,0 +1,3 @@
({
"lebron": File (path: "images/KingLebron.png"),
})

Binary file not shown.

Binary file not shown.

46
src/asset_loading/mod.rs Normal file
View 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>,
}

View File

@@ -1,10 +1,16 @@
use bevy::prelude::*;
use asset_loading::ImageAssets;
use bevy::{prelude::*, state::app::StatesPlugin};
mod asset_loading;
pub mod player;
fn main() {
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
.add_systems(OnExit(GameState::Loading), debug_our_king)
.add_systems(Startup, (setup, player::init_player))
.add_systems(Update, player::move_camera)
.add_systems(FixedUpdate, player::advance_physics)
@@ -18,6 +24,21 @@ fn main() {
.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,
}
fn debug_our_king(mut commands: Commands, images: Res<ImageAssets>) {
commands.spawn(Sprite::from_image(images.king.clone()));
}
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,