diff --git a/Cargo.lock b/Cargo.lock index db61f4f..47bcc7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3115,6 +3115,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" name = "store" version = "0.1.0" dependencies = [ + "log", "rand", "serde", ] diff --git a/client/assets/sound/click.wav b/client/assets/sound/click.wav new file mode 100644 index 0000000..8b6c99d Binary files /dev/null and b/client/assets/sound/click.wav differ diff --git a/client/assets/sound/throw.wav b/client/assets/sound/throw.wav new file mode 100755 index 0000000..cb5e438 Binary files /dev/null and b/client/assets/sound/throw.wav differ diff --git a/client/assets/tac.png b/client/assets/tac.png new file mode 100644 index 0000000..2c18813 Binary files /dev/null and b/client/assets/tac.png differ diff --git a/client/assets/tic.png b/client/assets/tic.png new file mode 100644 index 0000000..786e0c7 Binary files /dev/null and b/client/assets/tic.png differ diff --git a/client/src/main.rs b/client/src/main.rs index f558f69..8e5d60e 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -3,7 +3,7 @@ use std::{net::UdpSocket, time::SystemTime}; use renet::transport::{NetcodeClientTransport, NetcodeTransportError, NETCODE_USER_DATA_BYTES}; use store::{EndGameReason, GameEvent, GameState}; -use bevy::prelude::*; +use bevy::{prelude::*, utils::HashMap}; use bevy::window::PrimaryWindow; use bevy_renet::{ renet::{transport::ClientAuthentication, ConnectionConfig, RenetClient}, @@ -73,7 +73,7 @@ fn main() { .insert_resource(transport) .insert_resource(CurrentClientId(client_id)) .add_systems(Startup, setup) - .add_systems(Update, (update_waiting_text, input, panic_on_error_system)) + .add_systems(Update, (update_waiting_text, input, update_board, panic_on_error_system)) .add_systems( PostUpdate, receive_events_from_server.run_if(client_connected()), @@ -88,7 +88,70 @@ struct UIRoot; #[derive(Component)] struct WaitingText; +#[derive(Component)] +struct Board { + squares: [Square; 26] +} + +impl Default for Board { + fn default() -> Self { + Self { + squares: [Square { count: 0, color: None, position: 0}; 26] + } + } +} + +impl Board { + fn square_at(&self, position: usize) -> Square { + self.squares[position] + } +} + +#[derive(Component, Clone, Copy)] +struct Square { + count: usize, + color: Option, + position: usize, +} + ////////// UPDATE SYSTEMS ////////// +fn update_board( + mut commands: Commands, + game_state: Res, + mut game_events: EventReader, + asset_server: Res, +) { + for event in game_events.iter() { + match event.0 { + GameEvent::Move { player_id, from, to } => { + // backgammon postions, TODO : dépend de player_id + let (x, y) = if to < 13 { (13 - to, 1) } else { (to - 13, 0)}; + let texture = + asset_server.load(match game_state.0.players[&player_id].color { + store::Color::Black => "tac.png", + store::Color::White => "tic.png", + }); + + info!("spawning tictac sprite"); + commands.spawn(SpriteBundle { + transform: Transform::from_xyz( + 83.0 * (x as f32 - 1.0), + -30.0 + 540.0 * (y as f32 - 1.0), + 0.0, + ), + sprite: Sprite { + custom_size: Some(Vec2::new(83.0, 83.0)), + ..default() + }, + texture: texture.into(), + ..default() + }); + } + _ => {} + } + } +} + fn update_waiting_text(mut text_query: Query<&mut Text, With>, time: Res