//! This example shows a simple cut-in implementation. //! //! Cut-in will start by pressing the R key. #![allow(clippy::type_complexity)] use std::f32::consts::PI; use std::time::Duration; use bevy::prelude::*; use bevy::window::PrimaryWindow; use bevy_flurx::prelude::*; #[derive(Component)] struct CutInBackground; #[derive(Component)] struct HandsomeFerris; #[derive(Component)] struct StartPos(Vec3); struct MoveSlowly; struct MoveFast; fn main() { App::new() .add_plugins(( DefaultPlugins, FlurxPlugin )) .add_systems(Startup, ( spawn_reactor, spawn_ferris, setup, )) .add_systems(Update, ( cut_in::.run_if(switch_is_on::), cut_in_ferris.run_if(switch_is_on::), move_left_down::<25>.run_if(switch_is_on::), move_left_down::<10000>.run_if(switch_is_on::) )) .run(); } fn spawn_reactor( mut commands: Commands ) { commands.spawn(Reactor::schedule(|task| async move { info!("please press [`R`] key!"); task.will(Update, { wait::input::just_pressed().with(KeyCode::KeyR) .then(once::switch::on::()) .then(delay::time().with(Duration::from_millis(100))) .then(once::switch::on::()) .then(wait::both( wait::switch::off::(), wait::switch::off::(), )) .then(once::switch::on::()) .then(delay::time().with(Duration::from_millis(500))) .then(once::switch::off::()) .then(once::switch::on::()) .then(delay::time().with(Duration::from_millis(300))) .then(once::event::app_exit_success()) }) .await; })); } fn setup( mut commands: Commands, window: Query<&Window, With>, ) { let wh = &window.single().resolution; let angle = (wh.height() / 2.).atan2(wh.width() / 2.); commands.spawn(( SpriteBundle { sprite: Sprite { custom_size: Some(Vec2::new(wh.width() * 2., 300.)), color: Color::srgb(0.8, 0.6, 0.1), ..default() }, transform: Transform::from_rotation(Quat::from_rotation_z(angle)) .with_translation(Vec3::new(wh.width() * 2., wh.height(), 0.)), ..default() }, CutInBackground )); commands.spawn(Camera2dBundle::default()); } fn spawn_ferris( mut commands: Commands, asset_server: Res, window: Query<&Window, With>, ) { const HEIGHT: f32 = 200.; const WIDTH: f32 = HEIGHT * 1.5; let wh = &window.single().resolution; let pos = Vec3::new(wh.width() / 2. + WIDTH / 2., wh.height() / 2. + HEIGHT / 2., 1.); commands.spawn(( SpriteBundle { sprite: Sprite { custom_size: Some(Vec2::new(WIDTH, HEIGHT)), ..default() }, texture: asset_server.load("rustacean-flat-gesture.png"), transform: Transform::from_translation(pos), ..default() }, StartPos(pos), HandsomeFerris )); } fn cut_in( mut target: Query<&mut Transform, With>, mut switch: ResMut>, mut tick: Local, time: Res