Breakout game as plugin

This commit is contained in:
2024-07-05 15:49:47 -05:00
parent d90e70e084
commit 593f3edd10
2 changed files with 21 additions and 2 deletions

View File

@@ -143,6 +143,24 @@ fn ball_collision(ball: BoundingCircle, bounding_box: Aabb2d) -> Option<Collisio
Some(side)
}
pub struct BreakoutPlugin;
impl Plugin for BreakoutPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(Score(0))
.insert_resource(ClearColor(BACKGROUND_COLOR))
.add_event::<CollisionEvent>()
.add_systems(Startup, setup)
.add_systems(FixedUpdate, (
apply_velocity,
move_paddle,
).chain())
.add_systems(FixedUpdate, (
check_for_collisions,
update_scoreboard
));
}
}
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,

View File

@@ -2,13 +2,14 @@
use bevy::prelude::*;
mod hello_world_plugin;
// mod breakout_plugin;
mod breakout_plugin;
use hello_world_plugin::HelloPlugin;
use breakout_plugin::BreakoutPlugin;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(HelloPlugin)
.add_plugins(BreakoutPlugin)
.run();
}