Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // example of using bevy games engine with hot reloadable
- // $ cargo init
- // $ cargo add bevy
- //
- // Cargo.toml
- // [package]
- // name = "project name"
- // version = "0.1.0"
- // authors = ["XXXXX <[email protected]>"]
- // edition = "2025"
- //
- // [features]
- // hot = ["bevy_dexterous_developer/hot"]
- //
- // [dependencies]
- // bevy = "0.14"
- // bevy_dexterous_developer = "0.4"
- use bevy::prelude::*;
- use bevy_dexterous_developer::*;
- const GAME_TITLE: &str = "My 2D Action Game";
- const DEFAULT_WINDOW_WIDTH: f32 = 1280.0;
- const DEFAULT_WINDOW_HEIGHT: f32 = 720.0;
- reloadable_main!((initial_plugins) {
- App::new()
- // Specifying the window background color
- .insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0)))
- // Window initial settings
- .insert_resource(
- WindowDescriptor {
- title: GAME_TITLE.to_string(),
- width: DEFAULT_WINDOW_WIDTH,
- height: DEFAULT_WINDOW_HEIGHT,
- resizable: false, // Disable window resizing
- ..Default::default()
- }
- )
- // All functionality of the Bevy engine is implemented as plugins.
- .add_plugins(initial_plugins.initialize::<DefaultPlugins>())
- .add_systems(Startup, setup)
- //.add_systems(OnEnter, sound_setup)
- //.add_systems(Update, (sound_system, play_sound))
- //.add_systems(OnExit, sound_cleanup);
- .add_systems(Update, player_movement.reloadable())
- .run();
- });
- // set-up scene
- fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
- commands.spawn(Camera2d::default());
- commands.spawn(Sprite::from_image(asset_server.load("bevy_bird_dark.png")));
- }
- // hot re-loadable function
- fn player_movement(
- mut query: Query<&mut Transform, With<Player>>,
- time: Res<Time>,
- ) {
- // This system will be hot reloadable.
- // Movement speed and logic can be adjusted in real time.
- for mut transform in query.iter_mut() {
- transform.translation.x += time.delta_seconds() * 150.0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment