use bevy::prelude::*;
use bevy_pipe_affect::prelude::*;
#[derive(Component)]
struct Spinny;
fn spawn_camera() -> impl Effect {
command_spawn(Camera2d)
}
fn spawn_relationship() -> impl Effect {
asset_server_load_and("player.png", |image_handle| {
command_spawn_and(
(
Spinny,
Sprite::from_image(image_handle.clone()),
Transform::from_scale(Vec3::splat(10.0)),
),
|parent| {
command_spawn((
ChildOf(parent), Spinny,
Sprite::from_image(image_handle),
Transform::from_xyz(20.0, 20.0, 0.0).with_scale(Vec3::splat(0.5)),
))
},
)
})
}
fn spin(time: Res<Time>) -> QueryMap<&'static Transform, ComponentSet<Transform>, With<Spinny>> {
let theta = time.elapsed_secs();
query_map(move |transform: &Transform| {
component_set(transform.with_rotation(Quat::from_axis_angle(Vec3::Z, theta)))
})
}
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
.add_systems(
Startup,
(spawn_camera.pipe(affect), spawn_relationship.pipe(affect)),
)
.add_systems(Update, spin.pipe(affect))
.run();
}