Format all cargo source files.
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
|
use bevy::{
|
||||||
use bevy::{input::keyboard::Key, math::bounding::{Aabb2d, BoundingCircle, BoundingVolume, IntersectsVolume}, prelude::*, sprite::MaterialMesh2dBundle};
|
input::keyboard::Key,
|
||||||
|
math::bounding::{Aabb2d, BoundingCircle, BoundingVolume, IntersectsVolume},
|
||||||
|
prelude::*,
|
||||||
|
sprite::MaterialMesh2dBundle,
|
||||||
|
};
|
||||||
|
|
||||||
// Using the default 2D camera they correspond 1:1 with screen pixels.
|
// Using the default 2D camera they correspond 1:1 with screen pixels.
|
||||||
const PADDLE_SIZE: Vec2 = Vec2::new(120.0, 20.0);
|
const PADDLE_SIZE: Vec2 = Vec2::new(120.0, 20.0);
|
||||||
@@ -41,7 +45,6 @@ const WALL_COLOR: Color = Color::srgb(0.8, 0.8, 0.8);
|
|||||||
const TEXT_COLOR: Color = Color::srgb(0.5, 0.5, 1.0);
|
const TEXT_COLOR: Color = Color::srgb(0.5, 0.5, 1.0);
|
||||||
const SCORE_COLOR: Color = Color::srgb(1.0, 0.5, 0.5);
|
const SCORE_COLOR: Color = Color::srgb(1.0, 0.5, 0.5);
|
||||||
|
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct Paddle;
|
struct Paddle;
|
||||||
|
|
||||||
@@ -91,7 +94,12 @@ impl WallBundle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enum WallLocation { Right, Top, Left, Bottom }
|
enum WallLocation {
|
||||||
|
Right,
|
||||||
|
Top,
|
||||||
|
Left,
|
||||||
|
Bottom,
|
||||||
|
}
|
||||||
|
|
||||||
impl WallLocation {
|
impl WallLocation {
|
||||||
fn position(&self) -> Vec2 {
|
fn position(&self) -> Vec2 {
|
||||||
@@ -111,7 +119,7 @@ impl WallLocation {
|
|||||||
match self {
|
match self {
|
||||||
WallLocation::Left | WallLocation::Right => {
|
WallLocation::Left | WallLocation::Right => {
|
||||||
Vec2::new(WALL_THICKNESS, arena_height + WALL_THICKNESS)
|
Vec2::new(WALL_THICKNESS, arena_height + WALL_THICKNESS)
|
||||||
},
|
}
|
||||||
WallLocation::Top | WallLocation::Bottom => {
|
WallLocation::Top | WallLocation::Bottom => {
|
||||||
Vec2::new(WALL_THICKNESS + arena_width, WALL_THICKNESS)
|
Vec2::new(WALL_THICKNESS + arena_width, WALL_THICKNESS)
|
||||||
}
|
}
|
||||||
@@ -119,7 +127,12 @@ impl WallLocation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Collision { Right, Top, Left, Bottom }
|
enum Collision {
|
||||||
|
Right,
|
||||||
|
Top,
|
||||||
|
Left,
|
||||||
|
Bottom,
|
||||||
|
}
|
||||||
|
|
||||||
fn ball_collision(ball: BoundingCircle, bounding_box: Aabb2d) -> Option<Collision> {
|
fn ball_collision(ball: BoundingCircle, bounding_box: Aabb2d) -> Option<Collision> {
|
||||||
if !ball.intersects(&bounding_box) {
|
if !ball.intersects(&bounding_box) {
|
||||||
@@ -150,14 +163,8 @@ impl Plugin for BreakoutPlugin {
|
|||||||
.insert_resource(ClearColor(BACKGROUND_COLOR))
|
.insert_resource(ClearColor(BACKGROUND_COLOR))
|
||||||
.add_event::<CollisionEvent>()
|
.add_event::<CollisionEvent>()
|
||||||
.add_systems(Startup, setup)
|
.add_systems(Startup, setup)
|
||||||
.add_systems(FixedUpdate, (
|
.add_systems(FixedUpdate, (apply_velocity, move_paddle).chain())
|
||||||
apply_velocity,
|
.add_systems(FixedUpdate, (check_for_collisions, update_scoreboard));
|
||||||
move_paddle,
|
|
||||||
).chain())
|
|
||||||
.add_systems(FixedUpdate, (
|
|
||||||
check_for_collisions,
|
|
||||||
update_scoreboard
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,7 +230,7 @@ fn setup(
|
|||||||
top: SCOREBOARD_TEXT_PADDING,
|
top: SCOREBOARD_TEXT_PADDING,
|
||||||
left: SCOREBOARD_TEXT_PADDING,
|
left: SCOREBOARD_TEXT_PADDING,
|
||||||
..default()
|
..default()
|
||||||
})
|
}),
|
||||||
));
|
));
|
||||||
|
|
||||||
// walls
|
// walls
|
||||||
@@ -306,7 +313,8 @@ fn move_paddle(
|
|||||||
direction += 1.0;
|
direction += 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_paddle_position = paddle_transform.translation.x + direction * PADDLE_SPEED * time.delta_seconds();
|
let new_paddle_position =
|
||||||
|
paddle_transform.translation.x + direction * PADDLE_SPEED * time.delta_seconds();
|
||||||
|
|
||||||
let left_bound = LEFT_WALL + WALL_THICKNESS / 2.0 + PADDLE_SIZE.x / 2.0 + PADDLE_PADDING;
|
let left_bound = LEFT_WALL + WALL_THICKNESS / 2.0 + PADDLE_SIZE.x / 2.0 + PADDLE_PADDING;
|
||||||
let right_bound = RIGHT_WALL - WALL_THICKNESS / 2.0 + PADDLE_SIZE.x / 2.0 - PADDLE_PADDING;
|
let right_bound = RIGHT_WALL - WALL_THICKNESS / 2.0 + PADDLE_SIZE.x / 2.0 - PADDLE_PADDING;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
@@ -16,11 +15,7 @@ fn add_people(mut commands: Commands) {
|
|||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
struct GreetTimer(Timer);
|
struct GreetTimer(Timer);
|
||||||
|
|
||||||
fn greet_people(
|
fn greet_people(time: Res<Time>, mut timer: ResMut<GreetTimer>, query: Query<&Name, With<Person>>) {
|
||||||
time: Res<Time>,
|
|
||||||
mut timer: ResMut<GreetTimer>,
|
|
||||||
query: Query<&Name, With<Person>>
|
|
||||||
) {
|
|
||||||
if timer.0.tick(time.delta()).just_finished() {
|
if timer.0.tick(time.delta()).just_finished() {
|
||||||
for name in &query {
|
for name in &query {
|
||||||
println!("Hello {}!", name.0);
|
println!("Hello {}!", name.0);
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
mod hello_world_plugin;
|
|
||||||
mod breakout_plugin;
|
mod breakout_plugin;
|
||||||
|
mod hello_world_plugin;
|
||||||
|
|
||||||
use hello_world_plugin::HelloPlugin;
|
|
||||||
use breakout_plugin::BreakoutPlugin;
|
use breakout_plugin::BreakoutPlugin;
|
||||||
|
use hello_world_plugin::HelloPlugin;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
|
|||||||
Reference in New Issue
Block a user