Compare commits

4 Commits

Author SHA1 Message Date
caa8dbd28c Dynamic linking better? 2024-08-23 17:22:33 +03:00
3a2501a009 Tutorial implemented 2024-08-23 15:01:24 +03:00
61f5eabc2c rust-analyzer ate my processing on every save 2024-08-23 14:17:10 +03:00
235574cf19 We are go with Bevy <3 2024-08-23 14:15:22 +03:00
3 changed files with 65 additions and 1 deletions

3
.gitignore vendored
View File

@@ -23,3 +23,6 @@ Cargo.lock
# Added by cargo # Added by cargo
/target /target
# My vscode shtuff
.vscode

View File

@@ -4,3 +4,12 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
bevy = { version = "0.14.1", features = ["dynamic_linking"] }
# Enable a small amount of optimization in the dev profile.
[profile.dev]
opt-level = 1
# Enable a large amount of optimization in the dev profile for dependencies.
[profile.dev.package."*"]
opt-level = 3

View File

@@ -1,3 +1,55 @@
use bevy::prelude::*;
fn main() { fn main() {
println!("Inits are hard"); App::new()
.add_plugins(DefaultPlugins)
.add_plugins(HelloPlugin)
.run();
}
fn hello_world() {
println!("hello world!");
}
#[derive(Component)]
struct Person;
#[derive(Component)]
struct Name(String);
fn add_people(mut commands: Commands) {
commands.spawn((Person, Name("Elaina Proctor".to_string())));
commands.spawn((Person, Name("Renzo Hume".to_string())));
commands.spawn((Person, Name("Zayna Nieves".to_string())));
}
#[derive(Resource)]
struct GreetTimer(Timer);
fn greet_people(time: Res<Time>, mut timer: ResMut<GreetTimer>, query: Query<&Name, With<Person>>) {
// update our timer with the time elapsed since the last update
// if that caused the timer to finish, we say hello to everyone
if timer.0.tick(time.delta()).just_finished() {
for name in &query {
println!("hello {}!", name.0);
}
}
}
fn update_people(mut query: Query<&mut Name, With<Person>>) {
for mut name in &mut query {
if name.0 == "Elaina Proctor" {
name.0 = "Elaina Hume".to_string();
break; // We don't need to change any other names.
}
}
}
pub struct HelloPlugin;
impl Plugin for HelloPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(GreetTimer(Timer::from_seconds(2.0, TimerMode::Repeating)));
app.add_systems(Startup, add_people);
app.add_systems(Update, (hello_world, (update_people, greet_people).chain()));
}
} }