|
| 1 | +use bevy::prelude::*; |
| 2 | + |
| 3 | +use linear_algebra::{point, vector}; |
| 4 | +use scenario::scenario; |
| 5 | +use spl_network_messages::{GameState, PlayerNumber}; |
| 6 | + |
| 7 | +use bevyhavior_simulator::{ |
| 8 | + ball::BallResource, |
| 9 | + game_controller::GameControllerCommand, |
| 10 | + robot::Robot, |
| 11 | + time::{Ticks, TicksTime}, |
| 12 | +}; |
| 13 | +use types::ball_position::SimulatorBallState; |
| 14 | + |
| 15 | +#[scenario] |
| 16 | +fn standing_searcher(app: &mut App) { |
| 17 | + app.add_systems(Startup, startup); |
| 18 | + app.add_systems(Update, update); |
| 19 | +} |
| 20 | + |
| 21 | +fn startup( |
| 22 | + mut commands: Commands, |
| 23 | + mut game_controller_commands: EventWriter<GameControllerCommand>, |
| 24 | +) { |
| 25 | + for number in [ |
| 26 | + PlayerNumber::One, |
| 27 | + PlayerNumber::Two, |
| 28 | + PlayerNumber::Three, |
| 29 | + PlayerNumber::Seven, |
| 30 | + ] { |
| 31 | + commands.spawn(Robot::new(number)); |
| 32 | + } |
| 33 | + game_controller_commands.send(GameControllerCommand::SetGameState(GameState::Ready)); |
| 34 | +} |
| 35 | + |
| 36 | +fn update(time: Res<Time<Ticks>>, mut ball: ResMut<BallResource>, mut exit: EventWriter<AppExit>) { |
| 37 | + if time.ticks() == 4200 { |
| 38 | + ball.state = None; |
| 39 | + } |
| 40 | + if time.ticks() == 5000 { |
| 41 | + ball.state = Some(SimulatorBallState { |
| 42 | + position: point![-2.7, -0.2], |
| 43 | + velocity: vector![0.0, 0.0], |
| 44 | + }); |
| 45 | + } |
| 46 | + if time.ticks() == 5500 { |
| 47 | + ball.state = None; |
| 48 | + } |
| 49 | + if time.ticks() >= 10_000 { |
| 50 | + println!("Done"); |
| 51 | + exit.send(AppExit::Success); |
| 52 | + } |
| 53 | +} |
0 commit comments