generated from 2ndbeam/bevy-template
Initial commit
This commit is contained in:
commit
5170b588b2
5 changed files with 4509 additions and 0 deletions
11
.cargo/config.toml
Normal file
11
.cargo/config.toml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
[unstable]
|
||||||
|
codegen-backend = true
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
codegen-backend = "cranelift"
|
||||||
|
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
codegen-backend = "llvm"
|
||||||
|
|
||||||
|
[target.x86_64-unknown-linux-gnu]
|
||||||
|
rustflags = [ "-Zshare-generics=y" ]
|
||||||
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
/target
|
||||||
4426
Cargo.lock
generated
Normal file
4426
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
17
Cargo.toml
Normal file
17
Cargo.toml
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
cargo-features = ["codegen-backend"]
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "bevy_test"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bevy = { version = "0.14.2", features = ["dynamic_linking"] }
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
opt-level = 1
|
||||||
|
codegen-backend = "cranelift"
|
||||||
|
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
opt-level = 3
|
||||||
|
codegen-backend = "llvm"
|
||||||
54
src/main.rs
Normal file
54
src/main.rs
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct Person;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct Name(String);
|
||||||
|
|
||||||
|
#[derive(Resource)]
|
||||||
|
struct GreetTimer(Timer);
|
||||||
|
|
||||||
|
#[derive(Resource)]
|
||||||
|
struct UpdateTimer(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)));
|
||||||
|
app.insert_resource(UpdateTimer(Timer::from_seconds(10.0, TimerMode::Once)));
|
||||||
|
app.add_systems(Startup, add_people);
|
||||||
|
app.add_systems(Update, (update_people, greet_people).chain());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn add_people(mut commands: Commands) {
|
||||||
|
commands.spawn((Person, Name("Alkesey Mirnekov".to_string())));
|
||||||
|
commands.spawn((Person, Name("Alkesey Mirnekov 2".to_string())));
|
||||||
|
commands.spawn((Person, Name("Alkesey Mirnekov 3".to_string())));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn greet_people(time: Res<Time>, mut timer: ResMut<GreetTimer>, query: Query<&Name, With<Person>>) {
|
||||||
|
if timer.0.tick(time.delta()).just_finished() {
|
||||||
|
for name in &query {
|
||||||
|
println!("hello {}!", name.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_people(time: Res<Time>, mut timer: ResMut<UpdateTimer>, mut query: Query<&mut Name, With<Person>>) {
|
||||||
|
if timer.0.tick(time.delta()).just_finished() {
|
||||||
|
for mut name in &mut query {
|
||||||
|
name.0 = format!("{} II", name.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
App::new()
|
||||||
|
.add_plugins(DefaultPlugins)
|
||||||
|
.add_plugins(HelloPlugin)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue