diff --git a/client/src/main.rs b/client/src/main.rs index a8dba14..3ba3a91 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -12,6 +12,8 @@ use crate::ui::{despawn_main_menu, spawn_main_menu}; mod ui; +const PADDLE_GAP: f32 = 20.0; // gap between the paddles and the wall (window border) + fn main() { App::new() .add_plugins(DefaultPlugins) @@ -23,6 +25,7 @@ fn main() { .add_observer(ui::button_hover_stop) // TODO: System to operate buttons & other UI widgets // .add_systems(Update, ) + .add_systems(OnEnter(GameState::Playing), setup_game) .add_systems( Update, ( @@ -65,17 +68,38 @@ fn spawn_camera(mut commands: Commands) { } /// Initialize the scene -fn setup( +fn setup_game( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, + window: Single<&Window>, ) { - commands.spawn(Camera2d); + // ball commands.spawn(( Mesh2d(meshes.add(Circle::new(10.0))), MeshMaterial2d(materials.add(Color::srgb(1.0, 0.0, 0.0))), Transform::default(), )); + + let paddle_mesh = meshes.add(Rectangle::new(10.0, 100.0)); + let paddle_material = materials.add(Color::WHITE); + // Player 1 + commands.spawn(( + // TODO: Marker component for player + // Maybe one for each player? + // Maybe it can hold the WebSocket, too. + // *Maybe* I can have one struct with an Option to know which + // player is the local one (the one with a socket). + Mesh2d(paddle_mesh.clone()), + MeshMaterial2d(paddle_material.clone()), + Transform::from_xyz(-window.width() / 2.0 + PADDLE_GAP, 0.0, 1.0), + )); + // Player 2 + commands.spawn(( + Mesh2d(paddle_mesh), + MeshMaterial2d(paddle_material), + Transform::from_xyz(window.width() / 2.0 - PADDLE_GAP, 0.0, 1.0), + )); } /// ECS Component to hold the WebSocket. I guess there's going to be a magic