Skip to content

Commit

Permalink
Check if goal is scored in walk_around_ball scenario and tell robot w…
Browse files Browse the repository at this point in the history
…here the ball teleported
  • Loading branch information
knoellle committed Feb 16, 2025
1 parent 393a42e commit 5fc6353
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions crates/bevyhavior_simulator/src/bin/walk_around_ball.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use std::time::SystemTime;

use bevy::prelude::*;

use linear_algebra::point;
use linear_algebra::{point, Vector2};
use scenario::scenario;
use spl_network_messages::{GameState, PlayerNumber};

use bevyhavior_simulator::{
ball::BallResource,
game_controller::GameControllerCommand,
game_controller::{GameController, GameControllerCommand},
robot::Robot,
time::{Ticks, TicksTime},
};
use types::ball_position::BallPosition;

#[scenario]
fn walk_around_ball(app: &mut App) {
Expand All @@ -25,14 +28,32 @@ fn startup(
game_controller_commands.send(GameControllerCommand::SetGameState(GameState::Ready));
}

fn update(time: Res<Time<Ticks>>, mut ball: ResMut<BallResource>, mut exit: EventWriter<AppExit>) {
if time.ticks() == 2_800 {
fn update(
game_controller: ResMut<GameController>,
time: Res<Time<Ticks>>,
mut robots: Query<&mut Robot>,
mut ball: ResMut<BallResource>,
mut exit: EventWriter<AppExit>,
) {
if time.ticks() == 3200 {
if let Some(ball) = ball.state.as_mut() {
ball.position = point![0.0, 0.0];

// loser never looks behind itself, so we need to tell it where the ball is
let mut robot = robots.get_single_mut().unwrap();
robot.database.main_outputs.ball_position = Some(BallPosition {
position: robot.ground_to_field().inverse() * ball.position,
velocity: Vector2::zeros(),
last_seen: SystemTime::UNIX_EPOCH + time.elapsed(),
});
}
}
if time.ticks() >= 10_000 {
if game_controller.state.hulks_team.score > 0 {
println!("Done");
exit.send(AppExit::Success);
}
if time.ticks() >= 10_000 {
println!("No goal was scored :(");
exit.send(AppExit::from_code(1));
}
}

0 comments on commit 5fc6353

Please sign in to comment.