diff options
author | Henauxg <19689618+Henauxg@users.noreply.github.com> | 2022-11-03 17:48:19 +0100 |
---|---|---|
committer | Henauxg <19689618+Henauxg@users.noreply.github.com> | 2022-11-03 17:48:19 +0100 |
commit | e104ce1299a64fb2b575a2193ec2151b48667165 (patch) | |
tree | 274e3ad13d9a66e1b30f15bb8c61d6f377e79328 /examples/breakout/breakout.rs | |
parent | a6f63d755caf51cd9866ba5aaf0c9fd3c0d56bde (diff) |
[example:breakout] Networked bricks destruction
Diffstat (limited to 'examples/breakout/breakout.rs')
-rw-r--r-- | examples/breakout/breakout.rs | 113 |
1 files changed, 57 insertions, 56 deletions
diff --git a/examples/breakout/breakout.rs b/examples/breakout/breakout.rs index 96527c2..894364a 100644 --- a/examples/breakout/breakout.rs +++ b/examples/breakout/breakout.rs @@ -12,6 +12,7 @@ mod client; mod protocol; mod server; +const SERVER_HOST: &str = "127.0.0.1"; const SERVER_PORT: u16 = 6000; // Defines the amount of time that should elapse between each physics step. @@ -51,6 +52,60 @@ enum GameState { Running, } +#[derive(Component, Deref, DerefMut)] +struct Velocity(Vec2); + +#[derive(Default)] +struct CollisionEvent; + +#[derive(Component)] +struct Score; + +struct CollisionSound(Handle<AudioSource>); + +pub type BrickId = u64; + +/// Which side of the arena is this wall located on? +enum WallLocation { + Left, + Right, + Bottom, + Top, +} + +impl WallLocation { + fn position(&self) -> Vec2 { + match self { + WallLocation::Left => Vec2::new(LEFT_WALL, 0.), + WallLocation::Right => Vec2::new(RIGHT_WALL, 0.), + WallLocation::Bottom => Vec2::new(0., BOTTOM_WALL), + WallLocation::Top => Vec2::new(0., TOP_WALL), + } + } + + fn size(&self) -> Vec2 { + let arena_height = TOP_WALL - BOTTOM_WALL; + let arena_width = RIGHT_WALL - LEFT_WALL; + // Make sure we haven't messed up our constants + assert!(arena_height > 0.0); + assert!(arena_width > 0.0); + + match self { + WallLocation::Left | WallLocation::Right => { + Vec2::new(WALL_THICKNESS, arena_height + WALL_THICKNESS) + } + WallLocation::Bottom | WallLocation::Top => { + Vec2::new(arena_width + WALL_THICKNESS, WALL_THICKNESS) + } + } + } +} + +// This resource tracks the game's score +struct Scoreboard { + score: usize, +} + fn main() { App::new() .add_plugins(DefaultPlugins) @@ -63,7 +118,8 @@ fn main() { .insert_resource(ClearColor(BACKGROUND_COLOR)) .insert_resource(server::Players::default()) .insert_resource(client::ClientData::default()) - .insert_resource(NetworkMapping::default()) + .insert_resource(client::NetworkMapping::default()) + .insert_resource(client::BricksMapping::default()) // Main menu .add_system_set( SystemSet::on_enter(GameState::MainMenu).with_system(client::setup_main_menu), @@ -139,58 +195,3 @@ fn main() { .add_system(bevy::window::close_on_esc) .run(); } - -#[derive(Component, Deref, DerefMut)] -struct Velocity(Vec2); - -#[derive(Component)] -struct Collider; - -#[derive(Default)] -struct CollisionEvent; - -#[derive(Component)] -struct Score; - -struct CollisionSound(Handle<AudioSource>); - -/// Which side of the arena is this wall located on? -enum WallLocation { - Left, - Right, - Bottom, - Top, -} - -impl WallLocation { - fn position(&self) -> Vec2 { - match self { - WallLocation::Left => Vec2::new(LEFT_WALL, 0.), - WallLocation::Right => Vec2::new(RIGHT_WALL, 0.), - WallLocation::Bottom => Vec2::new(0., BOTTOM_WALL), - WallLocation::Top => Vec2::new(0., TOP_WALL), - } - } - - fn size(&self) -> Vec2 { - let arena_height = TOP_WALL - BOTTOM_WALL; - let arena_width = RIGHT_WALL - LEFT_WALL; - // Make sure we haven't messed up our constants - assert!(arena_height > 0.0); - assert!(arena_width > 0.0); - - match self { - WallLocation::Left | WallLocation::Right => { - Vec2::new(WALL_THICKNESS, arena_height + WALL_THICKNESS) - } - WallLocation::Bottom | WallLocation::Top => { - Vec2::new(arena_width + WALL_THICKNESS, WALL_THICKNESS) - } - } - } -} - -// This resource tracks the game's score -struct Scoreboard { - score: usize, -} |