diff --git a/Cargo.lock b/Cargo.lock index 2421879..54809d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -207,9 +207,9 @@ dependencies = [ [[package]] name = "arrayref" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d151e35f61089500b617991b791fc8bfd237ae50cd5950803758a179b41e67a" +checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb" [[package]] name = "arrayvec" @@ -1482,9 +1482,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.18" +version = "1.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476" +checksum = "2d74707dde2ba56f86ae90effb3b43ddd369504387e718014de010cec7959800" dependencies = [ "jobserver", "libc", @@ -1679,6 +1679,16 @@ dependencies = [ "libc", ] +[[package]] +name = "core-foundation" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -1692,7 +1702,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081" dependencies = [ "bitflags 1.3.2", - "core-foundation", + "core-foundation 0.9.4", "core-graphics-types", "foreign-types", "libc", @@ -1705,7 +1715,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" dependencies = [ "bitflags 1.3.2", - "core-foundation", + "core-foundation 0.9.4", "libc", ] @@ -2308,9 +2318,9 @@ dependencies = [ [[package]] name = "gilrs" -version = "0.10.9" +version = "0.10.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfb8c78963a8856a5b10015c9349176ff5edbc8095384d52aada467a848bc03a" +checksum = "a556964c6d62458084356ce9770676f5104bd667e12e9a795691076e8a17c5cf" dependencies = [ "fnv", "gilrs-core", @@ -2325,7 +2335,7 @@ version = "0.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "732dadc05170599ddec9a89653f10d7a2af54da9181b3fa6e2bd49907ec8f7e4" dependencies = [ - "core-foundation", + "core-foundation 0.9.4", "inotify 0.10.2", "io-kit-sys", "js-sys", @@ -3591,9 +3601,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" [[package]] name = "opener" @@ -4912,12 +4922,12 @@ dependencies = [ [[package]] name = "webbrowser" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "425ba64c1e13b1c6e8c5d2541c8fac10022ca584f33da781db01b5756aef1f4e" +checksum = "2e5f07fb9bc8de2ddfe6b24a71a75430673fd679e568c48b52716cef1cfae923" dependencies = [ "block2", - "core-foundation", + "core-foundation 0.10.0", "home", "jni", "log", @@ -5455,7 +5465,7 @@ dependencies = [ "calloop", "cfg_aliases 0.2.1", "concurrent-queue", - "core-foundation", + "core-foundation 0.9.4", "core-graphics", "cursor-icon", "dpi", diff --git a/src/bck2_main.rs b/src/bck2_main.rs deleted file mode 100644 index 25ee8f9..0000000 --- a/src/bck2_main.rs +++ /dev/null @@ -1,282 +0,0 @@ -use bevy::{ - math::vec3, - math::vec2, - math::bounding::{Aabb2d, BoundingCircle, BoundingVolume, IntersectsVolume}, - prelude::* -}; -use bevy::diagnostic::FrameTimeDiagnosticsPlugin; - -//paddle -const PADDLE_START_Y: f32 = 0.0; -const PADDLE_SIZE: Vec2 = Vec2::new(120.0, 20.0); -const PADDLE_COLOR: Color = Color::srgb(0.3, 0.3, 0.7); -const PADDLE_SPEED: f32 = 500.0; - -//ball -const BALL_COLOR: Color = Color::srgb(1.0, 0.54, 0.5); -const BALL_STARTING_POSITION: Vec3 = Vec3::new(0.0, -50.0, 1.0); -const BALL_SIZE: Vec2 = Vec2::new(30.0, 30.0); -const BALL_SPEED: f32 = 400.0; -const BALL_INITIAL_DIRECTION: Vec2 = Vec2::new(0.5, -0.5); - -//wall -const LEFT_WALL: f32 = -450.0; -const RIGHT_WALL: f32 = 450.0; -const BOTTOM_WALL: f32 = -300.0; -const TOP_WALL: f32 = 300.0; - -const WALL_THICKNESS: f32 = 10.0; -const WALL_BLOCK_WIDTH: f32 = RIGHT_WALL - LEFT_WALL; -const WALL_BLOCK_HEIGHT: f32 = TOP_WALL - BOTTOM_WALL; -const WALL_COLOR: Color = Color::srgb(0.8, 0.8, 0.8); - -fn main() { - App::new() - .add_plugins(DefaultPlugins) - .add_systems(Update, close_on_esc) - .add_systems(Startup, setup) - .add_plugins(FrameTimeDiagnosticsPlugin::default()) - .add_systems( - FixedUpdate, - ( - move_paddle, - apply_velocity, - check_ball_collision.after(apply_velocity), - ), - ) - .run(); -} - -#[derive(Component)] -struct Paddle; - -#[derive(Component)] -struct Ball { - size: Vec2, -} - -#[derive(Component, Deref, DerefMut)] -struct Velocity(Vec2); - -#[derive(Component)] -struct Collider { - size: Vec2, -} - -#[derive(Bundle)] -struct WallBundle{ - sprite_bundle: SpriteBundle, - collider: Collider, -} - -fn setup(mut commands: Commands, asset_server: Res) { - //camera - commands.spawn(Camera2dBundle::default()); - - //paddle - commands.spawn(( - SpriteBundle { - transform: Transform { - translation: vec3(0., PADDLE_START_Y, 0.), - ..default() - }, - sprite: Sprite { - color: PADDLE_COLOR, - custom_size: Some(PADDLE_SIZE), - ..default() - }, - ..default() - }, - Paddle, - )); - - //ball - let ball_tex = asset_server.load("textures/circle.png"); - commands.spawn(( - SpriteBundle { - transform: Transform { - translation: BALL_STARTING_POSITION, - ..default() - }, - sprite: Sprite { - color: BALL_COLOR, - custom_size: Some(BALL_SIZE), - ..default() - }, - texture:ball_tex, - ..default() - }, - Ball { size: BALL_SIZE }, - Velocity(BALL_SPEED * BALL_INITIAL_DIRECTION), - )); - - //walls - { - let vertical_wall_size = vec2(WALL_THICKNESS, WALL_BLOCK_HEIGHT + WALL_THICKNESS); - let horizontal_wall_size = vec2(WALL_BLOCK_WIDTH + WALL_THICKNESS, WALL_THICKNESS); - //left wall - commands.spawn(WallBundle { - sprite_bundle: SpriteBundle { - transform: Transform { - translation: vec3(LEFT_WALL, 0.0, 0.0), - ..default() - }, - sprite: Sprite { - color: WALL_COLOR, - custom_size: Some(vertical_wall_size), - ..default() - }, - ..default() - }, - collider: Collider { - size: vertical_wall_size, - }, - }); - - //right wall - commands.spawn(WallBundle { - sprite_bundle: SpriteBundle { - transform: Transform { - translation: vec3(RIGHT_WALL, 0.0, 0.0), - ..default() - }, - sprite: Sprite { - color: WALL_COLOR, - custom_size: Some(vertical_wall_size), - ..default() - }, - ..default() - }, - collider: Collider { - size: vertical_wall_size, - }, - }); - - //bottom wall - commands.spawn(WallBundle { - sprite_bundle: SpriteBundle { - transform: Transform { - translation: vec3(0.0, BOTTOM_WALL, 0.0), - ..default() - }, - sprite: Sprite { - color: WALL_COLOR, - custom_size: Some(horizontal_wall_size), - ..default() - }, - ..default() - }, - collider: Collider { - size: horizontal_wall_size, - }, - }); - - //top wall - commands.spawn(WallBundle { - sprite_bundle: SpriteBundle { - transform: Transform { - translation: vec3(0.0, TOP_WALL, 0.0), - ..default() - }, - sprite: Sprite { - color: WALL_COLOR, - custom_size: Some(horizontal_wall_size), - ..default() - }, - ..default() - }, - collider: Collider { - size: horizontal_wall_size, - }, - }); - } - - -} - -fn move_paddle( - input: Res>, - time_step: Res>, - mut query: Query<&mut Transform, With>, -) { - let mut paddle_transform = query.single_mut(); - - let mut direction: f32 = 0.0; - if input.pressed(KeyCode::KeyA) { - direction -= 1.0 - } - if input.pressed(KeyCode::KeyD) { - direction += 1.0; - } - - let mut new_x = - paddle_transform.translation.x + direction * PADDLE_SPEED * time_step.delta_seconds(); - - new_x = new_x.min(RIGHT_WALL - (WALL_THICKNESS + PADDLE_SIZE.x) * 0.5); - new_x = new_x.max(LEFT_WALL + (WALL_THICKNESS + PADDLE_SIZE.x) * 0.5); - - paddle_transform.translation.x = new_x; -} - -fn apply_velocity(mut query: Query<(&mut Transform, &Velocity)>, time_step: Res>) { - let dt = time_step.delta_seconds(); - for (mut transform, velocity) in &mut query { - transform.translation.x += velocity.x * dt; - transform.translation.y += velocity.y * dt; - } -} - -fn check_ball_collision( - mut ball_query: Query<(&mut Velocity, &Transform, &Ball)>, - collider_query: Query<(&Transform, &Collider)>, -) { - for (mut ball_velocity, ball_transform, ball) in &mut ball_query { - for (transform, other) in &collider_query { - let collision = ball_collision( - ball_transform.translation, - ball.size, - transform.translation, - other.size, - ); - - let mut reflect_x = false; - let mut reflect_y = false; - if let Some(collision) = collision { - match collision { - Collision::Left => reflect_x = ball_velocity.x > 0.0, - Collision::Right => reflect_x = ball_velocity.x < 0.0, - Collision::Top => reflect_y = ball_velocity.y < 0.0, - Collision::Bottom => reflect_y = ball_velocity.y > 0.0, - Collision::Inside => { /* do nothing */ } - } - - if reflect_x { - ball_velocity.x *= -1.; - } - if reflect_y { - ball_velocity.y *= -1.; - } - } - } - } -} - -fn ball_collision() { - -} - -pub fn close_on_esc( - mut commands: Commands, - focused_windows: Query<(Entity, &Window)>, - input: Res>, -) { - for (window, focus) in focused_windows.iter() { - if !focus.focused { - continue; - } - - if input.just_pressed(KeyCode::Escape) { - commands.entity(window).despawn(); - } - } -} \ No newline at end of file diff --git a/src/bck_main.rs b/src/bck_main.rs deleted file mode 100644 index 78910d7..0000000 --- a/src/bck_main.rs +++ /dev/null @@ -1,50 +0,0 @@ -use bevy::prelude::*; - -#[derive(Component)] -struct Person; - -#[derive(Component)] -struct Name(String); - -#[derive(Resource)] -struct GreetTimer(Timer); - -pub struct HelloPlugin; - -impl Plugin for HelloPlugin { - fn build(&self, app: &mut App) { - app.insert_resource(GreetTimer(Timer::from_seconds(2.0, TimerMode::Repeating))); - app.add_systems(Startup, add_people); - app.add_systems(Update, (update_people, greet_people).chain()); - } -} - -fn main() { - App::new() - .add_plugins(HelloPlugin) - .add_plugins(DefaultPlugins) - .run(); -} - -fn add_people(mut commands: Commands) { - commands.spawn((Person, Name("Elaina Proctor".to_string()))); - commands.spawn((Person, Name("Renzo Hume".to_string()))); - commands.spawn((Person, Name("Zayna Nieves".to_string()))); -} - -fn greet_people(time: Res