use bevy::math::bounding::{Aabb2d, BoundingCircle, BoundingVolume, IntersectsVolume}; use bevy::prelude::*; fn main() { App::new() .add_plugins(DefaultPlugins) .insert_resource(ClearColor(Color::srgb(0.8, 0.8, 1.0))) .add_systems(Startup, setup) .add_systems( FixedUpdate, (move_paddle, apply_velocity, check_for_collisions), ) .run(); } const PADDLE_GAP_Y: f32 = 50.0; const PADDLE_COLOR: Color = Color::srgb(0.5, 0.5, 1.0); const PADDLE_SIZE: Vec2 = Vec2::new(120.0, 20.0); const PADDLE_SPEED: f32 = 500.0; const PADDLE_PADDING: f32 = 10.0; const LEFT_WALL: f32 = -600.0; const RIGHT_WALL: f32 = 600.0; const BOTTOM_WALL: f32 = -300.0; const TOP_WALL: f32 = 300.0; const WALL_WIDTH: f32 = 20.0; const BALL_START_POS: Vec2 = Vec2::new(0.0, -100.0); const BALL_COLOR: Color = Color::srgb(0.2, 0.5, 0.2); const BALL_DIAMETER: f32 = 20.0; const INIT_BALL_SPEED: Vec2 = Vec2::new(100.0, 100.0); #[derive(Component)] struct Paddle; #[derive(Component)] struct Ball; #[derive(Component)] struct Collider; fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { commands.spawn(Camera2d); let paddle_y = BOTTOM_WALL + PADDLE_GAP_Y; commands.spawn(( Sprite::from_color(PADDLE_COLOR, Vec2::ONE), Transform { translation: Vec3::new(0.0, paddle_y, 0.0), scale: PADDLE_SIZE.extend(1.0), ..Default::default() }, Paddle, Collider, )); commands.spawn(( Mesh2d(meshes.add(Circle::default())), MeshMaterial2d(materials.add(BALL_COLOR)), Transform { translation: BALL_START_POS.extend(0.0), scale: Vec3::splat(BALL_DIAMETER), ..Default::default() }, Velocity(INIT_BALL_SPEED), Ball, )); commands.spawn(Wall::new(WallLocation::Left)); commands.spawn(Wall::new(WallLocation::Right)); commands.spawn(Wall::new(WallLocation::Top)); commands.spawn(Wall::new(WallLocation::Bottom)); } fn move_paddle( input: Res>, time: Res