From faf326203e4fcdcad0e97d2bcf1a7ce6ca9ff06a Mon Sep 17 00:00:00 2001 From: gbrochar Date: Mon, 15 May 2023 18:19:40 +0200 Subject: [PATCH] feat(): bevy 101 --- .gitignore | 9 ++++ Cargo.toml | 17 +++++++ src/main.rs | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore index 62bd1a4..44dc315 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# Assets and songs +assets +songs + # ---> Rust # Generated by Cargo # will have compiled files and executables @@ -10,3 +14,8 @@ Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk + + +# Added by cargo + +/target diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..a4ffc1f --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "sky_hero" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +bevy = { version = "0.10.1", features = ["dynamic_linking"] } + +# Enable a small amount of optimization in debug mode +[profile.dev] +opt-level = 1 + +# Enable high optimizations for dependencies (incl. Bevy), but not for our code: +[profile.dev.package."*"] +opt-level = 3 diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..0b6171d --- /dev/null +++ b/src/main.rs @@ -0,0 +1,136 @@ +use bevy::{ + prelude::*, + window::PresentMode, +}; + +#[derive(Component)] +struct Person; + +#[derive(Component)] +struct Name(String); + +#[derive(Resource)] +struct GreetTimer(Timer); + +pub struct HelloPlugin; + +impl Plugin for HelloPlugin { + fn build(&self, app: &mut App) { + app.insert_resource(GreetTimer(Timer::from_seconds(2.0, TimerMode::Repeating))) + .add_startup_system(add_people) + .add_system(greet_people); + } +} + +fn main() { + App::new() + .add_plugins(DefaultPlugins.set(WindowPlugin { + primary_window: Some(Window { + title: "Sky Hero".into(), + resolution:(640., 480.).into(), + present_mode: PresentMode::AutoVsync, + // Tells wasm to resize the window according to the available canvas + fit_canvas_to_parent: false, + // Tells wasm not to override default event handling, like F5, Ctrl+R etc. + prevent_default_event_handling: false, + ..default() + }), + ..default()})) + .add_plugin(HelloPlugin) + .add_startup_system(setup) + .add_system(button_system) + .run(); +} + +#[allow(dead_code)] +fn hello_world(time: Res